Skip to content

Commit 1c55b83

Browse files
committed
chore: Update upgrade guide, add container definition example for testing
1 parent f3c9f66 commit 1c55b83

File tree

10 files changed

+612
-15
lines changed

10 files changed

+612
-15
lines changed

docs/UPGRADE-6.0.md

Lines changed: 183 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ If you find a bug, please open an issue with supporting configuration to reprodu
55

66
## List of backwards incompatible changes
77

8-
- Terraform v1.5.7 is now minimum supported version
9-
- AWS provider v6.0.0 is now minimum supported version
8+
- Terraform `v1.5.7` is now minimum supported version
9+
- AWS provider `v6.0.0` is now minimum supported version
10+
- The attributes used to construct the container definition(s) have been changed from HCL's norm of `snake_case` to `camelCase` to match the AWS API. There currently isn't a [resource nor data source for the container definition](https://github.com/hashicorp/terraform-provider-aws/issues/17988), so one is constructed entirely from HCL in the `container-definition` sub-module. This definition is then rendered as JSON when presented to the task definition (or task set) APIs. Previously, the variable names used were `snake_case` and then internally converted to `camelCase`. However, this does not allow for [using the `container-definition` sub-module on its own](https://github.com/terraform-aws-modules/terraform-aws-ecs/issues/147) due to the mismatch between casing. Its probably going to trip a few folks up, but hopefully we'll remove this for a data source in the future.
11+
- `security_group_rules` has been split into `security_group_ingress_rules` and `security_group_egress_rules` to better match the AWS API and allow for more flexibility in defining security group rules.
12+
- Default permissive permissions for SSM parameter ARNs and Secrets Manager secret ARNs have been removed throughout. While this made it easier for users since it "just worked", it was not secure and could lead to unexpected access to resources. Users should now explicitly define the permissions they need in their IAM policies.
13+
- The "hack" put in place to track the task definition version when updating outside of the module has been removed. Instead, users should rely on the `track_latest` variable to ensure that the latest task definition is used when updating the service. Any issues with tracking the task definition version should be reported to the *ECS service team* as it is a limitation of the AWS ECS service/API and not the module itself.
14+
- The inline policy for the Tasks role of the `service` sub-module has been replaced with a standalone IAM policy. In some organizations, inline policies are not allowed.
15+
- The default for the `container-definition` `user` has been changed from `0` to `null`.
1016

1117
## Additional changes
1218

1319
### Added
1420

1521
- Support for `region` parameter to specify the AWS region for the resources created if different from the provider region.
22+
- Support for ECS infrastructure IAM role creation in the `service` sub-module. This role is used to manage ECS infrastructure resources https://docs.aws.amazon.com/AmazonECS/latest/developerguide/infrastructure_IAM_role.html
1623

1724
### Modified
1825

@@ -22,35 +29,148 @@ If you find a bug, please open an issue with supporting configuration to reprodu
2229

2330
1. Removed variables:
2431

25-
-
32+
- `default_capacity_provider_use_fargate`
33+
- `fargate_capacity_providers`
34+
35+
- `cluster` sub-module
36+
- `fargate_capacity_providers`; part of `default_capacity_provider_strategy` now
37+
- `default_capacity_provider_use_fargate`
38+
39+
- `container-definition` sub-module
40+
- None
41+
42+
- `service` sub-module
43+
- `inference_accelerator`
44+
2645

2746
2. Renamed variables:
2847

29-
-
48+
- `cluster_settings` -> `cluster_setting`
49+
50+
- `cluster` sub-module
51+
- `cluster_configuration` - `configuration`
52+
- `cluster_settings` - `setting`
53+
- `cluster_service_connect_defaults` - `service_connect_defaults`
54+
55+
- `container-definition` sub-module
56+
- `dependencies` - `dependsOn`
57+
- `disable_networking` - `disableNetworking`
58+
- `dns_search_domains` - `dnsSearchDomains`
59+
- `dns_servers` - `dnsServers`
60+
- `docker_labels` - `dockerLabels`
61+
- `docker_security_options` - `dockerSecurityOptions`
62+
- `environment_files` - `environmentFiles`
63+
- `extra_hosts` - `extraHosts`
64+
- `firelens_configuration` - `firelensConfiguration`
65+
- `health_check` - `healthCheck`
66+
- `linux_parameters` - `linuxParameters`
67+
- `log_configuration` - `logConfiguration`
68+
- `memory_reservation` - `memoryReservation`
69+
- `mount_points` - `mountPoints`
70+
- `port_mappings` - `portMappings`
71+
- `psuedo_terminal` - `pseudoTerminal`
72+
- `readonly_root_filesystem` - `readonlyRootFilesystem`
73+
- `repository_credentials` - `repositoryCredentials`
74+
- `start_timeout` - `startTimeout`
75+
- `system_controls` - `systemControls`
76+
- `volumes_from` - `volumesFrom`
77+
- `working_directory` - `workingDirectory`
78+
79+
- `service` sub-module
80+
- None
3081

3182
3. Added variables:
3283

33-
-
84+
- `cloudwatch_log_group_class`
85+
- `default_capacity_provider_strategy`
86+
87+
- `cluster` sub-module
88+
- `cloudwatch_log_group_class`
89+
- `default_capacity_provider_strategy` - replaces `fargate_capacity_providers` and `default_capacity_provider_use_fargate` functionality
90+
91+
- `container-definition` sub-module
92+
- `log_group_class`
93+
- `restartPolicy` - defaults to `enabled = true`
94+
- `versionConsistency` - defaults to `"disabled"` https://github.com/aws/containers-roadmap/issues/2394
95+
96+
- `service` sub-module
97+
- `availability_zone_rebalancing`
98+
- `volume_configuration`
99+
- `vpc_lattice_configurations`
100+
- `enable_fault_injection`
101+
- `track_latest`
102+
- `create_infrastructure_iam_role`
103+
- `infrastructure_iam_role_arn`
104+
- `infrastructure_iam_role_name`
105+
- `infrastructure_iam_role_use_name_prefix`
106+
- `infrastructure_iam_role_path`
107+
- `infrastructure_iam_role_description`
108+
- `infrastructure_iam_role_permissions_boundary`
109+
- `infrastructure_iam_role_tags`
34110

35111
4. Removed outputs:
36112

37-
-
113+
- `cluster` sub-module
114+
- None
115+
- `container-definition` sub-module
116+
- None
117+
- `service` sub-module
118+
- `task_definition_family_revision`
38119

39120
5. Renamed outputs:
40121

41-
-
122+
- `cluster` sub-module
123+
- None
124+
- `container-definition` sub-module
125+
- None
126+
- `service` sub-module
127+
- None
42128

43129
6. Added outputs:
44130

45-
-
131+
- `cluster` sub-module
132+
- None
133+
- `container-definition` sub-module
134+
- None
135+
- `service` sub-module
136+
- `infrastructure_iam_role_arn`
137+
- `infrastructure_iam_role_name`
46138

47139
## Upgrade Migrations
48140

49141
### Before 5.x Example
50142

143+
#### Cluster Sub-Module
144+
51145
```hcl
52-
module "ecs" {
53-
source = "terraform-aws-modules/ecs/aws"
146+
module "ecs_cluster" {
147+
source = "terraform-aws-modules/ecs/aws//modules/cluster"
148+
version = "~> 5.0"
149+
150+
# Truncated for brevity ...
151+
152+
# Capacity provider
153+
fargate_capacity_providers = {
154+
FARGATE = {
155+
default_capacity_provider_strategy = {
156+
weight = 50
157+
base = 20
158+
}
159+
}
160+
FARGATE_SPOT = {
161+
default_capacity_provider_strategy = {
162+
weight = 50
163+
}
164+
}
165+
}
166+
}
167+
```
168+
169+
#### Service Sub-Module
170+
171+
```hcl
172+
module "ecs_service" {
173+
source = "terraform-aws-modules/ecs/aws//modules/service"
54174
version = "~> 5.0"
55175
56176
# Truncated for brevity ...
@@ -122,6 +242,18 @@ module "ecs" {
122242
}
123243
}
124244
245+
service_connect_configuration = {
246+
namespace = aws_service_discovery_http_namespace.this.arn
247+
service = {
248+
client_alias = {
249+
port = 3000
250+
dns_name = "ecsdemo-frontend"
251+
}
252+
port_name = "ecsdemo-frontend"
253+
discovery_name = "ecsdemo-frontend"
254+
}
255+
}
256+
125257
security_group_rules = {
126258
alb_ingress_3000 = {
127259
type = "ingress"
@@ -142,10 +274,32 @@ module "ecs" {
142274

143275
### After 6.x Example
144276

145-
#### Service
277+
#### Cluster Sub-Module
146278

147279
```hcl
148-
module "ecs" {
280+
module "ecs_cluster" {
281+
source = "terraform-aws-modules/ecs/aws//modules/cluster"
282+
version = "~> 6.0"
283+
284+
# Truncated for brevity ...
285+
286+
# Cluster capacity providers
287+
default_capacity_provider_strategy = {
288+
FARGATE = {
289+
weight = 50
290+
base = 20
291+
}
292+
FARGATE_SPOT = {
293+
weight = 50
294+
}
295+
}
296+
}
297+
```
298+
299+
#### Service Sub-Module
300+
301+
```hcl
302+
module "ecs_service" {
149303
source = "terraform-aws-modules/ecs/aws//modules/service"
150304
version = "~> 6.0"
151305
@@ -224,6 +378,20 @@ module "ecs" {
224378
}
225379
}
226380
381+
service_connect_configuration = {
382+
namespace = aws_service_discovery_http_namespace.this.arn
383+
service = [
384+
{
385+
client_alias = {
386+
port = 3000
387+
dns_name = "ecsdemo-frontend"
388+
}
389+
port_name = "ecsdemo-frontend"
390+
discovery_name = "ecsdemo-frontend"
391+
}
392+
]
393+
}
394+
227395
security_group_ingress_rules = {
228396
alb_3000 = {
229397
description = "Service port"
@@ -242,15 +410,16 @@ module "ecs" {
242410

243411
### State Changes
244412

245-
#### Service
413+
#### Service Sub-Module
414+
415+
Due to the change from `aws_security_group_rule` to `aws_vpc_security_group_ingress_rule` and `aws_vpc_security_group_egress_rule`, the following reference state changes are required to maintain the current security group rules. (Note: these are different resources so they cannot be moved with `terraform mv ...`)
246416

247417
```sh
248418
terraform state rm 'module.ecs_service.aws_security_group_rule.this["alb_ingress_3000"]'
249419
terraform state import 'module.ecs_service.aws_vpc_security_group_ingress_rule.this["alb_3000"]' 'sg-xxx'
250420

251421
terraform state rm 'module.ecs_service.aws_security_group_rule.this["egress_all"]'
252422
terraform state import 'module.ecs_service.aws_vpc_security_group_egress_rule.this["all"]' 'sg-xxx'
253-
254423
```
255424

256425
The inline tasks `aws_iam_role_policy` cannot be moved or imported into a standalone `aws_iam_policy`. It must be re-created.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ECS Container Definition
2+
3+
Configuration in this directory creates:
4+
5+
- ECS container definition
6+
7+
## Usage
8+
9+
To run this example you need to execute:
10+
11+
```bash
12+
$ terraform init
13+
$ terraform plan
14+
$ terraform apply
15+
```
16+
17+
Note that this example may create resources which will incur monetary charges on your AWS bill. Run `terraform destroy` when you no longer need these resources.
18+
19+
<!-- BEGIN_TF_DOCS -->
20+
## Requirements
21+
22+
| Name | Version |
23+
|------|---------|
24+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
25+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
26+
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 2.5 |
27+
28+
## Providers
29+
30+
| Name | Version |
31+
|------|---------|
32+
| <a name="provider_local"></a> [local](#provider\_local) | >= 2.5 |
33+
34+
## Modules
35+
36+
| Name | Source | Version |
37+
|------|--------|---------|
38+
| <a name="module_ecs_container_definition"></a> [ecs\_container\_definition](#module\_ecs\_container\_definition) | ../../modules/container-definition | n/a |
39+
40+
## Resources
41+
42+
| Name | Type |
43+
|------|------|
44+
| [local_file.container_definition_json](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
45+
46+
## Inputs
47+
48+
No inputs.
49+
50+
## Outputs
51+
52+
| Name | Description |
53+
|------|-------------|
54+
| <a name="output_cloudwatch_log_group_arn"></a> [cloudwatch\_log\_group\_arn](#output\_cloudwatch\_log\_group\_arn) | ARN of CloudWatch log group created |
55+
| <a name="output_cloudwatch_log_group_name"></a> [cloudwatch\_log\_group\_name](#output\_cloudwatch\_log\_group\_name) | Name of CloudWatch log group created |
56+
| <a name="output_container_definition"></a> [container\_definition](#output\_container\_definition) | Container definition |
57+
| <a name="output_container_definition_json"></a> [container\_definition\_json](#output\_container\_definition\_json) | Container definition |
58+
<!-- END_TF_DOCS -->
59+
60+
## License
61+
62+
Apache-2.0 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-aws-ecs/blob/master/LICENSE).

0 commit comments

Comments
 (0)