hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.82k stars 9.17k forks source link

[Bug]: Permanent diff for `aws_ecs_task_definition` with null/empty values in environment variables #39533

Open flostadler opened 1 month ago

flostadler commented 1 month ago

Terraform Core Version

1.5.7

AWS Provider Version

5.69.0

Affected Resource(s)

Expected Behavior

When setting setting environment variables in aws_ecs_task_definition to null or the empty value AWS seems to filter out those environment variables when creating the Task Definition.

Running apply or preview should not detect changes if the aws_ecs_task_definition was not modified.

Actual Behavior

aws_ecs_task_definition permanently shows a diff when setting environment variables to null or the empty value.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

provider "aws" {
  region = "us-west-2"
}

resource "aws_ecs_task_definition" "example_task_definition" {
  family                = "example-service"
  container_definitions = jsonencode([
    {
      name      = "example-service"
      image     = "nginx"
      memory    = 128
      environment = [
        {
          name  = "EXAMPLE_VARIABLE"
          value = "" # Also happens for nulls
        }
      ]
    }
  ])
}

Steps to Reproduce

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

This could be fixed by filtering out nulls/empty values in the environment variables. The same is already done for the ecs_properties parameter of aws_batch_job_definition: https://github.com/hashicorp/terraform-provider-aws/blame/ad3a8be1c171039ddec00dd87d5e4e2ae8497519/internal/service/batch/ecs_properties.go#L84-L86

Would you like to implement a fix?

None

github-actions[bot] commented 1 month ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue