diff --git a/builtin/providers/aws/resource_aws_sns_topic.go b/builtin/providers/aws/resource_aws_sns_topic.go index 6a8e62fa7..4174e8732 100644 --- a/builtin/providers/aws/resource_aws_sns_topic.go +++ b/builtin/providers/aws/resource_aws_sns_topic.go @@ -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{ @@ -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" { + 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) } } } diff --git a/builtin/providers/aws/resource_aws_sns_topic_test.go b/builtin/providers/aws/resource_aws_sns_topic_test.go index 76510c76e..2852c36fb 100644 --- a/builtin/providers/aws/resource_aws_sns_topic_test.go +++ b/builtin/providers/aws/resource_aws_sns_topic_test.go @@ -128,8 +128,6 @@ resource "aws_sns_topic" "test_topic" { name = "example" policy = <