Skip to content

Commit

Permalink
Merge pull request #1399 from charles-at-geospock/tag-elasticsearch-d…
Browse files Browse the repository at this point in the history
…omain-before-waiting

Apply tags to Elastic Search domain resources after creation.
  • Loading branch information
radeksimko authored Aug 23, 2017
2 parents f88bea9 + 1038ed1 commit 9eff87b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions aws/resource_aws_elasticsearch_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface

d.SetId(*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 {
return err
}

d.Set("tags", tagsToMapElasticsearchService(tags))
d.SetPartial("tags")

log.Printf("[DEBUG] Waiting for ElasticSearch domain %q to be created", d.Id())
err = resource.Retry(60*time.Minute, func() *resource.RetryError {
out, err := conn.DescribeElasticsearchDomain(&elasticsearch.DescribeElasticsearchDomainInput{
Expand All @@ -264,15 +277,6 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface
if err != nil {
return err
}

tags := tagsFromMapElasticsearchService(d.Get("tags").(map[string]interface{}))

if err := setTagsElasticsearchService(conn, d, *out.DomainStatus.ARN); err != nil {
return err
}

d.Set("tags", tagsToMapElasticsearchService(tags))
d.SetPartial("tags")
d.Partial(false)

log.Printf("[DEBUG] ElasticSearch domain %q created", d.Id())
Expand Down

0 comments on commit 9eff87b

Please sign in to comment.