Skip to content

Commit

Permalink
Merge pull request #9892 from terraform-providers/rfd-retry-elastic
Browse files Browse the repository at this point in the history
Final retries for elasticsearch domain resources
  • Loading branch information
ryndaniels authored Sep 10, 2019
2 parents b4efb0b + 6b99958 commit 07d758c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 22 deletions.
71 changes: 58 additions & 13 deletions aws/resource_aws_elasticsearch_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,11 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface
}
return nil
})

if isResourceTimeoutError(err) {
out, err = conn.CreateElasticsearchDomain(&input)
}
if err != nil {
return err
return fmt.Errorf("Error creating ElasticSearch domain: %s", err)
}

d.SetId(aws.StringValue(out.DomainStatus.ARN))
Expand Down Expand Up @@ -509,10 +511,13 @@ func resourceAwsElasticSearchDomainCreate(d *schema.ResourceData, meta interface
}

func waitForElasticSearchDomainCreation(conn *elasticsearch.ElasticsearchService, domainName, arn string) error {
return resource.Retry(60*time.Minute, func() *resource.RetryError {
out, err := conn.DescribeElasticsearchDomain(&elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(domainName),
})
input := &elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(domainName),
}
var out *elasticsearch.DescribeElasticsearchDomainOutput
err := resource.Retry(60*time.Minute, func() *resource.RetryError {
var err error
out, err = conn.DescribeElasticsearchDomain(input)
if err != nil {
return resource.NonRetryableError(err)
}
Expand All @@ -524,6 +529,19 @@ func waitForElasticSearchDomainCreation(conn *elasticsearch.ElasticsearchService
return resource.RetryableError(
fmt.Errorf("%q: Timeout while waiting for the domain to be created", arn))
})
if isResourceTimeoutError(err) {
out, err = conn.DescribeElasticsearchDomain(input)
if err != nil {
return fmt.Errorf("Error describing ElasticSearch domain: %s", err)
}
if !*out.DomainStatus.Processing && (out.DomainStatus.Endpoint != nil || out.DomainStatus.Endpoints != nil) {
return nil
}
}
if err != nil {
return fmt.Errorf("Error waiting for ElasticSearch domain to be created: %s", err)
}
return nil
}

func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -727,10 +745,12 @@ func resourceAwsElasticSearchDomainUpdate(d *schema.ResourceData, meta interface
return err
}

descInput := &elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(d.Get("domain_name").(string)),
}
var out *elasticsearch.DescribeElasticsearchDomainOutput
err = resource.Retry(60*time.Minute, func() *resource.RetryError {
out, err := conn.DescribeElasticsearchDomain(&elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(d.Get("domain_name").(string)),
})
out, err = conn.DescribeElasticsearchDomain(descInput)
if err != nil {
return resource.NonRetryableError(err)
}
Expand All @@ -742,8 +762,17 @@ func resourceAwsElasticSearchDomainUpdate(d *schema.ResourceData, meta interface
return resource.RetryableError(
fmt.Errorf("%q: Timeout while waiting for changes to be processed", d.Id()))
})
if isResourceTimeoutError(err) {
out, err = conn.DescribeElasticsearchDomain(descInput)
if err != nil {
return fmt.Errorf("Error describing ElasticSearch domain: %s", err)
}
if !*out.DomainStatus.Processing {
return nil
}
}
if err != nil {
return err
return fmt.Errorf("Error waiting for ElasticSearch domain changes to be processed: %s", err)
}

if d.HasChange("elasticsearch_version") {
Expand Down Expand Up @@ -810,8 +839,10 @@ func resourceAwsElasticSearchDomainDeleteWaiter(domainName string, conn *elastic
input := &elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(domainName),
}
var out *elasticsearch.DescribeElasticsearchDomainOutput
err := resource.Retry(90*time.Minute, func() *resource.RetryError {
out, err := conn.DescribeElasticsearchDomain(input)
var err error
out, err = conn.DescribeElasticsearchDomain(input)

if err != nil {
if isAWSErr(err, elasticsearch.ErrCodeResourceNotFoundException, "") {
Expand All @@ -826,8 +857,22 @@ func resourceAwsElasticSearchDomainDeleteWaiter(domainName string, conn *elastic

return resource.RetryableError(fmt.Errorf("timeout while waiting for the domain %q to be deleted", domainName))
})

return err
if isResourceTimeoutError(err) {
out, err = conn.DescribeElasticsearchDomain(input)
if err != nil {
if isAWSErr(err, elasticsearch.ErrCodeResourceNotFoundException, "") {
return nil
}
return fmt.Errorf("Error describing ElasticSearch domain: %s", err)
}
if out.DomainStatus != nil && !aws.BoolValue(out.DomainStatus.Processing) {
return nil
}
}
if err != nil {
return fmt.Errorf("Error waiting for ElasticSearch domain to be deleted: %s", err)
}
return nil
}

func suppressEquivalentKmsKeyIds(k, old, new string, d *schema.ResourceData) bool {
Expand Down
38 changes: 29 additions & 9 deletions aws/resource_aws_elasticsearch_domain_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ func resourceAwsElasticSearchDomainPolicyUpsert(d *schema.ResourceData, meta int
}

d.SetId("esd-policy-" + domainName)

input := &elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(d.Get("domain_name").(string)),
}
var out *elasticsearch.DescribeElasticsearchDomainOutput
err = resource.Retry(50*time.Minute, func() *resource.RetryError {
out, err := conn.DescribeElasticsearchDomain(&elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(d.Get("domain_name").(string)),
})
var err error
out, err = conn.DescribeElasticsearchDomain(input)
if err != nil {
return resource.NonRetryableError(err)
}
Expand All @@ -84,8 +86,14 @@ func resourceAwsElasticSearchDomainPolicyUpsert(d *schema.ResourceData, meta int
return resource.RetryableError(
fmt.Errorf("%q: Timeout while waiting for changes to be processed", d.Id()))
})
if isResourceTimeoutError(err) {
out, err = conn.DescribeElasticsearchDomain(input)
if err == nil && !*out.DomainStatus.Processing {
return nil
}
}
if err != nil {
return err
return fmt.Errorf("Error upserting Elasticsearch domain policy: %s", err)
}

return resourceAwsElasticSearchDomainPolicyRead(d, meta)
Expand All @@ -103,10 +111,13 @@ func resourceAwsElasticSearchDomainPolicyDelete(d *schema.ResourceData, meta int
}

log.Printf("[DEBUG] Waiting for ElasticSearch domain policy %q to be deleted", d.Get("domain_name").(string))
input := &elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(d.Get("domain_name").(string)),
}
var out *elasticsearch.DescribeElasticsearchDomainOutput
err = resource.Retry(60*time.Minute, func() *resource.RetryError {
out, err := conn.DescribeElasticsearchDomain(&elasticsearch.DescribeElasticsearchDomainInput{
DomainName: aws.String(d.Get("domain_name").(string)),
})
var err error
out, err = conn.DescribeElasticsearchDomain(input)
if err != nil {
return resource.NonRetryableError(err)
}
Expand All @@ -118,5 +129,14 @@ func resourceAwsElasticSearchDomainPolicyDelete(d *schema.ResourceData, meta int
return resource.RetryableError(
fmt.Errorf("%q: Timeout while waiting for policy to be deleted", d.Id()))
})
return err
if isResourceTimeoutError(err) {
out, err := conn.DescribeElasticsearchDomain(input)
if err == nil && !*out.DomainStatus.Processing {
return nil
}
}
if err != nil {
return fmt.Errorf("Error deleting Elasticsearch domain policy: %s", err)
}
return nil
}

0 comments on commit 07d758c

Please sign in to comment.