You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When executing a terraform plan ., the plan is correct and maps the correct policy to the correct policy_arn. The resulting sample output lines were retrieved after executing terraform apply. && terraform plan . Observe that the policy_arn for each policy attachment is being modified. The expected behaviour is that after the initial apply, because the files haven't been changed, a plan should produce no changes.
The policy_arn that is being mapped to is correct when executing a plan, but incorrect after an apply has been peformed.
Steps to Reproduce
terraform apply - create initial resources
terraform apply - see changes despite the files being static
Important Factoids
I believe this issue is a result of depending on the order of an exported splat from a resource. Observe that in the example above the policy_arn for aws_iam_policy_attachment.policy_attachment.2 is being modified to go from 10->2 during the plan phase (policy_arn: "arn:aws:iam::068555316154:policy/policy10" => "arn:aws:iam::068555316154:policy/policy2" (forces new resource)).
I believe the issue is that after terraform creates the initial aws_iam_policy resources, they are ordered in the following fashion:
aws_iam_policy.policy.0
aws_iam_policy.policy.1
aws_iam_policy.policy.10
aws_iam_policy.policy.11
aws_iam_policy.policy.2
When indexing into this splat to retrieve the associated policy_arn, this causes the aws_iam_policy_attachment.policy_attachment.2 resource to get 10's policy_arn. This is because each resource is probably given a unique ID using its index, and the sorting algorithm orders it alphanumerically. Is this expected behaviour as a result of how the unique string ids associated with resources are generated?
Edit : Workaround
Our current workaround is to change the interpolation for the policy_arn to policy_arn = "${element(aws_iam_policy.policy.*.arn, index(aws_iam_policy.policy.*.name, lookup(var.policies[count.index], "name")))}"
The downfall of this approach is that if our policy list is modified, all resources will be destroyed and brought up again because of the interpolation.
The text was updated successfully, but these errors were encountered:
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.
ghost
locked and limited conversation to collaborators
Apr 20, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Salut,
Terraform Version
Terraform v0.7.8
Affected Resource(s)
Terraform Configuration Files
Debug Output
https://gist.github.com/dang3r/02a50747ffae7d7f323d319df1ac944e
Expected Behavior
When executing a
terraform plan .
, the plan is correct and maps the correct policy to the correct policy_arn. The resulting sample output lines were retrieved after executingterraform apply. && terraform plan .
Observe that the policy_arn for each policy attachment is being modified. The expected behaviour is that after the initial apply, because the files haven't been changed, a plan should produce no changes.Actual Behavior
The policy_arn that is being mapped to is correct when executing a plan, but incorrect after an apply has been peformed.
Steps to Reproduce
terraform apply
- create initial resourcesterraform apply
- see changes despite the files being staticImportant Factoids
I believe this issue is a result of depending on the order of an exported splat from a resource. Observe that in the example above the
policy_arn
foraws_iam_policy_attachment.policy_attachment.2
is being modified to go from 10->2 during the plan phase (policy_arn: "arn:aws:iam::068555316154:policy/policy10" => "arn:aws:iam::068555316154:policy/policy2" (forces new resource)
).I believe the issue is that after terraform creates the initial
aws_iam_policy
resources, they are ordered in the following fashion:When indexing into this splat to retrieve the associated
policy_arn
, this causes theaws_iam_policy_attachment.policy_attachment.2
resource to get 10's policy_arn. This is because each resource is probably given a unique ID using its index, and the sorting algorithm orders it alphanumerically. Is this expected behaviour as a result of how the unique string ids associated with resources are generated?Edit : Workaround
Our current workaround is to change the interpolation for the policy_arn to
policy_arn = "${element(aws_iam_policy.policy.*.arn, index(aws_iam_policy.policy.*.name, lookup(var.policies[count.index], "name")))}"
The downfall of this approach is that if our policy list is modified, all resources will be destroyed and brought up again because of the interpolation.
The text was updated successfully, but these errors were encountered: