-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Ignore the 'ResourceNotFoundException' when deleting ElasticSearch Po… #2095
Conversation
…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.
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 |
There was a problem hiding this 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 | ||
} |
There was a problem hiding this comment.
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" { |
There was a problem hiding this comment.
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
Closing for the reasons mentioned. Thanks. |
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! |
…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.