-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/aws: normalize json policy for sns topic policy attribute #6089
provider/aws: normalize json policy for sns topic policy attribute #6089
Conversation
@@ -183,9 +185,14 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error { | |||
// Some of the fetched attributes are stateful properties such as | |||
// the number of subscriptions, the owner, etc. skip those | |||
if resource.Schema[iKey] != nil { | |||
value := *attrmap[oKey] | |||
var value string | |||
if iKey == "policy" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @keymon
This if statement feels redundant - we are doing the same thing in the if & else - is this actually the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, sorry. It should not be the same fixed. I don't want to change the behaviour of the other attributes, that is why I got the if.
1a14a66
to
c90496a
Compare
If you consider necessary I could write a test for this case. But I wonder if you could point me to an example that checks that the plan is empty. Or maybe we can change https://github.com/hashicorp/terraform/blob/master/helper/resource/testing.go#L307 to add the option: |
If we setup a sns_topic policy with a policy with a different order to the one set by the AWS API, terraform plan will be not empty between runs.
For the policy attribute of the resource aws_sns_topic, AWS returns the policy in JSON format with the fields in a different order. If we store and compare the values without normalizing, terraform will unnecesary trigger and update of the resource. To avoid that, we must add a normalization function in the StateFunc of the policy attribute and also when we read the attribute from AWS.
c90496a
to
3e63ca1
Compare
I added a test by modifying the order of the attributes in the policy:
And with the new code:
|
Thanks for the explanations @keymon Will test this now P |
Hi @keymon this looks good - the tests pass as expected - thanks so much for the PR! Paul |
…ashicorp#6089) * provider/aws: test empty plan with sns_topic policy with random order If we setup a sns_topic policy with a policy with a different order to the one set by the AWS API, terraform plan will be not empty between runs. * provider/aws: normalize json policy for sns topic For the policy attribute of the resource aws_sns_topic, AWS returns the policy in JSON format with the fields in a different order. If we store and compare the values without normalizing, terraform will unnecesary trigger and update of the resource. To avoid that, we must add a normalization function in the StateFunc of the policy attribute and also when we read the attribute from AWS.
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. |
Summary
For the policy attribute of the resource aws_sns_topic, AWS returns the policy
in JSON format with the fields in a different order.
If we store and compare the values without normalizing, terraform
will unnecesary trigger and update of the resource.
To avoid that, we must add a normalization function in the StateFunc of
the policy attribute and also when we read the attribute from AWS.
Details
Given a manifest like this:
It will trigger update resource every time you run it:
Expected result
Only applies changes if required.