Arran Duff
Arran Duff

Reputation: 1474

terraform 0.13.5 resources overwrite each other on consecutive calls

Upvotes: 1

Views: 674

Answers (1)

luk2302
luk2302

Reputation: 57184

As to why this is happening:

  • during the first run terraform deploys the first resources, then the second ones - this order is due to the depends_on relation (the next steps work regardless of any depends_on). The second ones overwrite the first ones
  • during the second deploy terraform looks at what needs to be done:
    • the first ones are missing (were overwritten), they need to be created
    • the second ones are fine, terraform ignores them for this update
    • now only the first ones will be created and they will overwrite the second ones
  • during the third run the same happens but the exact other way around, seconds are missing, first are ignored, second overwrite first
  • repeat as often as you want, you will never end up with a stable deployment.

Solution: do not specify conflicting things in terraform. Terraform is supposed to be a description of what the infrastructure should look like - and saying "this resource should only have property A" and "this resource should only have property B" is contradictory, terraform will not be able to handle this gracefully.

What you should do specifically: do not use aws_iam_policy_attachment, basically ever, look at the big red box in the docs. Use multiple aws_iam_role_policy_attachment instead, they are additive, they will not overwrite each other.

Upvotes: 3

Related Questions