From 0fe5777aa16939ea180b2ae1fd5a62fe52882440 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sat, 4 Aug 2018 13:17:53 +0400 Subject: [PATCH 1/4] fix panic nil pointer dereference error --- aws/resource_aws_elasticsearch_domain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_elasticsearch_domain.go b/aws/resource_aws_elasticsearch_domain.go index 98c1c9956d7..84b674cb5dd 100644 --- a/aws/resource_aws_elasticsearch_domain.go +++ b/aws/resource_aws_elasticsearch_domain.go @@ -548,7 +548,7 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{} } if ds.SnapshotOptions != nil { d.Set("snapshot_options", map[string]interface{}{ - "automated_snapshot_start_hour": *ds.SnapshotOptions.AutomatedSnapshotStartHour, + "automated_snapshot_start_hour": aws.Int64Value(ds.SnapshotOptions.AutomatedSnapshotStartHour), }) } if ds.VPCOptions != nil { From 3bfa6b63a1d235735b54e3aba06f13f3f9f4f8c0 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sat, 4 Aug 2018 13:35:44 +0400 Subject: [PATCH 2/4] properly dereferenced other attributes --- aws/resource_aws_elasticsearch_domain.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/aws/resource_aws_elasticsearch_domain.go b/aws/resource_aws_elasticsearch_domain.go index 84b674cb5dd..249d78bd124 100644 --- a/aws/resource_aws_elasticsearch_domain.go +++ b/aws/resource_aws_elasticsearch_domain.go @@ -310,7 +310,7 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface DomainName: aws.String(d.Get("domain_name").(string)), }) if err == nil { - return fmt.Errorf("ElasticSearch domain %q already exists", *resp.DomainStatus.DomainName) + return fmt.Errorf("ElasticSearch domain %s already exists", aws.StringValue(resp.DomainStatus.DomainName)) } input := elasticsearch.CreateElasticsearchDomainInput{ @@ -425,7 +425,7 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface out, err = conn.CreateElasticsearchDomain(&input) if err != nil { if isAWSErr(err, "InvalidTypeException", "Error setting policy") { - log.Printf("[DEBUG] Retrying creation of ElasticSearch domain %s", *input.DomainName) + log.Printf("[DEBUG] Retrying creation of ElasticSearch domain %s", aws.StringValue(input.DomainName)) return resource.RetryableError(err) } if isAWSErr(err, "ValidationException", "enable a service-linked role to give Amazon ES permissions") { @@ -450,7 +450,7 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface return err } - d.SetId(*out.DomainStatus.ARN) + d.SetId(aws.StringValue(out.DomainStatus.ARN)) // Whilst the domain is being created, we can initialise the tags. // This should mean that if the creation fails (eg because your token expired @@ -458,7 +458,7 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface // the resources. tags := tagsFromMapElasticsearchService(d.Get("tags").(map[string]interface{})) - if err := setTagsElasticsearchService(conn, d, *out.DomainStatus.ARN); err != nil { + if err := setTagsElasticsearchService(conn, d, aws.StringValue(out.DomainStatus.ARN)); err != nil { return err } @@ -514,8 +514,8 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{} ds := out.DomainStatus - if ds.AccessPolicies != nil && *ds.AccessPolicies != "" { - policies, err := structure.NormalizeJsonString(*ds.AccessPolicies) + if ds.AccessPolicies != nil && aws.StringValue(ds.AccessPolicies) != "" { + policies, err := structure.NormalizeJsonString(aws.StringValue(ds.AccessPolicies)) if err != nil { return errwrap.Wrapf("access policies contain an invalid JSON: {{err}}", err) } @@ -525,7 +525,7 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{} if err != nil { return err } - d.SetId(*ds.ARN) + d.SetId(aws.StringValue(ds.ARN)) d.Set("domain_id", ds.DomainId) d.Set("domain_name", ds.DomainName) d.Set("elasticsearch_version", ds.ElasticsearchVersion) @@ -567,7 +567,7 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{} } } else { if ds.Endpoint != nil { - d.Set("endpoint", *ds.Endpoint) + d.Set("endpoint", aws.StringValue(ds.Endpoint)) d.Set("kibana_endpoint", getKibanaEndpoint(d)) } if ds.Endpoints != nil { @@ -581,9 +581,9 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{} mm := map[string]interface{}{} mm["log_type"] = k if val.CloudWatchLogsLogGroupArn != nil { - mm["cloudwatch_log_group_arn"] = *val.CloudWatchLogsLogGroupArn + mm["cloudwatch_log_group_arn"] = aws.StringValue(val.CloudWatchLogsLogGroupArn) } - mm["enabled"] = *val.Enabled + mm["enabled"] = aws.BoolValue(val.Enabled) m = append(m, mm) } d.Set("log_publishing_options", m) From 2cc7c082676af6d7bd85d03e4da549d1386ce478 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Mon, 6 Aug 2018 18:41:10 +0400 Subject: [PATCH 3/4] address feedback for setting ES snaphot options --- aws/resource_aws_elasticsearch_domain.go | 8 ++++---- aws/structure.go | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/aws/resource_aws_elasticsearch_domain.go b/aws/resource_aws_elasticsearch_domain.go index 249d78bd124..a3499ac6b57 100644 --- a/aws/resource_aws_elasticsearch_domain.go +++ b/aws/resource_aws_elasticsearch_domain.go @@ -546,11 +546,11 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{} if err != nil { return err } - if ds.SnapshotOptions != nil { - d.Set("snapshot_options", map[string]interface{}{ - "automated_snapshot_start_hour": aws.Int64Value(ds.SnapshotOptions.AutomatedSnapshotStartHour), - }) + + if err := d.Set("snapshot_options", flattenESSnapshotOptions(ds.SnapshotOptions)); err != nil { + return fmt.Errorf("error setting snapshot_options: %s", err) } + if ds.VPCOptions != nil { err = d.Set("vpc_options", flattenESVPCDerivedInfo(ds.VPCOptions)) if err != nil { diff --git a/aws/structure.go b/aws/structure.go index 6c1e7a54feb..caffbebf0eb 100644 --- a/aws/structure.go +++ b/aws/structure.go @@ -1132,6 +1132,18 @@ func flattenESCognitoOptions(c *elasticsearch.CognitoOptions) []map[string]inter return []map[string]interface{}{m} } +func flattenESSnapshotOptions(snapshotOptions *elasticsearch.SnapshotOptions) []map[string]interface{} { + if snapshotOptions == nil { + return []map[string]interface{}{} + } + + m := map[string]interface{}{ + "automated_snapshot_start_hour": int(aws.Int64Value(snapshotOptions.AutomatedSnapshotStartHour)), + } + + return []map[string]interface{}{m} +} + func flattenESEBSOptions(o *elasticsearch.EBSOptions) []map[string]interface{} { m := map[string]interface{}{} From 6627421581f001ee9a99ec00e0300035f5b9adcd Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Mon, 6 Aug 2018 22:16:54 +0400 Subject: [PATCH 4/4] add DiffSuppressFunc to ignore the difference --- aws/resource_aws_elasticsearch_domain.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aws/resource_aws_elasticsearch_domain.go b/aws/resource_aws_elasticsearch_domain.go index a3499ac6b57..20e24e62d47 100644 --- a/aws/resource_aws_elasticsearch_domain.go +++ b/aws/resource_aws_elasticsearch_domain.go @@ -157,6 +157,12 @@ func resourceAwsElasticSearchDomain() *schema.Resource { "snapshot_options": { Type: schema.TypeList, Optional: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + if old == "1" && new == "0" { + return true + } + return false + }, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "automated_snapshot_start_hour": {