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

Ignore the 'ResourceNotFoundException' when deleting ElasticSearch Po… #2095

Conversation

charles-at-geospock
Copy link
Contributor

…licies.

If the Elastic Search Domain Policy has already been deleted, and then you
try to destroy it with Terraform, the detroy will fail, reporting that the
resource is not found. This goes against the rest of the implementation of
the Terraform destroy process that already gone resources are silently
ignored.

The problem was caused by one instance of the code using the wrong name for
the exception, and another instance failing to ignore the lack of the
resource as an acceptable error.

Both of these are addressed here. In passing through, more debugging was
added, in line with other functions, and the common domainName value
held in a local variable.

…licies.

If the Elastic Search Domain Policy has already been deleted, and then you
try to destroy it with Terraform, the detroy will fail, reporting that the
resource is not found. This goes against the rest of the implementation of
the Terraform destroy process that already gone resources are silently
ignored.

The problem was caused by one instance of the code using the wrong name for
the exception, and another instance failing to ignore the lack of the
resource as an acceptable error.

Both of these are addressed here. In passing through, more debugging was
added, in line with other functions, and the common domainName value
held in a local variable.
@radeksimko radeksimko added the enhancement Requests to existing resources that expand the functionality or scope. label Oct 28, 2017
@charles-at-geospock
Copy link
Contributor Author

This fix only helps in the case where the resources have been destroyed out of band of the Terraform environment (or at least outside the knowledge of the Terraform state). All the other resource types seem to be very happy to ignore resources that have already gone away.

In my case, the resources were destroyed by the Terraform tool, BUT the assumed role that was in use was expired before the completion of the terraform destroy. This meant that the S3 upload of the state information never happened, and therefore the next terraform destroy was run over the resources and failed for the ESDP. After adding my fix, the destroy completed successfully :-)

@radeksimko radeksimko added the size/S Managed by automation to categorize the size of a PR. label Nov 15, 2017
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking the time to prepare and submit this PR.

For the reasons mentioned in my comments inside the code I'm inclined to close it though.
Do you mind me closing it?

log.Printf("[WARN] ElasticSearch Domain %q not found, removing", domainName)
d.SetId("")
return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition here in Delete() isn't necessary, because by default apply always refreshes the state and runs Read(), so the above condition should be sufficient and more aligned with behaviour of majority of existing resources in the codebase.

@@ -40,7 +40,7 @@ func resourceAwsElasticSearchDomainPolicyRead(d *schema.ResourceData, meta inter
DomainName: aws.String(name),
})
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFound" {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ResourceNotFoundException" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already addressed in #2249

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Nov 15, 2017
@radeksimko
Copy link
Member

Closing for the reasons mentioned.

Thanks.

@radeksimko radeksimko closed this Jan 3, 2018
@ghost
Copy link

ghost commented Apr 8, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. size/S Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants