terraform-provider-aws: KMS resource Key Policy propagation consistent fail
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 CLI and Terraform AWS Provider Version
Terraforn Core: 1.0.5
AWS Provider: 3.62.0
Affected Resource(s)
- aws_kms_key
Terraform Configuration Files
Same as per #20588 which isn’t resolved in latest provider.
Workaround is to roll back to 3.52 which allows to create a key with policy having multiple statements.
Note: providing a policy that is equivalent to the default (non lock out) policy will create successfully, when adding an additional statement, provisioning will fail.
There are new comments on #20588 that provide additional detail.
Thanks for helping resolve.
Expected Behavior
I should be able to create a CMK key with a custom policy.
Actual Behavior
Provisioning fails with failure to propagate key policy.
Steps to Reproduce
Create a aws_key_resource with the policy attribute set to a policy with multiple statements.
References
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 22
- Comments: 15 (3 by maintainers)
I’m facing this issue but can’t downgrade to 3.52 because I need to use autoscaling_group_tag which has only been added in v3.56.0.
I attempted to debug the issue and in my case it was related to me using the following in my policy (note the boolean represented as an actual bool)
I debugged
awspolicy.PoliciesAreEquivalentand found that theequalsimplemetation fails, because the policy retrieved via the KMS APIs (the “theirs” side of the comparison) haskms:GrantIsForAWSResourceset to"true"instead (boolean represented as string).I changed my condition to the following:
and it seems to work now. Terraform was also continously showing a diff before this change but I assumed this to be unrelated. Changing
trueto"true"has fixed this was well.This might not be the cause in the case of @AshMenhennett but may be of help to others. Cheers
This is also occurring for me on hashicorp/aws v4.1
https://github.com/hashicorp/terraform-provider-aws/blob/040f37e8d6a1b13fe796c5cdbfebbebb833ae90a/aws/internal/service/kms/waiter/waiter.go#L96-L122
Potentially caused by
awspolicy.PoliciesAreEquivalentincorrectly returningfalse?Same for me to on v3.74.3.
Still occurring for me
Thanks to @CrawX’s pointer, we also fixed our issue and now use
hashicorp/aws v3.67.0. Here’s the summary, instead of usingwe now use
which allows us to avoid updates-in-place related to the principals block of our key policies like the one below.
So it looks like the validation between user_id and arn is either not working or does so after the 5m0s timeout.
Hey @CrawX,
That’s awesome to find workaround AND use the new features. I also appreciate that you took the time to debug it, as that’s helpful us as well!
Seeing this thread looks like it’s related, when I find some time I’ll see if we can remedy as you have.