Update the ECS Terraform module from major version 4 to 5
Version 5 of the module changed some resource addresses. Use terraform state mv
to move these addresses.
If you try to update to version 5 without moving the resources, Terraform will try to recreate the resources managed by the module.
Before you begin
You should familiarize yourself with the Terraform command for moving resources addresses (terraform state mv
).
Affected versions
Version 4 of the Terraform community module terraform-aws-modules/ecs/aws
.
You're not affected if you're using a private Terraform module sourced from oslokommune/golden-path-iac
.
How do I know what version I am using?
Go to the Terraform file defining your ECS cluster. See the source
and version
attributes.
Example:
Related issues
The template was updated in #752.
Step 1: Move resources
Move the cluster to its new address:
terraform state mv \
'module.ecs.aws_ecs_cluster.this[0]' \
'module.ecs.module.cluster.aws_ecs_cluster.this[0]'
Move the capacity provider:
terraform state mv \
'module.ecs.aws_ecs_cluster_capacity_providers.this[0]' \
'module.ecs.module.cluster.aws_ecs_cluster_capacity_providers.this[0]'
Step 2: Update your Terraform code
Edit the Terraform file for your ECS cluster:
- Bump the module version to 5
- Set
create_cloudwatch_log_group
tofalse
- Add a
cluster_configuration block
See an example of the end result link to Git diff, or this Git diff:
---
stacks/prod/app-common/ecs_cluster.tf | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/stacks/prod/app-common/ecs_cluster.tf b/stacks/prod/app-common/ecs_cluster.tf
index 3da83b9..baf3a3f 100644
--- a/stacks/prod/app-common/ecs_cluster.tf
+++ b/stacks/prod/app-common/ecs_cluster.tf
@@ -1,10 +1,18 @@
module "ecs" {
# https://github.com/terraform-aws-modules/terraform-aws-ecs
source = "terraform-aws-modules/ecs/aws"
- version = "4.1.3"
+ version = "5.0.1"
cluster_name = local.environment
+ create_cloudwatch_log_group = false
+
+ cluster_configuration = {
+ execute_command_configuration = {
+ logging = "DEFAULT"
+ }
+ }
+
fargate_capacity_providers = {
FARGATE = {
default_capacity_provider_strategy = {
Step 3: Apply the changes
Run terraform init -upgrade
.
Run terraform plan
.
If everything went well, there should be no changes: