Merge branch 'kwilczynski-feature/json-validation-aws_sns_topic'

This commit is contained in:
stack72 2016-09-22 09:11:34 +01:00
commit 4cc320a67e
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
1 changed files with 10 additions and 19 deletions

View File

@ -1,19 +1,17 @@
package aws package aws
import ( import (
"bytes"
"encoding/json"
"fmt" "fmt"
"log" "log"
"strings" "strings"
"time" "time"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/sns" "github.com/aws/aws-sdk-go/service/sns"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
) )
// Mutable attributes // Mutable attributes
@ -49,21 +47,11 @@ func resourceAwsSnsTopic() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Computed: true, Computed: true,
ValidateFunc: validateJsonString,
DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs, DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs,
StateFunc: func(v interface{}) string { StateFunc: func(v interface{}) string {
s, ok := v.(string) json, _ := normalizeJsonString(v)
if !ok || s == "" { return json
return ""
}
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")
return ""
}
value := normalizeJson(buffer.String())
log.Printf("[DEBUG] topic policy before save: %s", value)
return value
}, },
}, },
"delivery_policy": &schema.Schema{ "delivery_policy": &schema.Schema{
@ -191,7 +179,10 @@ func resourceAwsSnsTopicRead(d *schema.ResourceData, meta interface{}) error {
if resource.Schema[iKey] != nil { if resource.Schema[iKey] != nil {
var value string var value string
if iKey == "policy" { if iKey == "policy" {
value = normalizeJson(*attrmap[oKey]) value, err = normalizeJsonString(*attrmap[oKey])
if err != nil {
return errwrap.Wrapf("policy contains an invalid JSON: {{err}}", err)
}
} else { } else {
value = *attrmap[oKey] value = *attrmap[oKey]
} }