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

Changing terraform name of policy attachment caused provider bug: "Error: Provider produced inconsistent result after apply" #12127

Closed
arigesher opened this issue Feb 21, 2020 · 5 comments · Fixed by #18435
Assignees
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service.
Milestone

Comments

@arigesher
Copy link

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 Version

Terraform v0.12.20

  • provider.aws v2.44.0

Affected Resource(s)

  • aws_iam_role_policy_attachment

Terraform Configuration Files

Not provided

Debug Output

Panic Output

Expected Behavior

Simple apply

Actual Behavior

Terraform errored out with a message to file a bug on the provider:

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  - destroy

Terraform will perform the following actions:

  # aws_iam_role_policy_attachment.foreign_s3_access will be destroyed
  - resource "aws_iam_role_policy_attachment" "foreign_s3_access" {
      - id         = "tileservice-customer-nm-20200219070556171800000001" -> null
      - policy_arn = "arn:aws:iam::490182873131:policy/customer-nm-processed-s3-access" -> null
      - role       = "tileservice-customer-nm" -> null
    }

  # aws_iam_role_policy_attachment.pat_foreign_s3_access will be created
  + resource "aws_iam_role_policy_attachment" "pat_foreign_s3_access" {
      + id         = (known after apply)
      + policy_arn = "arn:aws:iam::490182873131:policy/customer-nm-processed-s3-access"
      + role       = "pat-customer-nm"
    }

  # aws_iam_role_policy_attachment.tileservice_foreign_s3_access will be created
  + resource "aws_iam_role_policy_attachment" "tileservice_foreign_s3_access" {
      + id         = (known after apply)
      + policy_arn = "arn:aws:iam::490182873131:policy/customer-nm-processed-s3-access"
      + role       = "tileservice-customer-nm"
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_iam_role_policy_attachment.foreign_s3_access: Destroying... [id=tileservice-customer-nm-20200219070556171800000001]
aws_iam_role_policy_attachment.tileservice_foreign_s3_access: Creating...
aws_iam_role_policy_attachment.pat_foreign_s3_access: Creating...
aws_iam_role_policy_attachment.foreign_s3_access: Destruction complete after 1s
aws_iam_role_policy_attachment.pat_foreign_s3_access: Creation complete after 1s [id=pat-customer-nm-20200221204549721200000002]

Error: Provider produced inconsistent result after apply

When applying changes to
aws_iam_role_policy_attachment.tileservice_foreign_s3_access, provider
"registry.terraform.io/-/aws" produced an unexpected new value for was
present, but now absent.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.

Steps to Reproduce

  1. terraform apply

Important Factoids

The policy attachment aws_iam_role_policy_attachment.tileservice_foreign_s3_access already existed with the name aws_iam_role_policy_attachment.foreign_s3_access. There was no other change to this resource than changing the name of the block in terraform (should not have produced a change on the AWS side other than too the ID string).

@ghost ghost added the service/iam Issues and PRs that pertain to the iam service. label Feb 21, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 21, 2020
@aberezin
Copy link

aberezin commented May 22, 2020

The workaround seems to be to rerun the apply.

@cvsmith
Copy link
Contributor

cvsmith commented Oct 29, 2020

Simply rerunning the apply from Terraform Cloud did not fix it for me. It still failed with the same error.

I tried to destroy and reapply (which is an option for me but not for many), and destroying from Terraform Cloud also failed on the job role in question:

Error: Error deleting IAM Role (...): DeleteConflict: Cannot delete entity, must detach all policies first.

After manually deleting the role in the AWS console, the destroy succeeded, but then applying failed with the original error message.

@cvsmith
Copy link
Contributor

cvsmith commented Oct 29, 2020

Despite the error message, the role and its policies were successfully created and function.

@bflad bflad added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 26, 2021
@bflad bflad self-assigned this Mar 26, 2021
bflad added a commit that referenced this issue Mar 26, 2021
…e resources

Reference: #12127
Reference: #16247
Reference: #16796

Output from acceptance testing in AWS Commerical:

```
--- PASS: TestAccAWSIAMRole_badJSON (11.02s)
--- PASS: TestAccAWSIAMRole_basic (23.54s)
--- PASS: TestAccAWSIAMRole_basicWithDescription (53.20s)
--- PASS: TestAccAWSIAMRole_disappears (46.04s)
--- PASS: TestAccAWSIAMRole_force_detach_policies (51.73s)
--- PASS: TestAccAWSIAMRole_MaxSessionDuration (87.07s)
--- PASS: TestAccAWSIAMRole_namePrefix (24.63s)
--- PASS: TestAccAWSIAMRole_PermissionsBoundary (124.99s)
--- PASS: TestAccAWSIAMRole_policyBasicInline (100.26s)
--- PASS: TestAccAWSIAMRole_policyBasicInlineEmpty (49.13s)
--- PASS: TestAccAWSIAMRole_policyBasicManaged (97.33s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionIgnored_inlineNonExistent (94.08s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionIgnored_managedNonExistent (74.63s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_inlineEmpty (76.32s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_inlineNonEmpty (79.85s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_managedEmpty (76.09s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_managedNonEmpty (77.20s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandRemovalAddedBack_inlineNonEmpty (77.85s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandRemovalAddedBack_managedNonEmpty (77.66s)
--- PASS: TestAccAWSIAMRole_tags (80.65s)
--- PASS: TestAccAWSIAMRole_testNameChange (82.60s)

--- PASS: TestAccAWSIAMRolePolicy_basic (49.38s)
--- PASS: TestAccAWSIAMRolePolicy_disappears (46.58s)
--- PASS: TestAccAWSIAMRolePolicy_generatedName (67.85s)
--- PASS: TestAccAWSIAMRolePolicy_invalidJSON (4.22s)
--- PASS: TestAccAWSIAMRolePolicy_namePrefix (56.10s)
--- PASS: TestAccAWSIAMRolePolicy_Policy_InvalidResource (26.78s)

--- PASS: TestAccAWSRolePolicyAttachment_basic (81.14s)
--- PASS: TestAccAWSRolePolicyAttachment_disappears (28.61s)
--- PASS: TestAccAWSRolePolicyAttachment_disappears_Role (32.83s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAWSIAMRole_badJSON (15.80s)
--- PASS: TestAccAWSIAMRole_basic (56.37s)
--- PASS: TestAccAWSIAMRole_basicWithDescription (117.55s)
--- PASS: TestAccAWSIAMRole_disappears (32.81s)
--- PASS: TestAccAWSIAMRole_force_detach_policies (65.18s)
--- PASS: TestAccAWSIAMRole_MaxSessionDuration (88.44s)
--- PASS: TestAccAWSIAMRole_namePrefix (56.26s)
--- PASS: TestAccAWSIAMRole_PermissionsBoundary (135.60s)
--- PASS: TestAccAWSIAMRole_policyBasicInline (98.21s)
--- PASS: TestAccAWSIAMRole_policyBasicInlineEmpty (39.47s)
--- PASS: TestAccAWSIAMRole_policyBasicManaged (98.71s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionIgnored_inlineNonExistent (112.38s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionIgnored_managedNonExistent (82.67s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_inlineEmpty (76.48s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_inlineNonEmpty (85.73s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_managedEmpty (84.34s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_managedNonEmpty (86.56s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandRemovalAddedBack_inlineNonEmpty (66.74s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandRemovalAddedBack_managedNonEmpty (74.49s)
--- PASS: TestAccAWSIAMRole_tags (74.03s)
--- PASS: TestAccAWSIAMRole_testNameChange (93.57s)

--- PASS: TestAccAWSIAMRolePolicy_basic (78.62s)
--- PASS: TestAccAWSIAMRolePolicy_disappears (35.25s)
--- PASS: TestAccAWSIAMRolePolicy_generatedName (100.35s)
--- PASS: TestAccAWSIAMRolePolicy_invalidJSON (9.46s)
--- PASS: TestAccAWSIAMRolePolicy_namePrefix (84.49s)
--- PASS: TestAccAWSIAMRolePolicy_Policy_InvalidResource (27.87s)

--- PASS: TestAccAWSRolePolicyAttachment_basic (88.63s)
--- PASS: TestAccAWSRolePolicyAttachment_disappears (32.95s)
--- PASS: TestAccAWSRolePolicyAttachment_disappears_Role (43.69s)
```
bflad added a commit that referenced this issue Apr 1, 2021
…e resources (#18435)

* service/iam: Handle read-after-create eventual consistency in IAM Role resources

Reference: #12127
Reference: #16247
Reference: #16796

Output from acceptance testing in AWS Commerical:

```
--- PASS: TestAccAWSIAMRole_badJSON (11.02s)
--- PASS: TestAccAWSIAMRole_basic (23.54s)
--- PASS: TestAccAWSIAMRole_basicWithDescription (53.20s)
--- PASS: TestAccAWSIAMRole_disappears (46.04s)
--- PASS: TestAccAWSIAMRole_force_detach_policies (51.73s)
--- PASS: TestAccAWSIAMRole_MaxSessionDuration (87.07s)
--- PASS: TestAccAWSIAMRole_namePrefix (24.63s)
--- PASS: TestAccAWSIAMRole_PermissionsBoundary (124.99s)
--- PASS: TestAccAWSIAMRole_policyBasicInline (100.26s)
--- PASS: TestAccAWSIAMRole_policyBasicInlineEmpty (49.13s)
--- PASS: TestAccAWSIAMRole_policyBasicManaged (97.33s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionIgnored_inlineNonExistent (94.08s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionIgnored_managedNonExistent (74.63s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_inlineEmpty (76.32s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_inlineNonEmpty (79.85s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_managedEmpty (76.09s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_managedNonEmpty (77.20s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandRemovalAddedBack_inlineNonEmpty (77.85s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandRemovalAddedBack_managedNonEmpty (77.66s)
--- PASS: TestAccAWSIAMRole_tags (80.65s)
--- PASS: TestAccAWSIAMRole_testNameChange (82.60s)

--- PASS: TestAccAWSIAMRolePolicy_basic (49.38s)
--- PASS: TestAccAWSIAMRolePolicy_disappears (46.58s)
--- PASS: TestAccAWSIAMRolePolicy_generatedName (67.85s)
--- PASS: TestAccAWSIAMRolePolicy_invalidJSON (4.22s)
--- PASS: TestAccAWSIAMRolePolicy_namePrefix (56.10s)
--- PASS: TestAccAWSIAMRolePolicy_Policy_InvalidResource (26.78s)

--- PASS: TestAccAWSRolePolicyAttachment_basic (81.14s)
--- PASS: TestAccAWSRolePolicyAttachment_disappears (28.61s)
--- PASS: TestAccAWSRolePolicyAttachment_disappears_Role (32.83s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAWSIAMRole_badJSON (15.80s)
--- PASS: TestAccAWSIAMRole_basic (56.37s)
--- PASS: TestAccAWSIAMRole_basicWithDescription (117.55s)
--- PASS: TestAccAWSIAMRole_disappears (32.81s)
--- PASS: TestAccAWSIAMRole_force_detach_policies (65.18s)
--- PASS: TestAccAWSIAMRole_MaxSessionDuration (88.44s)
--- PASS: TestAccAWSIAMRole_namePrefix (56.26s)
--- PASS: TestAccAWSIAMRole_PermissionsBoundary (135.60s)
--- PASS: TestAccAWSIAMRole_policyBasicInline (98.21s)
--- PASS: TestAccAWSIAMRole_policyBasicInlineEmpty (39.47s)
--- PASS: TestAccAWSIAMRole_policyBasicManaged (98.71s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionIgnored_inlineNonExistent (112.38s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionIgnored_managedNonExistent (82.67s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_inlineEmpty (76.48s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_inlineNonEmpty (85.73s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_managedEmpty (84.34s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandAdditionRemoved_managedNonEmpty (86.56s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandRemovalAddedBack_inlineNonEmpty (66.74s)
--- PASS: TestAccAWSIAMRole_policyOutOfBandRemovalAddedBack_managedNonEmpty (74.49s)
--- PASS: TestAccAWSIAMRole_tags (74.03s)
--- PASS: TestAccAWSIAMRole_testNameChange (93.57s)

--- PASS: TestAccAWSIAMRolePolicy_basic (78.62s)
--- PASS: TestAccAWSIAMRolePolicy_disappears (35.25s)
--- PASS: TestAccAWSIAMRolePolicy_generatedName (100.35s)
--- PASS: TestAccAWSIAMRolePolicy_invalidJSON (9.46s)
--- PASS: TestAccAWSIAMRolePolicy_namePrefix (84.49s)
--- PASS: TestAccAWSIAMRolePolicy_Policy_InvalidResource (27.87s)

--- PASS: TestAccAWSRolePolicyAttachment_basic (88.63s)
--- PASS: TestAccAWSRolePolicyAttachment_disappears (32.95s)
--- PASS: TestAccAWSRolePolicyAttachment_disappears_Role (43.69s)
```

* Update CHANGELOG for #18435
@github-actions github-actions bot added this to the v3.35.0 milestone Apr 1, 2021
@ghost
Copy link

ghost commented Apr 1, 2021

This has been released in version 3.35.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!

@ghost
Copy link

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

@ghost ghost locked as resolved and limited conversation to collaborators May 2, 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/iam Issues and PRs that pertain to the iam service.
Projects
None yet
4 participants