-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Destroy provisioners not working if resource is using "create_before_destroy" lifecycle #13395
Comments
Hi @daniel-ro! Sorry this isn't working as expected. I was able to reproduce this using the resource "null_resource" "foo" {
triggers {
val = "1"
}
provisioner "local-exec" {
command = "echo create provisioner"
}
provisioner "local-exec" {
when = "destroy"
command = "echo destroy provisioner"
}
lifecycle {
create_before_destroy = true
}
}
I'm going to dive in and try to figure out what's going on here. Thanks for reporting this! |
This has a similar interesting challenge to #13097, whereby we don't retain enough information in state to know what provisioners were present when a resource was created. I'm intending to try to make Terraform run the destroy provisioners that are in config at the time the deposed resource is destroyed, but this will have an edge case: If a resource already has an instance and I later add a destroy provisioner to it, replacing that resource will cause the destroy provisioner to run against the existing instance even though it might never have had a corresponding create provisioner run on it. This seems like an acceptable tradeoff for now, but it will add one more gotcha to the existing set of gotchas for destroy-time provisioners. |
@apparentlymart thank you for your fast response!
|
Unfortunately I'm going to have to put this one on the back-burner for a little while since its solution is quite a lot more complex than I originally expected, related to my earlier comment. We understand that this limitation makes destroy provisioners hard to use, so we will hopefully return to this in the near future but I am removing myself as the assignee just to represent that I'm not pro-actively working on this right now and that someone else on the team could pick it up. |
Since we have found a few different cases of this similar issue now, I'm going to consolidate this into #13549 as an umbrella, since I expect the fix for all of these will be similar and tackled at the same time. |
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform v0.9.2
Affected Resource(s)
Terraform Configuration Files
Debug Output
Expected Behavior
Destroy Provisioner should run before "deposed" instance termination, and on failure if happened and not "on_failure"="continue", prevent destruction.
Actual Behavior
Deposed resource destroyed without running the destroy provisioner.
Steps to Reproduce
terraform apply
terraform apply
againReferences
The text was updated successfully, but these errors were encountered: