Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 5.59.0 modifies capitalization of JSON keys unexpectedly #38543

Closed
alanszlosek opened this issue Jul 25, 2024 · 8 comments · Fixed by #38622
Closed

[Bug]: 5.59.0 modifies capitalization of JSON keys unexpectedly #38543

alanszlosek opened this issue Jul 25, 2024 · 8 comments · Fixed by #38622
Assignees
Labels
bug Addresses a defect in current functionality. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. service/ecs Issues and PRs that pertain to the ecs service.
Milestone

Comments

@alanszlosek
Copy link

alanszlosek commented Jul 25, 2024

Terraform Core Version

1.9.2

AWS Provider Version

5.59.0

Affected Resource(s)

  • aws_ecs_task_definition
  • Any resource where JSON data is or can be used as part of the HCL

Expected Behavior

If Terraform configuration contains an aws_ecs_task_definition with "cpu" in the container_definitions JSON, I expect "cpu" to be present in the JSON within the plan.

I use tools that inspect HCL and the Terraform plan to enforce compliance. For some checks, they need to analyze JSON data from the plan. The new provider changes the capitalization of JSON keys, which breaks JSON analysis.

Actual Behavior

The "cpu" field from the JSON for an ecs task container definition is showing in the plan as "Cpu". The compliance tools I use were configured to look for "cpu", following the AWS JSON schema, so they can't perform the compliance check.

But again, this issue isn't limited to the ECS task definition resource. The problem likely affects any resources where JSON data can be used.

Relevant Error/Panic Output Snippet

# aws_ecs_task_definition.service will be created
  + resource "aws_ecs_task_definition" "service" {
      + arn                   = (known after apply)
      + arn_without_revision  = (known after apply)
      + container_definitions = jsonencode(
            [
              + {
                  + Command                = null
                  + Cpu                    = 10
                  + CredentialSpecs        = null
                  + DependsOn              = null
                  + DisableNetworking      = null
                  + DnsSearchDomains       = null
                  + DnsServers             = null
                  + DockerLabels           = null
                  + DockerSecurityOptions  = null
                  + EntryPoint             = null
                  + Environment            = null
                  + EnvironmentFiles       = null
                  + Essential              = true
                  + ExtraHosts             = null
                  + FirelensConfiguration  = null
                  + HealthCheck            = null
                  + Hostname               = null
                  + Image                  = "alpine"
                  + Interactive            = null
                  + Links                  = null
                  + LinuxParameters        = null
                  + LogConfiguration       = null
                  + Memory                 = 512
                  + MemoryReservation      = null
                  + MountPoints            = null
                  + Name                   = "first"
                  + PortMappings           = [
                      + {
                          + AppProtocol        = ""
                          + ContainerPort      = 80
                          + ContainerPortRange = null
                          + HostPort           = 80
                          + Name               = null
                          + Protocol           = ""
                        },
                    ]
                  + Privileged             = null
                  + PseudoTerminal         = null
                  + ReadonlyRootFilesystem = null
                  + RepositoryCredentials  = null
                  + ResourceRequirements   = null
                  + Secrets                = null
                  + StartTimeout           = null
                  + StopTimeout            = null
                  + SystemControls         = null
                  + Ulimits                = null
                  + User                   = null
                  + VolumesFrom            = null
                  + WorkingDirectory       = null
                },
            ]
        )
      + family                = "service"
      + id                    = (known after apply)
      + network_mode          = (known after apply)
      + revision              = (known after apply)
      + skip_destroy          = false
      + tags_all              = (known after apply)
      + track_latest          = false
    }

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.59.0"
    }
  }
}

resource "aws_ecs_task_definition" "service" {
  family = "service"
  container_definitions = jsonencode([
    {
      name      = "first"
      image     = "alpine"
      cpu       = 10
      memory    = 512
      essential = true
      portMappings = [
        {
          containerPort = 80
          hostPort      = 80
        }
      ]
    }
  ])
}

Steps to Reproduce

terraform init followed by terraform plan.

If you modify the HCL to toggle between 5.58.0 and 5.59.0 you can see the change in capitalization.

Debug Output

No response

Panic Output

No response

Important Factoids

Reverting back to 5.58.0 fixes the problem.

References

No response

Would you like to implement a fix?

No

@alanszlosek alanszlosek added the bug Addresses a defect in current functionality. label Jul 25, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/ecs Issues and PRs that pertain to the ecs service. label Jul 25, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Jul 25, 2024
@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Jul 26, 2024
@ewbankkit ewbankkit self-assigned this Jul 26, 2024
@terraform-aws-provider terraform-aws-provider bot added the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Jul 26, 2024
@0xabdi
Copy link

0xabdi commented Jul 30, 2024

I can confirm the same exists in version 5.60.0 of the terraform AWS provider.

@ewbankkit what is the ETA for having this fixed? It is currently breaking our policy as code engine that enforces compliance on the terraform plan.

@ewbankkit ewbankkit added the regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. label Jul 30, 2024
@ewbankkit
Copy link
Contributor

This is caused by the AWS SDK for Go v2 migration of the ECS service (#38016). Previously JSON encoding routines in the AWS SDK for Go v1 were used for conversion of the Terraform configured JSON to the AWS API structures and vice-versa (#38380) and the migration replaced these with Go standard JSON functionality.
With SDK v1 the relevant AWS API ContainerDefinition structure had its own struct tags with initial lowercase field names: https://github.com/aws/aws-sdk-go/blob/d46b35a961c828998b8f0feda7a9437e5490791d/service/ecs/api.go#L8558-L9192.
The equivalent SDK v2 structure, https://github.com/aws/aws-sdk-go-v2/blob/99219561632de13ccd9d1fc800acb574d1212270/service/ecs/types/types.go#L631-L1335, has no struct tags and so the default behavior of uppercasing the field names is used.

@jonnangle
Copy link

@ewbankkit thanks for this! Will the provider be reverting to the previous behaviour, or should we plan to migrate to the new uppercased field names?

@ewbankkit
Copy link
Contributor

@jonnangle We will restore the previous (v5.58.0) behavior.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.61.0 milestone Jul 31, 2024
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Aug 2, 2024
Copy link

github-actions bot commented Aug 2, 2024

This functionality has been released in v5.61.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

github-actions bot commented Sep 1, 2024

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. service/ecs Issues and PRs that pertain to the ecs service.
Projects
None yet
4 participants