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.61k stars 9k forks source link

[Bug]: aws_ecs_task_definition outputs container definitions in different order to input #38208

Open mathew-hall opened 4 days ago

mathew-hall commented 4 days ago

Terraform Core Version

1.5.2

AWS Provider Version

5.56.1

Affected Resource(s)

Expected Behavior

The container_definitions output of the resource should be returned in identical order to the inputs provided

Actual Behavior

The container_definitions property of the resource is sorted, meaning the input order is lost

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_ecs_task_definition" "test" {
  family                   = "test"
  requires_compatibilities = ["FARGATE"]
  network_mode             = "awsvpc"
  cpu                      = 1024
  memory                   = 2048
  container_definitions    = jsonencode(
  [
    {
      "name": "3",
      "image": "bash",
      "essential": true
    },
    {
      "name": "2",
      "image": "bash",
      "essential": true
    },
    {
      "name": "1",
      "image": "bash",
      "essential": true
    },
  ]  
  )
}

output "example"  {
  value = jsondecode(aws_ecs_task_definition.test.container_definitions)[0]
}

Steps to Reproduce

  1. Create a task definition with at least 2 container_definition entries in its JSON
  2. Read the output of the task definition back and jsondecode it
  3. Index into that list and see that the tasks are reordered

Debug Output

No response

Panic Output

No response

Important Factoids

Our use case is niche as we require reading the task definition out of the terraform state for other processes, and we can work around it, but given the AWS API defines them as a list (and not a map) it would perhaps make sense to do the drift detection on an internal sorted copy of the definitions vs the supplied definitions to preserve the order.

References

It appears this was introduced in https://github.com/hashicorp/terraform-provider-aws/pull/35792 as it now seems to internally sort the list.

Would you like to implement a fix?

None

github-actions[bot] commented 4 days ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue