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

aws_batch_job_definition gets recreated on every apply, even if the state does not change #19180

Closed
alex-bolenok-centralreach opened this issue Apr 30, 2021 · 4 comments · Fixed by #19207
Assignees
Labels
bug Addresses a defect in current functionality. service/batch Issues and PRs that pertain to the batch service.
Milestone

Comments

@alex-bolenok-centralreach
Copy link

alex-bolenok-centralreach commented Apr 30, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • 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
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.15.0
on windows_amd64
+ provider registry.terraform.io/hashicorp/aws v3.38.0

Affected Resource(s)

  • aws_batch_job_definition

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

locals {
  container_properties = {
    image            = "hello-world"
    executionRoleArn = var.execution_role_arn
    jobRoleArn       = var.job_role_arn
    resourceRequirements = [
      {
        type  = "MEMORY"
        value = "1024"
      },
      {
        type  = "VCPU"
        value = "0.5"
      }
    ]
    environment = [
      {
        name  = "b"
        value = "b"
      },
      {
        name  = "a"
        value = "a"
      }
    ],
    networkConfiguration = {
      assignPublicIp = "ENABLED"
    }
  }
}

resource "aws_batch_job_definition" "environment_bug_test" {
  name                  = "environment-bug-test"
  type                  = "container"
  container_properties  = jsonencode(local.container_properties)
  platform_capabilities = ["FARGATE"]
}

Debug Output

Panic Output

Expected Behavior

The state does not change so apply should not update anything

Actual Behavior

aws_batch_job_definition.environment_bug_test: Refreshing state... [id=arn:aws:batch:us-east-1:XXXXXXXXXXXX:job:job-definition/environment-bug-test:4]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # aws_batch_job_definition.environment_bug_test must be replaced
-/+ resource "aws_batch_job_definition" "environment_bug_test" {
      ~ arn                   = "arn:aws:batch:us-east-1:XXXXXXXXXXXX:job:job-definition/environment-bug-test:4" -> (known after apply)
      ~ container_properties  = jsonencode(
          ~ {
              - command                      = [] -> null
              ~ environment                  = [
                  - {
                      - name  = "a"
                      - value = "a"
                    },
                    {
                        name  = "b"
                        value = "b"
                    },
                  + {
                      + name  = "a"
                      + value = "a"
                    },
                ]
              - fargatePlatformConfiguration = {
                  - platformVersion = "LATEST"
                } -> null
              - mountPoints                  = [] -> null
              - secrets                      = [] -> null
              - ulimits                      = [] -> null
              - volumes                      = [] -> null
                # (5 unchanged elements hidden)
            } # forces replacement
        )
      ~ id                    = "arn:aws:batch:us-east-1:XXXXXXXXXXXX:job-definition/environment-bug-test:4" -> (known after apply)
        name                  = "environment-bug-test"
      - parameters            = {} -> null
      ~ revision              = 4 -> (known after apply)
      - tags                  = {} -> null
      ~ tags_all              = {} -> (known after apply)
        # (3 unchanged attributes hidden)
    }

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

Steps to Reproduce

  1. terraform apply
  2. terraform plan

Important Factoids

Container properties are being read from JSON and not from a module block.

AWS rearranges the environment values and adds default values to the JSON when reading the job definition.

The provider should be aware about the default values and should not care about the order of environment variables.

References

Relates: #16850.

@ghost ghost added the service/batch Issues and PRs that pertain to the batch service. label Apr 30, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 30, 2021
@ewbankkit ewbankkit added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Apr 30, 2021
@ewbankkit
Copy link
Contributor

I can reproduce. Will address.

@ewbankkit ewbankkit self-assigned this Apr 30, 2021
@ewbankkit
Copy link
Contributor

The workaround is to add

fargatePlatformConfiguration = {
  platformVersion = "LATEST"
}

to container_properties.

@ghost
Copy link

ghost commented May 7, 2021

This has been released in version 3.39.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 for triage. Thanks!

@github-actions
Copy link

github-actions bot commented Jun 6, 2021

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 Jun 6, 2021
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. service/batch Issues and PRs that pertain to the batch service.
Projects
None yet
2 participants