Skip to content

Commit

Permalink
Merge pull request #8908 from kwilczynski/feature/json-validation-aws…
Browse files Browse the repository at this point in the history
…_s3_bucket

provider/aws: Add JSON validation to the aws_s3_bucket resource.
  • Loading branch information
stack72 authored Sep 22, 2016
2 parents bf02cc1 + 15d33c7 commit 076fd93
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -48,6 +49,7 @@ func resourceAwsS3Bucket() *schema.Resource {
"policy": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateJsonString,
DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs,
},

Expand Down Expand Up @@ -110,9 +112,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 +471,12 @@ 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, err := normalizeJsonString(*v)
if err != nil {
return errwrap.Wrapf("policy contains an invalid JSON: {{err}}", err)
}
d.Set("policy", policy)
}
}
}
Expand Down

0 comments on commit 076fd93

Please sign in to comment.