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
Changes from 2 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
22 changes: 11 additions & 11 deletions aws/resource_aws_elasticsearch_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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") {
Expand All @@ -450,15 +450,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 +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)
}
Expand All @@ -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)
Expand All @@ -548,7 +548,7 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{}
}
if ds.SnapshotOptions != nil {
Copy link
Contributor

@bflad bflad Aug 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This d.Set() was incorrectly implemented before (notice the missing [] before the map) and we should probably fix it now. I think the AutomatedSnapshotStartHour value also needs to be wrapped in int(). Something like the below could handle both for now and return an error if incorrect:

if err := d.Set("snapshot_options", flattenESSnapshotOptions(ds.SnapshotOptions)); err != nil {
	return fmt.Errorf("error setting snapshot_options: %s": err)
}
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}
}

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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down