-
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
0.13 count/for_each cannot be determined while destroying even with an empty state #25851
Comments
In my opinion, this bug is absolute CRITICAL In my code base, i always run in this when a resource with count/for_each using attributes from a other resource or module output which is created with count/for_each. This bug was alredy mentioned at #25815 but the thread opener gives up and closed it without a solution. Because @danieldreier answered in the closed ticket: Please take attention to this bug. Terraform 0.13 is not usable anymore with this if you have a mid-complex code structure. |
@jbardin if I'm understanding this correct, I think what's happening is that now that data sources are evaluated as part of the graph, functions that reference data sources return a "cannot be determined until apply" error. Am I understanding it right? If so, this does indeed seem like it would have a significant impact. |
I don't think this is specifically because of data sources, running destroy with an empty state is definitely and edge case that is not well tested. I don't have a full reproduction for this at the moment, but there's a good chance it will be covered by the fix for #25891. |
To clarify this happened when destroying a complete state, and then errorred after that state had been destroyed, subsequent commands to destroy fail for the same reason though. |
I can confirm this bug. It's even happening while not changing anything. It's completely non-deterministic behaviour in our case. If I go ahead and target just the depending resource, sometimes it works after one targeted run, sometimes only after a few, sometimes never. This is really bad and breaking some critical code for us. |
While terraform should be able to run |
In our case it's not happening specifically in a destroy run, but in every run - plan, apply, destroy. This is code that has been working fine in 0.12. I've read this comment #25815 (comment) which hints that maybe the code have is just "bad", but has been working until now. I'm currently trying to fix these instances by moving them over to for_each instead of count + length. Will report back on how this is working out. In my current case, I'm completely stuck at this error:
For some errors, I was able to workaround this by running the suggested -target, but in this case of a datasource this is not possible, hence we probably are forced to rewrite this code. |
No luck. 👎
|
@jbardin For me its the behaviour from what @JanKoppe said. In the comment #25815 @danieldreier said the code is maybe bad, but its exactly how all the Terraform modules from Microsoft are designed. See: https://github.com/Azure/terraform-azurerm-compute (and honestly, my private modules also, because there is no other way when you run different stages with the same code base where you have different amounts of vms etc.). The network cards here are build with a count attribute and returned in the output.tf as a list: https://github.com/Azure/terraform-azurerm-compute/blob/master/outputs.tf In the AzureRM Provider its very common that you have to connect two resources together over their id like the network_interface_application_security_group_association or the virtual_machine_data_disk_attachment. And i think its a very common usecase that you have different amounts of vms, disk, or network cards for each stage/workspace with the same code base. So if you use a assocation like in #25815 where cound depends on the length of the list, which is returnd by the compute module:
Then on my side i run in this problem. Using for_each change nothing on that. |
I believe a number of different issues are being confused here. This particular issue is about being able to run destroy with an empty state. This will hopefully be remedied by the same fix as #25891, and can be closed once we confirm. Any errors arising during plan or apply are very different issues, and not relevant here. If the count or for_each values are derived from data sources, it's likely that the root cause will be helped by #25812, but there are probably some data sources that still need updates from their respective providers to fix broken schemas as well. |
@jbardin Maybe i understand this wrong, but with data sources you meen a data source block? Because the output from network cards from the example are just a list of objects given by the attribute of the resource? The is no If you think this is not the same case (even its the same exception message), i think we should reopen #25815 |
To add to the discussion, I opened this issue about destroy because that was the one that I could reproduce reliably. But I am also having the same "cannot determine count" issues with other actions like apply as well. |
I believe I am having a very similar issue to @zachwhaley. @jbardin I think @zachwhaley's issue was not that I have a very simple project that uses the Google GKE module https://registry.terraform.io/modules/terraform-google-modules/kubernetes-engine/google/11.0.0. After successfully running
|
I'm also running into this exact same issue. It's completely broken one of my terraform plans. Worked without issues in 0.12.29. I'm running a similar for_each on other resources and they don't seem to be affected. |
like @kingsleyadam said but with an example
or with a dirty zipmap and foreach
worked fine in 0.12.29, after upgrading to 0.13 it broke
The suggest work around has no effect however because even if i run the |
Here's more detailed information on my setup and where it fails. Part of our terraform plan is to attach a server to multiple load balancers in Azure. We're speciyfing the load balancer as a direct variable:
Worked in 0.12.29, after upgrading to 0.13.0 we get:
Same as @DarkMukke, even if I Hopefully a fix is found ASAP. |
This appears to have been fixed in 0.13.1 I'm no longer seeing issues during destroy. |
@nicklofaso the |
Fixed at first apply operation, but I still have error when reapplying. |
Thanks for the confirmation @zachwhaley! |
I don't think this issue is completely fixed. May need to open a new one that covers more than just destroy. Multiple people have confirmed that it's happening on apply as well as destroy. I'm not able to test since 0.13.1 broke my terraform setup completely. Once 0.13.2 is out I can confirm and open a new issue. |
Confirming on 0.13.2 that this is still an issue for me. I can't apply my plan, I continue to get.
|
Thanks you are right. My issue is fixed in 0.13.1! |
I was able to resolve my issues so I'm posting in case someone else comes across this. The error is very misleading, I was under the impression that terraform couldn't come up with the list of items to be created based on my for_each.
The real issue was that I was using an unknown value for they key of the for each. I was using the id of the resource that was to be created, which it didn't know during apply. The fix was to use my own configured values for the key, now all my issues are resolved. This did work in 0.12.x. Hope this helps someone. |
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. |
Hello, we are experimenting with Terraform 0.13 and seeing an odd behavior where a destroy errors out because it reportedly cannot determine the count/for_each for a resource even though they are straight variables, and this seems to happen after the resources has been destroyed.
Terraform Version
Terraform Configuration Files
The subnet vars in the example above are declared like so
I found the state file in question:
Debug Output
Crash Output
Expected Behavior
Nothing errors
Actual Behavior
Errors occur
Steps to Reproduce
terraform apply
.terraform
directoryterraform init
terraform destroy
I've noticed this does not happen if I do a straight
apply
followed by adestroy
Additional Context
References
The text was updated successfully, but these errors were encountered: