From eaa48681d44784bdf38a6ac78f784021ff15fa32 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Sat, 3 Sep 2016 16:55:29 +0300 Subject: [PATCH] provider/aws: Refresh `aws_elasticsearch_domain` from state when ResourceNotFoundException (#8643) * provider/aws: Refresh `aws_elasticsearch_domain` from state when RecordNotFoundException Fixes #3967 When an ElasticSearch domain has been deleted outside of Terraform, the next Terraform operation would return the following: ``` * aws_elasticsearch_domain.curvelogic_es: ResourceNotFoundException: * Domain not found: curvelogic-es status code: 409, request id: 6e4b2371-8e1a-11e5-bd07-7741b705d65c ``` We now refresh the resource from state when it is no longer found * Update resource_aws_elasticsearch_domain.go --- builtin/providers/aws/resource_aws_elasticsearch_domain.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/providers/aws/resource_aws_elasticsearch_domain.go b/builtin/providers/aws/resource_aws_elasticsearch_domain.go index b7ba0a843..9b9adfaa8 100644 --- a/builtin/providers/aws/resource_aws_elasticsearch_domain.go +++ b/builtin/providers/aws/resource_aws_elasticsearch_domain.go @@ -256,6 +256,11 @@ func resourceAwsElasticSearchDomainRead(d *schema.ResourceData, meta interface{} DomainName: aws.String(d.Get("domain_name").(string)), }) if err != nil { + if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "ResourceNotFoundException" { + log.Printf("[INFO] ElasticSearch Domain %q not found", d.Get("domain_name").(string)) + d.SetId("") + return nil + } return err }