Skip to content

Commit

Permalink
Add JSON validation to the aws_s3_bucket resource.
Browse files Browse the repository at this point in the history
This commit adds support for new helper function which is used to
normalise and validate JSON string.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
  • Loading branch information
kwilczynski committed Sep 21, 2016
1 parent c942707 commit a00f8f1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func resourceAwsS3Bucket() *schema.Resource {
"policy": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateJsonString,
DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs,
},

Expand Down Expand Up @@ -110,9 +111,13 @@ func resourceAwsS3Bucket() *schema.Resource {
},

"routing_rules": &schema.Schema{
Type: schema.TypeString,
Optional: true,
StateFunc: normalizeJson,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateJsonString,
StateFunc: func(v interface{}) string {
json, _ := normalizeJsonString(v)
return json
},
},
},
},
Expand Down Expand Up @@ -465,8 +470,11 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("policy", ""); err != nil {
return err
}
} else if err := d.Set("policy", normalizeJson(*v)); err != nil {
return err
} else {
policy, _ := normalizeJsonString(*v)
if err := d.Set("policy", policy); err != nil {
return err
}
}
}
}
Expand Down

0 comments on commit a00f8f1

Please sign in to comment.