Merge pull request #8898 from kwilczynski/feature/json-validation-aws_elasticsearch_domain

provider/aws: Add JSON validation to the aws_elasticsearch_domain resource.
This commit is contained in:
Paul Stack 2016-09-22 09:27:15 +01:00 committed by GitHub
commit f13e020376
1 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,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"
elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice" elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -23,8 +24,9 @@ func resourceAwsElasticSearchDomain() *schema.Resource {
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"access_policies": &schema.Schema{ "access_policies": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs,
Optional: true, Optional: true,
ValidateFunc: validateJsonString,
DiffSuppressFunc: suppressEquivalentAwsPolicyDiffs,
}, },
"advanced_options": &schema.Schema{ "advanced_options": &schema.Schema{
Type: schema.TypeMap, Type: schema.TypeMap,
@ -269,7 +271,11 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{}
ds := out.DomainStatus ds := out.DomainStatus
if ds.AccessPolicies != nil && *ds.AccessPolicies != "" { if ds.AccessPolicies != nil && *ds.AccessPolicies != "" {
d.Set("access_policies", normalizeJson(*ds.AccessPolicies)) policies, err := normalizeJsonString(*ds.AccessPolicies)
if err != nil {
return errwrap.Wrapf("access policies contain an invalid JSON: {{err}}", err)
}
d.Set("access_policies", policies)
} }
err = d.Set("advanced_options", pointersMapToStringList(ds.AdvancedOptions)) err = d.Set("advanced_options", pointersMapToStringList(ds.AdvancedOptions))
if err != nil { if err != nil {