Skip to content
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

Merged
merged 2 commits into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions builtin/providers/aws/resource_aws_sns_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func resourceAwsSnsTopic() *schema.Resource {
log.Printf("[WARN] Error compacting JSON for Policy in SNS Topic")
return ""
}
return buffer.String()
value := normalizeJson(buffer.String())
log.Printf("[DEBUG] topic policy before save: %s", value)
return value
},
},
"delivery_policy": &schema.Schema{
Expand Down Expand Up @@ -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" {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

value = normalizeJson(*attrmap[oKey])
} else {
value = *attrmap[oKey]
}
log.Printf("[DEBUG] Reading %s => %s -> %s", iKey, oKey, value)
d.Set(iKey, *attrmap[oKey])
d.Set(iKey, value)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions builtin/providers/aws/resource_aws_sns_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ resource "aws_sns_topic" "test_topic" {
name = "example"
policy = <<EOF
{
"Version": "2012-10-17",
"Id": "Policy1445931846145",
"Statement": [
{
"Sid": "Stmt1445931846145",
Expand All @@ -140,7 +138,9 @@ resource "aws_sns_topic" "test_topic" {
"Action": "sns:Publish",
"Resource": "arn:aws:sns:us-west-2::example"
}
]
],
"Version": "2012-10-17",
"Id": "Policy1445931846145"
}
EOF
}
Expand Down