-
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
Erroneous 'Invalid for_each argument' when interpolating const map #22735
Comments
I am seeing same issue with terraform 0.12.8 /******************************* module foo ***********************/
//output.tf
/*************************************** ***********************/ //main.tf
|
Hi @OJFord! Thanks for reporting this. Was this working for you before in Terraform 0.12.7, or did you try this configuration for the first time in Terraform 0.12.8? We made some changes in this area in 0.12.8 to address some related bugs, so we'd like to try to figure out if this is a regression from those changes or a separate issue. Thanks! |
@terraformbot I believe it is actually resolved (perhaps by the changes in .7->.8) - the So you can get output like:
where it looks like the fix hasn't worked, but actually it relates to a However, what would be really great is if only the resource "server_resource" "servers" {
count = 3
name = "server-${count.index}"
# ...
}
locals {
servers = { for s in server_resource : s.name => s.id } # or whatever post-apply values
}
# *Not* possible today, don't copy-paste!
resource "null_resource" "n" {
for_each = local.servers # each.key is known at plan, each.value isn't
# use `each.value`
} |
@teamterraform @OJFord @pselle I have observed https://github.com/hashicorp/terraform/pull/22597 in terraform 0.12.7 and terraform 0.12.8 fixed few of the issues but strangely in some cases like the above one I have posted it is still happening.. I am not quite sure why this is the case.... |
Any update on this issue.. I am kind of stuck because of this issue... |
Thanks for the report @OJFord!
I've opened #22760 to add error source addressing for this error, which will make it much more useful, and easier to debug. I tested the initial issue's case and was able to successfully apply (which it sounds like you did as well), so that case looks fixed to me. In regards to the most recent comment, what you said should be true:
When I try your example on a map with known keys (but unknown values), things work smoothly for me. In general, this should be true (that map keys must be known, but values need not necessarily). Thanks so much for including examples, they are very helpful! Here's my working example (on 0.12.8):
|
@pselle Thank you for clarifying.. I am still not sure why the we are seeing this issue in the example I have posted above. |
I am able to reproduce the above error in the following examples as well .... /// not working
but if I change
to
the error disappears.... and even if change the above code to use maps... the error is gone ... working example ..
and the error returns again when I change to
or
it looks to me as if |
This is the line that seems like the best candidate to me, @venky999:
In the set definition, that's creating a dependency on the output of the module, thus leading me to believe the set contains unknown values (a set for |
thank you @pselle ... do you think the same issue might be the reason for the error in the pets examples I have posted ... |
@venky999 Sort of -- it has to do with the dynamism of the data, and when the values are known. Just because an expression contains "constant" values, depending on when things are evaluated, it may still be unknown from Terraform's perspective, and if values are unknown when TF is assigning keys to instances, that's a problem (from TF's perception of the world). I'm going to keep thinking about this and leave this open for now. |
thank you @pselle |
I believe this is the bug. I have a module that uses I parametrize the module like this: I parametrize it like this: (0.12.8 and 0.12.20) |
I've opened a documentation PR after further investigating this issue and am closing this one -- the original example is fixed, and further examples in this thread lead to investigation (thanks @jbardin!) leading to seeing that this is an expected behavior if using impure functions, of which As to @nik-shornikov -- the number of string keys is known, so you could use Thank you everyone for your examples, and for your patience. |
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 Configuration Files
Expected Behavior
Successful
plan
.Actual Behavior
Steps to Reproduce
terraform plan
Additional Context
As expected,
terraform apply -target=locals.server_set
does not help:The text was updated successfully, but these errors were encountered: