Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #5440 terraform crash in resource elasticsearch_domain #5451

Merged
merged 4 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions aws/resource_aws_elasticsearch_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -310,7 +316,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{
Expand Down Expand Up @@ -425,7 +431,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") {
Expand All @@ -450,15 +456,15 @@ 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
// whilst the operation is being performed), we still get the required tags on
// 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
}

Expand Down Expand Up @@ -514,8 +520,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)
}
Expand All @@ -525,7 +531,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)
Expand All @@ -546,11 +552,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": *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 {
Expand All @@ -567,7 +573,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 {
Expand All @@ -581,9 +587,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)
Expand Down
12 changes: 12 additions & 0 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}

Expand Down