From 87dd5c5bd077f67631a0103ea8db3d16fb2c9055 Mon Sep 17 00:00:00 2001 From: Tomas Doran Date: Wed, 4 Nov 2015 04:23:13 -0800 Subject: [PATCH 1/3] Fix panic I see when upgrading to 0.6.6 Check if the policy is nil or not before type casting it --- builtin/providers/aws/resource_aws_sns_topic.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_sns_topic.go b/builtin/providers/aws/resource_aws_sns_topic.go index 6a1c46590f7c..26e98a9b10e1 100644 --- a/builtin/providers/aws/resource_aws_sns_topic.go +++ b/builtin/providers/aws/resource_aws_sns_topic.go @@ -47,7 +47,10 @@ func resourceAwsSnsTopic() *schema.Resource { ForceNew: false, Computed: true, StateFunc: func(v interface{}) string { - jsonb := []byte(v.(string)) + jsonb := []byte{} + if v != nil { + jsonb = []byte(v.(string)) + } buffer := new(bytes.Buffer) if err := json.Compact(buffer, jsonb); err != nil { log.Printf("[WARN] Error compacting JSON for Policy in SNS Topic") From 274781224ee8cb1b4b8c9f6dffa299201680fcc8 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 5 Nov 2015 15:25:04 -0600 Subject: [PATCH 2/3] provider/aws: fix panic with SNS topic policy if omitted --- builtin/providers/aws/resource_aws_sns_topic.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_sns_topic.go b/builtin/providers/aws/resource_aws_sns_topic.go index 26e98a9b10e1..b0d6fecf56b3 100644 --- a/builtin/providers/aws/resource_aws_sns_topic.go +++ b/builtin/providers/aws/resource_aws_sns_topic.go @@ -44,13 +44,12 @@ func resourceAwsSnsTopic() *schema.Resource { "policy": &schema.Schema{ Type: schema.TypeString, Optional: true, - ForceNew: false, Computed: true, StateFunc: func(v interface{}) string { - jsonb := []byte{} - if v != nil { - jsonb = []byte(v.(string)) + if v == nil { + return "" } + jsonb := []byte{} buffer := new(bytes.Buffer) if err := json.Compact(buffer, jsonb); err != nil { log.Printf("[WARN] Error compacting JSON for Policy in SNS Topic") From 15533dca0908815f4172bf6c6571288c406831b3 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Fri, 6 Nov 2015 14:06:50 -0600 Subject: [PATCH 3/3] actually use the value --- builtin/providers/aws/resource_aws_sns_topic.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_sns_topic.go b/builtin/providers/aws/resource_aws_sns_topic.go index b0d6fecf56b3..6bf0127d0cf6 100644 --- a/builtin/providers/aws/resource_aws_sns_topic.go +++ b/builtin/providers/aws/resource_aws_sns_topic.go @@ -46,10 +46,11 @@ func resourceAwsSnsTopic() *schema.Resource { Optional: true, Computed: true, StateFunc: func(v interface{}) string { - if v == nil { + s, ok := v.(string) + if !ok || s == "" { return "" } - jsonb := []byte{} + jsonb := []byte(s) buffer := new(bytes.Buffer) if err := json.Compact(buffer, jsonb); err != nil { log.Printf("[WARN] Error compacting JSON for Policy in SNS Topic")