cloudposse / terraform-aws-ecs-container-definition

Terraform module to generate well-formed JSON documents (container definitions) that are passed to the aws_ecs_task_definition Terraform resource
https://cloudposse.com/accelerate
Apache License 2.0
340 stars 245 forks source link

Terraform producing unnecessarily noisy diffs due to omitted lists #165

Open mightyguava opened 1 year ago

mightyguava commented 1 year ago

Describe the Bug

Moving from module version 0.58.2 to 0.60.0, Terraform is creating unnecessarily noisy diffs for empty list values. It doesn't impact whether a change is detected on the task definition or not, just the size of the diff, presumably due to the way Terraform is treating [] and omitted the same.

Pasting part of the diff below

              ~ {
                  - mountPoints            = []
                    name                   = "log-router"
                  - portMappings           = []
                  - volumesFrom            = []
                    # (8 unchanged attributes hidden)
                },
              ~ {
                  ~ environment            = [
                        # (2 unchanged elements hidden)
                        {
                            name  = "DD_LOGS_ENABLED"
                            value = "true"
                        },
                      ~ {
                            name  = "DD_VERSION"
                          ~ value = "fake-tag-for-template" -> "326d5e5572a9f7b4fd8c54fa243a84af094dac5b"
                        },
                        {
                            name  = "ECS_FARGATE"
                            value = "true"
                        },
                    ]
                  - mountPoints            = []
                    name                   = "datadog"
                  - volumesFrom            = []
                    # (7 unchanged attributes hidden)
                },

Expected Behavior

Here's a diff using 0.58.2. Notice that mountPoints, portMappings, and volumesFrom don't show that they are being removed.

                {
                    cpu                    = 0
                    environment            = []
                    essential              = true
                    firelensConfiguration  = {
                        options = {
                            enable-ecs-log-metadata = "true"
                        }
                        type    = "fluentbit"
                    }
                    image                  = "public.ecr.aws/aws-observability/aws-for-fluent-bit:latest"
                    logConfiguration       = {
                        logDriver = "awslogs"
                        options   = {
                            awslogs-group         = "main/fromagerie-job-migrate-from-unified-keysets"
                            awslogs-region        = "us-west-2"
                            awslogs-stream-prefix = "fluentbit"
                        }
                    }
                    mountPoints            = []
                    name                   = "log-router"
                    portMappings           = []
                    readonlyRootFilesystem = false
                    user                   = "0"
                    volumesFrom            = []
                },
              ~ {
                  ~ environment            = [
                        # (2 unchanged elements hidden)
                        {
                            name  = "DD_LOGS_ENABLED"
                            value = "true"
                        },
                      ~ {
                            name  = "DD_VERSION"
                          ~ value = "fake-tag-for-template" -> "326d5e5572a9f7b4fd8c54fa243a84af094dac5b"
                        },
                        {
                            name  = "ECS_FARGATE"
                            value = "true"
                        },
                    ]
                    name                   = "datadog"
                    # (9 unchanged attributes hidden)
                },
            ] # forces replacement

Steps to Reproduce

Run plan on any task definition with changes that would cause the task definition to be replaced, where mountPoints or portMappings, etc, is omitted from the container definition or an [] is provided.

Screenshots

No response

Environment

Terraform v1.4.6 on darwin_arm64

Additional Context

I think the problem is that the ECS task definition API is returning [] for list fields that are unset. Maybe these fields should be set to [] when not provided in the container definition as well? @go