-
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
terraform destroy tries to evaluate outputs that can refer to non existing resources #18026
Comments
Hi @mildred, Thanks for filing the issue with a great example! Outputs are still evaluated during destroy, because they can feed into other modules that may still depend on them. In this case it's obvious that it can be pruned, but there are some cases that are a little harder to detect at the moment. There are definitely a few more changes I have planed around outputs (and locals) which will take care of this, but they have to wait until after the next major release. Thanks! |
Is there any way to work around this sort of issue? |
Workaround is to always have a successful apply before each destroy. Or revert terraform code before destroying. |
Just adding an additional data point here. I'm currently running into this issue with 0.11.8 and the azurerm provider where a module output is interpolated with formatlist(). Other than those details, looks like the same bug. |
@jbardin Would adding a "terraform refresh" before a validate or before apply solve the issue? |
@elvis2, unfortunately not, because the problem is that the output gets evaluated, not that the state isn't up to date. The output node needs to be selectively pruned from the graph during destroy. |
We run edit Also seeing this in the following scenario: |
Ran into same issue here. In our case we're using Terraform to standup an EKS Kubernetes cluster. One of the ELB's managed by EKS wasn't destroyed properly by Kubernetes, and the |
I get a similar error with v0.11.8:
When I do a destroy, I get an error:
|
I receive a similar error with Terraform v0.11.10.
|
#17655 seems to offer a workaround for this, in the form of setting In that issue there's a link to https://github.com/hashicorp/terraform/blob/master/CHANGELOG.md#0111-november-30-2017 which suggests that this workaround will cease to work in 0.12. Terraform looks to be playing whack-a-mole with this 'Resource X does not have attribute Y for variable' failure mode, so I'm not encouraged to see they plan to remove this flag. All credit to github user hawksight for identifying the workaround and the relevant changelog entry. |
@BruceFletcher thank you! been trying to work around this for a while now, thanks for crossposting the |
Have been wracking my brain for other workarounds, in our case we are using outputs to get underlying EKS attributes to configure kubernetes. If the output you need to access is for scripting and is a rendered template file or other existing attribute, it looks like you can pipe input into Unfortunately we use an alternate plugin dir so I'm still stuck, but hoping this might help someone else. |
@mildred I just want to mention that I had a completely successful apply prior to running destroy, and still had this problem. So this is not a full-proof workaround. |
|
In my case, v0.11.10, the first Upon deleting/destroying those external resources manually, however, all subsequent I was able to Not sure how I would clean it up if I had wanted to re-use the same state, maybe |
I'm still getting this with 0.12.3 not sure why its been labeled as a 0.11 issue and closed. "somevar is empty tuple The given key does not identify an element in this collection value." |
This is still an issue with 0.12.8. I get "The given key does not identify an element in this collection value." This is referencing a mapping output from a module, when the resources created by the module are destroyed (manually), recreating (using |
Also interested in a temporary workaround or update on a fix. We just upgraded to 0.12 as well. |
Any updates on this issue? |
for v0.12.x i had to use conditionals on the outputs like for maps
for tuples/ lists
and my destroy finally worked to the end |
Workaround seems to always have a value to output as a fallback, even null. In my case I'm trying to create either a linux or windows vm and those have different configurations so using a "mode" variable and the count attribute I create the correct resource. Problem was now for the outputs and here is my workaround:
the map contains only one element (either with windows or linux as key) when applying and none when destroying but no errors in either case. (Still, be careful if those outputs are used elsewhere, as they now need to be able to handle a null value) Also, the "try" function should work for newer terraform versions |
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
0.11.7
Terraform Configuration Files
during apply:
during destroy:
Debug Output
https://gist.github.com/mildred/af89828e68b53f996e3132f1eed26229
Output
Expected Behavior
No error should have happened. Terraform should detect that null_resource.b was never created and whouldn't try to access it. Anyway, it doesn't need to generate outputs on destroy.
Actual Behavior
Terraform tries to evaluate the output referring to a non existing resource and fails on it.
Steps to Reproduce
example.tf
the first version of the fileterraform init
terraform apply
example.tf
the second version of the fileterraform destroy
Additional Context
This is an error that initially happened with an AWS resource but could be reproduced with null_resource.
The text was updated successfully, but these errors were encountered: