diff --git a/aws/resource_aws_elasticsearch_domain.go b/aws/resource_aws_elasticsearch_domain.go index 3c11c779e95..a393fbcfe90 100644 --- a/aws/resource_aws_elasticsearch_domain.go +++ b/aws/resource_aws_elasticsearch_domain.go @@ -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)) @@ -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) } @@ -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 { @@ -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) } @@ -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") { @@ -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, "") { @@ -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 { diff --git a/aws/resource_aws_elasticsearch_domain_policy.go b/aws/resource_aws_elasticsearch_domain_policy.go index 46ae0c1f821..b9c0e421fdb 100644 --- a/aws/resource_aws_elasticsearch_domain_policy.go +++ b/aws/resource_aws_elasticsearch_domain_policy.go @@ -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) } @@ -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) @@ -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) } @@ -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 }