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

r/aws_ecs_task_definition: Ensure JSON keys in container_definitions have leading lowercase #38622

Merged

Conversation

ewbankkit
Copy link
Contributor

@ewbankkit ewbankkit commented Jul 31, 2024

Description

For

resource "aws_ecs_task_definition" "service" {
  family = "ewbankkit-test-002"
  container_definitions = jsonencode([
    {
      name      = "first"
      image     = "alpine"
      cpu       = 10
      memory    = 512
      essential = true
      portMappings = [
        {
          containerPort = 80
          hostPort      = 80
        }
      ]
    }
  ])
}
v5.58.0
% terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # 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(
            [
              + {
                  + cpu          = 10
                  + essential    = true
                  + image        = "alpine"
                  + memory       = 512
                  + name         = "first"
                  + portMappings = [
                      + {
                          + containerPort = 80
                          + hostPort      = 80
                        },
                    ]
                },
            ]
        )
      + family                = "ewbankkit-test-002"
      + id                    = (known after apply)
      + network_mode          = (known after apply)
      + revision              = (known after apply)
      + skip_destroy          = false
      + tags_all              = (known after apply)
      + track_latest          = false
    }

Plan: 1 to add, 0 to change, 0 to destroy.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run
"terraform apply" now.
v5.60.0
% terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  + create

Terraform will perform the following actions:

  # 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                = "ewbankkit-test-002"
      + id                    = (known after apply)
      + network_mode          = (known after apply)
      + revision              = (known after apply)
      + skip_destroy          = false
      + tags_all              = (known after apply)
      + track_latest          = false
    }

Plan: 1 to add, 0 to change, 0 to destroy.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run
"terraform apply" now.

This PR manipulates the JSON representation of container_definitions to

  • Remove empty values
  • Convert the first character of the keys to lowercase

Relations

Closes #38543.

Output from Acceptance Testing

Before fix

% make testacc TESTARGS='-run=TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression' PKG=ecs
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.5 test ./internal/service/ecs/... -v -count 1 -parallel 20  -run=TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression -timeout 360m
=== RUN   TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
=== PAUSE TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
=== CONT  TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
    task_definition_test.go:1254: Step 3/3 error: Check failed: Check 3/16 error: aws_ecs_task_definition.test: Attribute "container_definitions", JMESPath "[0].cpu" got "<nil>" (<nil>)
--- FAIL: TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression (66.61s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/ecs	71.407s
FAIL
make: *** [testacc] Error 1
% make testacc TESTARGS='-run=TestAccECSTaskDefinition_' PKG=ecs ACCTEST_PARALLELISM=3
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.5 test ./internal/service/ecs/... -v -count 1 -parallel 3  -run=TestAccECSTaskDefinition_ -timeout 360m
=== RUN   TestAccECSTaskDefinition_basic
=== PAUSE TestAccECSTaskDefinition_basic
=== RUN   TestAccECSTaskDefinition_scratchVolume
=== PAUSE TestAccECSTaskDefinition_scratchVolume
=== RUN   TestAccECSTaskDefinition_configuredAtLaunch
=== PAUSE TestAccECSTaskDefinition_configuredAtLaunch
=== RUN   TestAccECSTaskDefinition_DockerVolume_basic
=== PAUSE TestAccECSTaskDefinition_DockerVolume_basic
=== RUN   TestAccECSTaskDefinition_DockerVolume_minimal
=== PAUSE TestAccECSTaskDefinition_DockerVolume_minimal
=== RUN   TestAccECSTaskDefinition_runtimePlatform
=== PAUSE TestAccECSTaskDefinition_runtimePlatform
=== RUN   TestAccECSTaskDefinition_Fargate_runtimePlatform
=== PAUSE TestAccECSTaskDefinition_Fargate_runtimePlatform
=== RUN   TestAccECSTaskDefinition_Fargate_runtimePlatformWithoutArch
=== PAUSE TestAccECSTaskDefinition_Fargate_runtimePlatformWithoutArch
=== RUN   TestAccECSTaskDefinition_EFSVolume_minimal
=== PAUSE TestAccECSTaskDefinition_EFSVolume_minimal
=== RUN   TestAccECSTaskDefinition_EFSVolume_basic
=== PAUSE TestAccECSTaskDefinition_EFSVolume_basic
=== RUN   TestAccECSTaskDefinition_EFSVolume_transitEncryptionMinimal
=== PAUSE TestAccECSTaskDefinition_EFSVolume_transitEncryptionMinimal
=== RUN   TestAccECSTaskDefinition_EFSVolume_transitEncryption
=== PAUSE TestAccECSTaskDefinition_EFSVolume_transitEncryption
=== RUN   TestAccECSTaskDefinition_EFSVolume_transitEncryptionDisabled
=== PAUSE TestAccECSTaskDefinition_EFSVolume_transitEncryptionDisabled
=== RUN   TestAccECSTaskDefinition_EFSVolume_accessPoint
=== PAUSE TestAccECSTaskDefinition_EFSVolume_accessPoint
=== RUN   TestAccECSTaskDefinition_fsxWinFileSystem
=== PAUSE TestAccECSTaskDefinition_fsxWinFileSystem
=== RUN   TestAccECSTaskDefinition_DockerVolume_taskScoped
=== PAUSE TestAccECSTaskDefinition_DockerVolume_taskScoped
=== RUN   TestAccECSTaskDefinition_service
=== PAUSE TestAccECSTaskDefinition_service
=== RUN   TestAccECSTaskDefinition_taskRoleARN
=== PAUSE TestAccECSTaskDefinition_taskRoleARN
=== RUN   TestAccECSTaskDefinition_networkMode
=== PAUSE TestAccECSTaskDefinition_networkMode
=== RUN   TestAccECSTaskDefinition_ipcMode
=== PAUSE TestAccECSTaskDefinition_ipcMode
=== RUN   TestAccECSTaskDefinition_pidMode
=== PAUSE TestAccECSTaskDefinition_pidMode
=== RUN   TestAccECSTaskDefinition_constraint
=== PAUSE TestAccECSTaskDefinition_constraint
=== RUN   TestAccECSTaskDefinition_changeVolumesForcesNewResource
=== PAUSE TestAccECSTaskDefinition_changeVolumesForcesNewResource
=== RUN   TestAccECSTaskDefinition_arrays
=== PAUSE TestAccECSTaskDefinition_arrays
=== RUN   TestAccECSTaskDefinition_Fargate_basic
=== PAUSE TestAccECSTaskDefinition_Fargate_basic
=== RUN   TestAccECSTaskDefinition_Fargate_ephemeralStorage
=== PAUSE TestAccECSTaskDefinition_Fargate_ephemeralStorage
=== RUN   TestAccECSTaskDefinition_executionRole
=== PAUSE TestAccECSTaskDefinition_executionRole
=== RUN   TestAccECSTaskDefinition_disappears
=== PAUSE TestAccECSTaskDefinition_disappears
=== RUN   TestAccECSTaskDefinition_tags
=== PAUSE TestAccECSTaskDefinition_tags
=== RUN   TestAccECSTaskDefinition_proxy
=== PAUSE TestAccECSTaskDefinition_proxy
=== RUN   TestAccECSTaskDefinition_inferenceAccelerator
=== PAUSE TestAccECSTaskDefinition_inferenceAccelerator
=== RUN   TestAccECSTaskDefinition_invalidContainerDefinition
=== PAUSE TestAccECSTaskDefinition_invalidContainerDefinition
=== RUN   TestAccECSTaskDefinition_trackLatest
=== PAUSE TestAccECSTaskDefinition_trackLatest
=== RUN   TestAccECSTaskDefinition_unknownContainerDefinitions
=== PAUSE TestAccECSTaskDefinition_unknownContainerDefinitions
=== RUN   TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
=== PAUSE TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
=== CONT  TestAccECSTaskDefinition_basic
=== CONT  TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
=== CONT  TestAccECSTaskDefinition_taskRoleARN
--- PASS: TestAccECSTaskDefinition_taskRoleARN (14.41s)
=== CONT  TestAccECSTaskDefinition_unknownContainerDefinitions
--- PASS: TestAccECSTaskDefinition_basic (20.29s)
=== CONT  TestAccECSTaskDefinition_Fargate_ephemeralStorage
--- PASS: TestAccECSTaskDefinition_unknownContainerDefinitions (10.47s)
=== CONT  TestAccECSTaskDefinition_invalidContainerDefinition
--- PASS: TestAccECSTaskDefinition_invalidContainerDefinition (0.67s)
=== CONT  TestAccECSTaskDefinition_inferenceAccelerator
--- PASS: TestAccECSTaskDefinition_Fargate_ephemeralStorage (10.78s)
=== CONT  TestAccECSTaskDefinition_proxy
--- PASS: TestAccECSTaskDefinition_inferenceAccelerator (12.67s)
=== CONT  TestAccECSTaskDefinition_tags
--- PASS: TestAccECSTaskDefinition_proxy (22.50s)
=== CONT  TestAccECSTaskDefinition_disappears
--- PASS: TestAccECSTaskDefinition_disappears (14.87s)
=== CONT  TestAccECSTaskDefinition_executionRole
--- PASS: TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression (69.37s)
=== CONT  TestAccECSTaskDefinition_trackLatest
--- PASS: TestAccECSTaskDefinition_tags (36.56s)
=== CONT  TestAccECSTaskDefinition_EFSVolume_basic
--- PASS: TestAccECSTaskDefinition_trackLatest (10.56s)
=== CONT  TestAccECSTaskDefinition_Fargate_basic
--- PASS: TestAccECSTaskDefinition_executionRole (11.59s)
=== CONT  TestAccECSTaskDefinition_service
--- PASS: TestAccECSTaskDefinition_Fargate_basic (13.52s)
=== CONT  TestAccECSTaskDefinition_arrays
--- PASS: TestAccECSTaskDefinition_EFSVolume_basic (19.47s)
=== CONT  TestAccECSTaskDefinition_DockerVolume_taskScoped
--- PASS: TestAccECSTaskDefinition_DockerVolume_taskScoped (8.34s)
=== CONT  TestAccECSTaskDefinition_changeVolumesForcesNewResource
--- PASS: TestAccECSTaskDefinition_arrays (10.63s)
=== CONT  TestAccECSTaskDefinition_fsxWinFileSystem
--- PASS: TestAccECSTaskDefinition_changeVolumesForcesNewResource (17.47s)
=== CONT  TestAccECSTaskDefinition_constraint
--- PASS: TestAccECSTaskDefinition_constraint (12.58s)
=== CONT  TestAccECSTaskDefinition_EFSVolume_accessPoint
--- PASS: TestAccECSTaskDefinition_EFSVolume_accessPoint (24.48s)
=== CONT  TestAccECSTaskDefinition_pidMode
--- PASS: TestAccECSTaskDefinition_pidMode (11.60s)
=== CONT  TestAccECSTaskDefinition_EFSVolume_transitEncryptionDisabled
--- PASS: TestAccECSTaskDefinition_service (98.29s)
=== CONT  TestAccECSTaskDefinition_ipcMode
--- PASS: TestAccECSTaskDefinition_EFSVolume_transitEncryptionDisabled (19.67s)
=== CONT  TestAccECSTaskDefinition_EFSVolume_transitEncryption
--- PASS: TestAccECSTaskDefinition_ipcMode (11.35s)
=== CONT  TestAccECSTaskDefinition_networkMode
--- PASS: TestAccECSTaskDefinition_networkMode (11.38s)
=== CONT  TestAccECSTaskDefinition_EFSVolume_transitEncryptionMinimal
--- PASS: TestAccECSTaskDefinition_EFSVolume_transitEncryption (19.84s)
=== CONT  TestAccECSTaskDefinition_runtimePlatform
--- PASS: TestAccECSTaskDefinition_runtimePlatform (10.95s)
=== CONT  TestAccECSTaskDefinition_Fargate_runtimePlatformWithoutArch
--- PASS: TestAccECSTaskDefinition_EFSVolume_transitEncryptionMinimal (19.44s)
=== CONT  TestAccECSTaskDefinition_Fargate_runtimePlatform
--- PASS: TestAccECSTaskDefinition_Fargate_runtimePlatformWithoutArch (10.40s)
=== CONT  TestAccECSTaskDefinition_EFSVolume_minimal
--- PASS: TestAccECSTaskDefinition_Fargate_runtimePlatform (10.67s)
=== CONT  TestAccECSTaskDefinition_DockerVolume_basic
--- PASS: TestAccECSTaskDefinition_DockerVolume_basic (10.73s)
=== CONT  TestAccECSTaskDefinition_DockerVolume_minimal
--- PASS: TestAccECSTaskDefinition_EFSVolume_minimal (19.53s)
=== CONT  TestAccECSTaskDefinition_configuredAtLaunch
--- PASS: TestAccECSTaskDefinition_DockerVolume_minimal (10.30s)
=== CONT  TestAccECSTaskDefinition_scratchVolume
--- PASS: TestAccECSTaskDefinition_configuredAtLaunch (10.48s)
--- PASS: TestAccECSTaskDefinition_scratchVolume (10.65s)
--- PASS: TestAccECSTaskDefinition_fsxWinFileSystem (2746.58s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ecs	2855.237s

@ewbankkit ewbankkit requested a review from a team as a code owner July 31, 2024 16:16
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull 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.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/ecs Issues and PRs that pertain to the ecs service. service/ssm Issues and PRs that pertain to the ssm service. generators Relates to code generators. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. labels Jul 31, 2024
Copy link
Member

@jar-b jar-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

% make testacc PKG=ecs TESTS=TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.5 test ./internal/service/ecs/... -v -count 1 -parallel 20 -run='TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression'  -timeout 360m
=== RUN   TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
=== PAUSE TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
=== CONT  TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression
--- PASS: TestAccECSTaskDefinition_v5590ContainerDefinitionsRegression (95.90s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/ecs        101.916s

internal/acctest/acctest.go Show resolved Hide resolved
@ewbankkit ewbankkit merged commit 37bd1c1 into main Jul 31, 2024
36 checks passed
@ewbankkit ewbankkit deleted the b-aws_ecs_task_definition.container_definitions-json-uppercase branch July 31, 2024 18:09
@github-actions github-actions bot added this to the v5.61.0 milestone Jul 31, 2024
terraform-aws-provider bot pushed a commit that referenced this pull request Jul 31, 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 pull request 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 related to this change, 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
generators Relates to code generators. service/ecs Issues and PRs that pertain to the ecs service. service/ssm Issues and PRs that pertain to the ssm service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: 5.59.0 modifies capitalization of JSON keys unexpectedly
2 participants