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

Final retries for elasticsearch domain resources #9892

Merged
merged 1 commit into from
Sep 10, 2019
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
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
}