Merge pull request #8976 from kwilczynski/feature/check-error-aws_glacier_vault

provider/aws: Handle JSON parsing error in the ReadFunc for the access policy document.
This commit is contained in:
Paul Stack 2016-09-22 08:53:57 +01:00 committed by GitHub
commit a9dce86bf2
1 changed files with 6 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"regexp" "regexp"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -33,7 +34,7 @@ func resourceAwsGlacierVault() *schema.Resource {
value := v.(string) value := v.(string)
if !regexp.MustCompile(`^[.0-9A-Za-z-_]+$`).MatchString(value) { if !regexp.MustCompile(`^[.0-9A-Za-z-_]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf( errors = append(errors, fmt.Errorf(
"only alphanumeric characters, hyphens, underscores, and periods allowed in %q", k)) "only alphanumeric characters, hyphens, underscores, and periods are allowed in %q", k))
} }
if len(value) > 255 { if len(value) > 255 {
errors = append(errors, fmt.Errorf( errors = append(errors, fmt.Errorf(
@ -163,7 +164,10 @@ func resourceAwsGlacierVaultRead(d *schema.ResourceData, meta interface{}) error
if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "ResourceNotFoundException" { if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "ResourceNotFoundException" {
d.Set("access_policy", "") d.Set("access_policy", "")
} else if pol != nil { } else if pol != nil {
policy, _ := normalizeJsonString(*pol.Policy.Policy) policy, err := normalizeJsonString(*pol.Policy.Policy)
if err != nil {
return errwrap.Wrapf("access policy contains an invalid JSON: {{err}}", err)
}
d.Set("access_policy", policy) d.Set("access_policy", policy)
} else { } else {
return err return err