Merge pull request #8908 from kwilczynski/feature/json-validation-aws_s3_bucket
provider/aws: Add JSON validation to the aws_s3_bucket resource.
This commit is contained in:
commit
076fd93eb8
|
@ -11,6 +11,7 @@ import (
|
||||||
"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/s3"
|
"github.com/aws/aws-sdk-go/service/s3"
|
||||||
|
"github.com/hashicorp/errwrap"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
@ -48,6 +49,7 @@ func resourceAwsS3Bucket() *schema.Resource {
|
||||||
"policy": &schema.Schema{
|
"policy": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
ValidateFunc: validateJsonString,
|
||||||
DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs,
|
DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -110,9 +112,13 @@ func resourceAwsS3Bucket() *schema.Resource {
|
||||||
},
|
},
|
||||||
|
|
||||||
"routing_rules": &schema.Schema{
|
"routing_rules": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
StateFunc: normalizeJson,
|
ValidateFunc: validateJsonString,
|
||||||
|
StateFunc: func(v interface{}) string {
|
||||||
|
json, _ := normalizeJsonString(v)
|
||||||
|
return json
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -465,8 +471,12 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
if err := d.Set("policy", ""); err != nil {
|
if err := d.Set("policy", ""); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if err := d.Set("policy", normalizeJson(*v)); err != nil {
|
} else {
|
||||||
return err
|
policy, err := normalizeJsonString(*v)
|
||||||
|
if err != nil {
|
||||||
|
return errwrap.Wrapf("policy contains an invalid JSON: {{err}}", err)
|
||||||
|
}
|
||||||
|
d.Set("policy", policy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue