Add JSON validation to the aws_vpc_endpoint resource.

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>
This commit is contained in:
Krzysztof Wilczynski 2016-09-14 23:29:29 +01:00
parent c942707476
commit 7596991303
No known key found for this signature in database
GPG Key ID: B89F6447B63419A6
1 changed files with 13 additions and 7 deletions

View File

@ -22,10 +22,14 @@ func resourceAwsVpcEndpoint() *schema.Resource {
Schema: map[string]*schema.Schema{
"policy": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Computed: true,
StateFunc: normalizeJson,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateJsonString,
StateFunc: func(v interface{}) string {
json, _ := normalizeJsonString(v)
return json
},
},
"vpc_id": &schema.Schema{
Type: schema.TypeString,
@ -60,7 +64,7 @@ func resourceAwsVPCEndpointCreate(d *schema.ResourceData, meta interface{}) erro
}
if v, ok := d.GetOk("policy"); ok {
policy := normalizeJson(v)
policy, _ := normalizeJsonString(v)
input.PolicyDocument = aws.String(policy)
}
@ -128,8 +132,10 @@ func resourceAwsVPCEndpointRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("There are multiple prefix lists associated with the service name '%s'. Unexpected", prefixListServiceName)
}
policy, _ := normalizeJsonString(*vpce.PolicyDocument)
d.Set("vpc_id", vpce.VpcId)
d.Set("policy", normalizeJson(*vpce.PolicyDocument))
d.Set("policy", policy)
d.Set("service_name", vpce.ServiceName)
if err := d.Set("route_table_ids", aws.StringValueSlice(vpce.RouteTableIds)); err != nil {
return err
@ -162,7 +168,7 @@ func resourceAwsVPCEndpointUpdate(d *schema.ResourceData, meta interface{}) erro
}
if d.HasChange("policy") {
policy := normalizeJson(d.Get("policy"))
policy, _ := normalizeJsonString(d.Get("policy"))
input.PolicyDocument = aws.String(policy)
}