Skip to content

Commit 7a41657

Browse files
authored
feat!: Upgrade module to include capacity providers and bump minimum supported versions (#60)
1 parent b71f615 commit 7a41657

34 files changed

+1092
-462
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.62.3
3+
rev: v1.72.1
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
@@ -23,7 +23,7 @@ repos:
2323
- '--args=--only=terraform_standard_module_structure'
2424
- '--args=--only=terraform_workspace_remote'
2525
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.1.0
26+
rev: v4.2.0
2727
hooks:
2828
- id: check-merge-conflict
2929
- id: end-of-file-fixer

README.md

+179-32
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,214 @@
1-
# AWS Elastic Container Service (ECS) Terraform module
1+
# AWS ECS Terraform module
22

3-
Terraform module which creates ECS resources on AWS.
3+
Terraform module which creates ECS (Elastic Container Service) resources on AWS.
44

5-
This module focuses purely on ECS and nothing else. Therefore only these resources can be created with this module:
5+
## Available Features
66

7-
- [ECS](https://www.terraform.io/docs/providers/aws/r/ecs_cluster.html)
8-
- [IAM](https://www.terraform.io/docs/providers/aws/r/iam_instance_profile.html)
9-
10-
However, having said the above to have a proper ECS cluster up and running multiple resources are needed. In most cases creating these resources is heavily opinionated and or context-bound. That is why this module does not create these resources. But you still need them to have a production ready environment. Therefore the example area shows how to create everything needed for a production environment.
7+
- ECS cluster
8+
- Fargate capacity providers
9+
- EC2 AutoScaling Group capacity providers
1110

1211
## Usage
1312

13+
### Fargate Capacity Providers
14+
15+
```hcl
16+
module "ecs" {
17+
source = "terraform-aws-modules/ecs/aws"
18+
19+
name = "ecs-fargate"
20+
21+
cluster_configuration = {
22+
execute_command_configuration = {
23+
logging = "OVERRIDE"
24+
log_configuration = {
25+
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
26+
}
27+
}
28+
}
29+
30+
fargate_capacity_providers = {
31+
FARGATE = {
32+
default_capacity_provider_strategy = {
33+
weight = 50
34+
}
35+
}
36+
FARGATE_SPOT = {
37+
default_capacity_provider_strategy = {
38+
weight = 50
39+
}
40+
}
41+
}
42+
43+
tags = {
44+
Environment = "Development"
45+
Project = "EcsEc2"
46+
}
47+
}
48+
```
49+
50+
### EC2 Autoscaling Capacity Providers
51+
52+
```hcl
53+
module "ecs" {
54+
source = "terraform-aws-modules/ecs/aws"
55+
56+
name = "ecs-ec2"
57+
58+
cluster_configuration = {
59+
execute_command_configuration = {
60+
logging = "OVERRIDE"
61+
log_configuration = {
62+
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
63+
}
64+
}
65+
}
66+
67+
autoscaling_capacity_providers = {
68+
one = {
69+
auto_scaling_group_arn = "arn:aws:autoscaling:eu-west-1:012345678901:autoScalingGroup:08419a61:autoScalingGroupName/ecs-ec2-one-20220603194933774300000011"
70+
managed_termination_protection = "ENABLED"
71+
72+
managed_scaling = {
73+
maximum_scaling_step_size = 5
74+
minimum_scaling_step_size = 1
75+
status = "ENABLED"
76+
target_capacity = 60
77+
}
78+
79+
default_capacity_provider_strategy = {
80+
weight = 60
81+
base = 20
82+
}
83+
}
84+
two = {
85+
auto_scaling_group_arn = "arn:aws:autoscaling:eu-west-1:012345678901:autoScalingGroup:08419a61:autoScalingGroupName/ecs-ec2-two-20220603194933774300000022"
86+
managed_termination_protection = "ENABLED"
87+
88+
managed_scaling = {
89+
maximum_scaling_step_size = 15
90+
minimum_scaling_step_size = 5
91+
status = "ENABLED"
92+
target_capacity = 90
93+
}
94+
95+
default_capacity_provider_strategy = {
96+
weight = 40
97+
}
98+
}
99+
}
100+
101+
tags = {
102+
Environment = "Development"
103+
Project = "EcsEc2"
104+
}
105+
}
106+
```
107+
108+
### Fargate & EC2 Autoscaling Capacity Providers
109+
14110
```hcl
15111
module "ecs" {
16112
source = "terraform-aws-modules/ecs/aws"
17113
18-
name = "my-ecs"
114+
name = "ecs-mixed"
19115
20-
container_insights = true
116+
cluster_configuration = {
117+
execute_command_configuration = {
118+
logging = "OVERRIDE"
119+
log_configuration = {
120+
cloud_watch_log_group_name = "/aws/ecs/aws-ec2"
121+
}
122+
}
123+
}
21124
22-
capacity_providers = ["FARGATE", "FARGATE_SPOT"]
125+
fargate_capacity_providers = {
126+
FARGATE = {
127+
default_capacity_provider_strategy = {
128+
weight = 50
129+
}
130+
}
131+
FARGATE_SPOT = {
132+
default_capacity_provider_strategy = {
133+
weight = 50
134+
}
135+
}
136+
}
23137
24-
default_capacity_provider_strategy = [
25-
{
26-
capacity_provider = "FARGATE_SPOT"
138+
autoscaling_capacity_providers = {
139+
one = {
140+
auto_scaling_group_arn = "arn:aws:autoscaling:eu-west-1:012345678901:autoScalingGroup:08419a61:autoScalingGroupName/ecs-ec2-one-20220603194933774300000011"
141+
managed_termination_protection = "ENABLED"
142+
143+
managed_scaling = {
144+
maximum_scaling_step_size = 5
145+
minimum_scaling_step_size = 1
146+
status = "ENABLED"
147+
target_capacity = 60
148+
}
149+
150+
default_capacity_provider_strategy = {
151+
weight = 60
152+
base = 20
153+
}
27154
}
28-
]
155+
two = {
156+
auto_scaling_group_arn = "arn:aws:autoscaling:eu-west-1:012345678901:autoScalingGroup:08419a61:autoScalingGroupName/ecs-ec2-two-20220603194933774300000022"
157+
managed_termination_protection = "ENABLED"
158+
159+
managed_scaling = {
160+
maximum_scaling_step_size = 15
161+
minimum_scaling_step_size = 5
162+
status = "ENABLED"
163+
target_capacity = 90
164+
}
165+
166+
default_capacity_provider_strategy = {
167+
weight = 40
168+
}
169+
}
170+
}
29171
30172
tags = {
31173
Environment = "Development"
174+
Project = "EcsEc2"
32175
}
33176
}
34177
```
35178

36-
## Conditional creation
179+
## Conditional Creation
37180

38-
Sometimes you need to have a way to create ECS resources conditionally but Terraform does not allow to use `count` inside `module` block, so the solution is to specify argument `create_ecs`.
181+
The following values are provided to toggle on/off creation of the associated resources as desired:
39182

40183
```hcl
41-
# ECS cluster will not be created
42184
module "ecs" {
43185
source = "terraform-aws-modules/ecs/aws"
44-
version = "~> 2.0"
45186
46-
create_ecs = false
187+
# Disable creation of cluster and all resources
188+
create = false
189+
47190
# ... omitted
48191
}
49192
```
50193

51194
## Examples
52195

53-
- [Complete ECS](https://github.com/terraform-aws-modules/terraform-aws-ecs/tree/master/examples/complete-ecs)
196+
- [ECS Cluster w/ EC2 Autoscaling Capacity Provider](https://github.com/terraform-aws-modules/terraform-aws-ecs/tree/master/examples/complete)
197+
- [ECS Cluster w/ Fargate Capacity Provider](https://github.com/terraform-aws-modules/terraform-aws-ecs/tree/master/examples/fargate)
54198

55199
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
56200
## Requirements
57201

58202
| Name | Version |
59203
|------|---------|
60-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
61-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.74 |
204+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
205+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.6 |
62206

63207
## Providers
64208

65209
| Name | Version |
66210
|------|---------|
67-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.74 |
211+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.6 |
68212

69213
## Modules
70214

@@ -74,27 +218,30 @@ No modules.
74218

75219
| Name | Type |
76220
|------|------|
221+
| [aws_ecs_capacity_provider.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_capacity_provider) | resource |
77222
| [aws_ecs_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster) | resource |
78223
| [aws_ecs_cluster_capacity_providers.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster_capacity_providers) | resource |
79224

80225
## Inputs
81226

82227
| Name | Description | Type | Default | Required |
83228
|------|-------------|------|---------|:--------:|
84-
| <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 |
85-
| <a name="input_container_insights"></a> [container\_insights](#input\_container\_insights) | Controls if ECS Cluster has container insights enabled | `bool` | `false` | no |
86-
| <a name="input_create_ecs"></a> [create\_ecs](#input\_create\_ecs) | Controls if ECS should be created | `bool` | `true` | no |
87-
| <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 |
88-
| <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 |
89-
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to ECS Cluster | `map(string)` | `{}` | no |
229+
| <a name="input_autoscaling_capacity_providers"></a> [autoscaling\_capacity\_providers](#input\_autoscaling\_capacity\_providers) | Map of autoscaling capacity provider definitons to create for the cluster | `any` | `{}` | no |
230+
| <a name="input_cluster_configuration"></a> [cluster\_configuration](#input\_cluster\_configuration) | The execute command configuration for the cluster | `any` | `{}` | no |
231+
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the cluster (up to 255 letters, numbers, hyphens, and underscores) | `string` | `""` | no |
232+
| <a name="input_cluster_settings"></a> [cluster\_settings](#input\_cluster\_settings) | Configuration block(s) with cluster settings. For example, this can be used to enable CloudWatch Container Insights for a cluster | `map(string)` | <pre>{<br> "name": "containerInsights",<br> "value": "enabled"<br>}</pre> | no |
233+
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no |
234+
| <a name="input_fargate_capacity_providers"></a> [fargate\_capacity\_providers](#input\_fargate\_capacity\_providers) | Map of Fargate capacity provider definitions to use for the cluster | `any` | `{}` | no |
235+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
90236

91237
## Outputs
92238

93239
| Name | Description |
94240
|------|-------------|
95-
| <a name="output_ecs_cluster_arn"></a> [ecs\_cluster\_arn](#output\_ecs\_cluster\_arn) | ARN of the ECS Cluster |
96-
| <a name="output_ecs_cluster_id"></a> [ecs\_cluster\_id](#output\_ecs\_cluster\_id) | ID of the ECS Cluster |
97-
| <a name="output_ecs_cluster_name"></a> [ecs\_cluster\_name](#output\_ecs\_cluster\_name) | The name of the ECS cluster |
241+
| <a name="output_autoscaling_capacity_providers"></a> [autoscaling\_capacity\_providers](#output\_autoscaling\_capacity\_providers) | Map of autoscaling capacity providers created and their attributes |
242+
| <a name="output_cluster_arn"></a> [cluster\_arn](#output\_cluster\_arn) | ARN that identifies the cluster |
243+
| <a name="output_cluster_capacity_providers"></a> [cluster\_capacity\_providers](#output\_cluster\_capacity\_providers) | Map of cluster capacity providers attributes |
244+
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | ID that identifies the cluster |
98245
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
99246

100247
## Authors

0 commit comments

Comments
 (0)