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

resource/aws_ecr_repository_policy: Update policy in state on read #7853

Conversation

chrisdcmoore
Copy link
Contributor

@chrisdcmoore chrisdcmoore commented Mar 7, 2019

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Description

Whilst using terraform to manage ECR repositories and their policies, I noticed that changing the policy directly in the AWS Console didn't cause my terraform plan to show any changes required. Running terraform refresh with debugging turned on showed that the modified version of the policy was being returned by the AWS API, but doing a subsequent terraform state pull and inspecting the state showed that the policy in the state hadn't been updated.

Changes proposed in this pull request:

  • In aws_ecr_repository_policy, update the policy property on the schema when pulling the policy from the AWS API.
  • In aws_ecr_repository_policy, suppress diffs between equivalent policies via the JSON diff suppressor

@ghost ghost added service/ecr Issues and PRs that pertain to the ecr service. size/XS Managed by automation to categorize the size of a PR. labels Mar 7, 2019
@bflad bflad added the bug Addresses a defect in current functionality. label Mar 8, 2019
@bflad bflad added this to the v2.2.0 milestone Mar 14, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Hi @chrisdcmoore 👋 Thank you so much for finding this and providing a fix. I hope you don't mind if I make one very minor adjustment in a commit after yours on merge (79e0160) to switch from using the suppressEquivalentJsonDiffs function to the suppressEquivalentAwsPolicyDiffs as it is more suited for ignoring equivalent IAM policy JSON documents and fixes these acceptance testing errors I received:

--- FAIL: TestAccAWSEcrRepositoryPolicy_basic (6.20s)
    testing.go:538: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_ecr_repository_policy.default
          policy: "{\n  \"Version\" : \"2008-10-17\",\n  \"Statement\" : [ {\n    \"Sid\" : \"testpolicy\",\n    \"Effect\" : \"Allow\",\n    \"Principal\" : \"*\",\n    \"Action\" : \"ecr:ListImages\"\n  } ]\n}" => "{\n    \"Version\": \"2008-10-17\",\n    \"Statement\": [\n        {\n            \"Sid\": \"testpolicy\",\n            \"Effect\": \"Allow\",\n            \"Principal\": \"*\",\n            \"Action\": [\n                \"ecr:ListImages\"\n            ]\n        }\n    ]\n}\n"

--- FAIL: TestAccAWSEcrRepositoryPolicy_iam (14.04s)
    testing.go:538: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: aws_ecr_repository_policy.default
          policy: "{\n  \"Version\" : \"2008-10-17\",\n  \"Statement\" : [ {\n    \"Sid\" : \"testpolicy\",\n    \"Effect\" : \"Allow\",\n    \"Principal\" : {\n      \"AWS\" : \"arn:aws:iam::--OMITTED--:role/tf-acc-test-ecr-o2wwkel9us\"\n    },\n    \"Action\" : \"ecr:ListImages\"\n  } ]\n}" => "{\n    \"Version\": \"2008-10-17\",\n    \"Statement\": [\n        {\n            \"Sid\": \"testpolicy\",\n            \"Effect\": \"Allow\",\n            \"Principal\": {\n              \"AWS\": \"arn:aws:iam::--OMITTED--:role/tf-acc-test-ecr-o2wwkel9us\"\n            },\n            \"Action\": [\n                \"ecr:ListImages\"\n            ]\n        }\n    ]\n}\n"

Output from acceptance testing after DiffSuppressFunc adjustment:

--- PASS: TestAccAWSEcrRepositoryPolicy_basic (6.18s)
--- PASS: TestAccAWSEcrRepositoryPolicy_iam (13.31s)

@bflad bflad merged commit 3fdcc24 into hashicorp:master Mar 14, 2019
bflad added a commit that referenced this pull request Mar 14, 2019
@bflad
Copy link
Contributor

bflad commented Mar 15, 2019

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

@chrisdcmoore
Copy link
Contributor Author

Hi @bflad

Much appreciated, sorry I didn't run the acceptance tests - first time contributing and wasn't sure what resources the acceptance tests would create in our AWS account - I'll get a new, isolated account set up for running them next time!

Thanks for the awesome work you all do!

@ghost
Copy link

ghost commented Mar 31, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
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/ecr Issues and PRs that pertain to the ecr service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants