-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Order is lost for data aws_iam_policy_document
when applied to S3 buckets, iam roles, kms keys, etc
#11801
Comments
After looking into this issue and looking into the jen20 library for awspolicyequivalency and https://github.com/hashicorp/terraform-provider-aws/blob/main/aws/resource_aws_kms_key.go#L205 nothing in Terraform was causing the policy re ordering and the Terraform outputs looked as I'd expect. As it turns out, KMS just saves in a random order. This can be replicated with a plain old Can also replicate this in the AWS console:
|
I'm experiencing a similar problem with Terraform 0.15.4 . Terraform 0.15.4 will now report the changes made outside of Terraform as part of the plan result. Some list orders is not retained, so Terraform always reports list orders have been changed like below. This problem has no real impact, but the plan results are unnecessarily long, and visibility is degraded.
|
Even though the api returns it in a random order, couldn't the apply save the policy in alphabetical order in the tfstate and then have the plan retrieve it from the aws api and then alphabetize it again to diff it thereby avoiding the reorder shown in the current diff? |
Same. Using Terraform 0.15.4 and applying for a directory with 30+ ecr repository resources with policies. Those policies are having their Principals section randomly sorted by AWS IAM, but neither |
+1 for this, seeing it in both KMS resource-based-policies and IAM resources with terraform 0.15.4. |
aws_iam_policy_document
when applied to resource aws_kms_key
This issue does not appear to be limited to aws_kms_key, it may be for assume_role_policy attributes in general. As of Terraform 0.15.4 this also occurs for the assume_role_policy attribute of aws_iam_role resources if there is >1 federated principal defined. Running
|
May not even be limited to |
Same issue here with |
Same issue here with |
Same issue here, this makes the idea of checking the plan nearly impossible without some programmatic filtering on the client side, as this bug generates thousands of lines of redundant plan code (in our case) and everything else gets lost in the noise. Terraform 15.5 |
Same problem here with an S3 Bucket Policy. Terraform 15.5, hashicorp/aws v3.44.0 |
Just another "me, too". This is tehncially AWS's fault if it's reordering lists inside JSON; that's supposed to be a no-no. But since these particular lists are semantically treated as sets, probably Terraform should special-case the comparison so that it doesn't care about order. |
This issue affects |
It still affects 1.0.1 as well.
|
Confirming it works like that for ANY policy. Suggestion about sorting principals before storing and comparing should do the trick here. @nitrocode can you change the title so it's not misleading? |
aws_iam_policy_document
when applied to resource aws_kms_key
aws_iam_policy_document
when applied to S3 buckets, iam roles, kms keys
aws_iam_policy_document
when applied to S3 buckets, iam roles, kms keysaws_iam_policy_document
when applied to S3 buckets, iam roles, kms keys, etc
can confirm this same issue exists in 1.0.2 as well. Ordering is not respected and subsequent runs will throw warnings for differing "changes" each time, even though no actual changes have been made. |
I don't think this is an issue with the version of Terraform, but the version of the AWS provider itself, as this is wholly within the |
Strangely enough terraform 0.14.11 shows no diff but 0.15.5 shows a diff, so it might be related to the terraform version somewhat (with the same version of the aws provider). |
We skipped 0.15 and went to 1.0 but I can confirm that on 0.14 I did not see this issue and after upgrading to 1.0 I now see this in a number of places. Sorting the lists in the terraform code does not help. |
IMO the way terraform core compares sets has changed. Even though it shows a diff, in the end it says the resource is up to date, weird. |
hi |
Wouldn't automagically sorting lists in AWS API response AND expected principals before comparing solve this? This should be easy ;) |
Ordering is easy but..."Order" in the context of this issue has two caveats:
What are we solving?I see there being two problems:
Our approach will be to fix # 1 and then see where we're at with # 2. Currently the two problems are intertwined in the issues to the point they are convulting each other. Once pain points are alleviated (hopefully) with #21968, we'll need your input to determine what problems still remain. |
Could it be that v3.69 doesn't fix all of the issues for this issue? I still have issues with aws_s3_bucket_policy showing a diff due to ordering. |
@anthonyAdhese Could you paste in an example of the diff that is shown? Thanks. |
Never had an issue with it in the past but we've upgraded from v3.23 a few weeks ago and this is the first run since then I believe. Debug output was this:
Received:
We do generate this policy with a jsonencode operation but I gave it a go with just a normal call like this: |
@anthonyAdhese We hoped to alleviate the majority of a pain points with this push. I ask that you give 3.70.0 a try when it is available. If you're still seeing issues, please open a new issue! We will need a complete config to be able to reproduce the issue. |
This functionality has been released in v3.70.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. Thank you! |
The form of the defect described here #11801 (comment) is still occurring.
|
I think if you plan the second time, you won't see the diffs. |
It still occurs on every plan for a random selection of resources even after applying changes but I'll be switching to one of the newly reported defects that cover my specific remaining symptoms as suggested by YakDriver. Thanks all for the great work on the larger issue group, it's clearly been a lot of work! |
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. |
Community Note
See also #21968
Terraform Version
Affected Resource(s)
aws_ecr_repository_policy
aws_kms_key
aws_s3_bucket
aws_launch_configuration
aws_lb_listener
aws_codeartifact_domain_pernission_policy
Terraform Configuration Files
If running locally, please add your own real roles to
local.secrets_roles
otherwise the kms policy will fail.In terraform console
local.secrets_roles_arns
is alphabeticaldata.aws_iam_policy_document.secrets.json
is reverse alphabetical which is expected (#6107)aws_kms_key.secrets_test.policy
returns the same output which is perfectAfter applying the above, I added a
default
role tolocal.secrets_roles
and I see this in the planDebug Output
Expected Behavior
Order should be retained. I wouldn't mind the reverse alphabetical order at the very least.
Actual Behavior
Random order
Steps to Reproduce
local.secrets_roles
with actual rolesterraform apply
local.secrets_roles
by adding another existing roleterraform plan
and you will see random orderImportant Factoids
I edited a policy in AWS console, changed the order of principal aws to alphabetical, saved it, and also saw a random order. Perhaps it is the AWS API that is reordering them?
References
Workaround
After upgrading to Terraform 0.14.x, my most recent workaround is by supplying an output
Then in the
terraform plan
orterraform apply
, it will hide all the unchanged and only show the few that changed.The text was updated successfully, but these errors were encountered: