Skip to content

Commit c035fe3

Browse files
setup module
1 parent 3c36322 commit c035fe3

File tree

5 files changed

+102
-10
lines changed

5 files changed

+102
-10
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,43 @@ See `examples` directory for working examples to reference
7979
| Name | Version |
8080
|------|---------|
8181
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1 |
82+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4 |
8283

8384
## Providers
8485

85-
No providers.
86+
| Name | Version |
87+
|------|---------|
88+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4 |
8689

8790
## Modules
8891

8992
No modules.
9093

9194
## Resources
9295

93-
No resources.
96+
| Name | Type |
97+
|------|------|
98+
| [aws_ecs_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster) | resource |
99+
| [aws_ecs_cluster_capacity_providers.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster_capacity_providers) | resource |
94100

95101
## Inputs
96102

97103
| Name | Description | Type | Default | Required |
98104
|------|-------------|------|---------|:--------:|
99-
| <a name="input_variable"></a> [variable](#input\_variable) | defaul,description,type | `string` | `"variable"` | no |
105+
| <a name="input_capacity_providers"></a> [capacity\_providers](#input\_capacity\_providers) | List of short names of one or more capacity providers to associate with the cluster. Valid values also include FARGATE and FARGATE\_SPOT. | `list(string)` | `[]` | no |
106+
| <a name="input_container_insights"></a> [container\_insights](#input\_container\_insights) | Controls if ECS Cluster has container insights enabled | `bool` | `false` | no |
107+
| <a name="input_create_ecs"></a> [create\_ecs](#input\_create\_ecs) | Controls if ECS should be created | `bool` | `true` | no |
108+
| <a name="input_default_capacity_provider_strategy"></a> [default\_capacity\_provider\_strategy](#input\_default\_capacity\_provider\_strategy) | The capacity provider strategy to use by default for the cluster. Can be one or more. | `list(map(any))` | `[]` | no |
109+
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as identifier, also the name of the ECS cluster | `string` | `null` | no |
110+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to ECS Cluster | `map(string)` | `{}` | no |
100111

101112
## Outputs
102113

103114
| Name | Description |
104115
|------|-------------|
105-
| <a name="output_used"></a> [used](#output\_used) | used value |
116+
| <a name="output_ecs_cluster_arn"></a> [ecs\_cluster\_arn](#output\_ecs\_cluster\_arn) | ARN of the ECS Cluster |
117+
| <a name="output_ecs_cluster_id"></a> [ecs\_cluster\_id](#output\_ecs\_cluster\_id) | ID of the ECS Cluster |
118+
| <a name="output_ecs_cluster_name"></a> [ecs\_cluster\_name](#output\_ecs\_cluster\_name) | The name of the ECS cluster |
106119
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
107120

108121

main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
resource "aws_ecs_cluster" "this" {
2+
count = var.create_ecs ? 1 : 0
3+
4+
name = var.name
5+
6+
setting {
7+
name = "containerInsights"
8+
value = var.container_insights ? "enabled" : "disabled"
9+
}
10+
11+
tags = var.tags
12+
}
13+
14+
resource "aws_ecs_cluster_capacity_providers" "this" {
15+
count = var.create_ecs ? 1 : 0
16+
17+
cluster_name = aws_ecs_cluster.this[0].name
18+
19+
capacity_providers = var.capacity_providers
20+
21+
dynamic "default_capacity_provider_strategy" {
22+
for_each = var.default_capacity_provider_strategy
23+
iterator = strategy
24+
25+
content {
26+
capacity_provider = strategy.value["capacity_provider"]
27+
weight = lookup(strategy.value, "weight", null)
28+
base = lookup(strategy.value, "base", null)
29+
}
30+
}
31+
}

outputs.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
output "used" {
2-
description = "used value"
3-
value = var.variable
1+
output "ecs_cluster_id" {
2+
description = "ID of the ECS Cluster"
3+
value = concat(aws_ecs_cluster.this.*.id, [""])[0]
4+
}
5+
6+
output "ecs_cluster_arn" {
7+
description = "ARN of the ECS Cluster"
8+
value = concat(aws_ecs_cluster.this.*.arn, [""])[0]
9+
}
10+
11+
output "ecs_cluster_name" {
12+
description = "The name of the ECS cluster"
13+
value = var.name
414
}

variables.tf

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1-
variable "variable" {
2-
default = "variable"
3-
description = "defaul,description,type"
1+
variable "create_ecs" {
2+
description = "Controls if ECS should be created"
3+
type = bool
4+
default = true
5+
}
6+
7+
variable "name" {
8+
description = "Name to be used on all the resources as identifier, also the name of the ECS cluster"
49
type = string
10+
default = null
11+
}
12+
13+
variable "capacity_providers" {
14+
description = "List of short names of one or more capacity providers to associate with the cluster. Valid values also include FARGATE and FARGATE_SPOT."
15+
type = list(string)
16+
default = []
17+
}
18+
19+
variable "default_capacity_provider_strategy" {
20+
description = "The capacity provider strategy to use by default for the cluster. Can be one or more."
21+
type = list(map(any))
22+
default = []
23+
}
24+
25+
variable "container_insights" {
26+
description = "Controls if ECS Cluster has container insights enabled"
27+
type = bool
28+
default = false
29+
}
30+
31+
variable "tags" {
32+
description = "A map of tags to add to ECS Cluster"
33+
type = map(string)
34+
default = {}
535
}

versions.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
terraform {
22
required_version = ">= 1"
3+
4+
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 4"
9+
}
10+
}
311
}

0 commit comments

Comments
 (0)