Handle JSON parsing error in the ReadFunc for the policy document.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
This commit is contained in:
Krzysztof Wilczynski 2016-09-21 19:22:40 +01:00
parent 7596991303
commit 125e175186
No known key found for this signature in database
GPG Key ID: B89F6447B63419A6
1 changed files with 13 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
)
@ -64,7 +65,10 @@ func resourceAwsVPCEndpointCreate(d *schema.ResourceData, meta interface{}) erro
}
if v, ok := d.GetOk("policy"); ok {
policy, _ := normalizeJsonString(v)
policy, err := normalizeJsonString(v)
if err != nil {
return errwrap.Wrapf("policy contains an invalid JSON: {{err}}", err)
}
input.PolicyDocument = aws.String(policy)
}
@ -132,7 +136,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)
policy, err := normalizeJsonString(*vpce.PolicyDocument)
if err != nil {
return errwrap.Wrapf("policy contains an invalid JSON: {{err}}", err)
}
d.Set("vpc_id", vpce.VpcId)
d.Set("policy", policy)
@ -168,7 +175,10 @@ func resourceAwsVPCEndpointUpdate(d *schema.ResourceData, meta interface{}) erro
}
if d.HasChange("policy") {
policy, _ := normalizeJsonString(d.Get("policy"))
policy, err := normalizeJsonString(d.Get("policy"))
if err != nil {
return errwrap.Wrapf("policy contains an invalid JSON: {{err}}", err)
}
input.PolicyDocument = aws.String(policy)
}