-
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
Allow for numeric/string comparisons in count, or change resulting error message from '"cannot" to "will not" be determined' #34726
Comments
Hi @jaffel-lc! Thanks for sharing this. I want to pick out one part of what you said to start:
This statement is incorrect. It's true that the values of all root module input variables are known at plan time -- because they are specified directly as resource "aws_subnet" "example" {
# ...
}
module "example" {
# ...
subnet_id = aws_subnet.example.id
}
I'm not sure whether that applies to your situation, though: your writeup doesn't show where the value of However, if what you have here is another example of the situation I illustrated above, where the input variable is derived from something that's unknown during planning, then I think this issue is essentially a subset of the existing #30937, for which some work has already been done and further work is happening right now. |
In this case, the value of var.kms_key is a string variable , with a default value - not a value derived from a not-yet-existent resource.
|
Thanks for that extra context. Can you also show me how you are setting the value for this variable? The caller of a module is the one that decides if a given variable value is known or not, so that's the more important thing to consider when figuring out what happened here. |
I already have. |
@jaffel-lc, We would need to see the |
I appreciate your patience and perseverance. It took several readings, but I finally understood what you were trying to tell me. I've rearranged my tests so that the KMS key is build in a tf apply before the apply that creates resource that tries to use it, and I am passing it from a data block instead of a module block. And it works, just like you said it would. Thank you very much. |
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. |
Terraform Version
Use Cases
count allows for a ?: operator as long as the left side is a Boolean variable or a comparison of of that variables state.
for example:
But a string comparison in the same place generates an error.
For example:
Generates this error:
In this case, the value of the variable absolutely can be determined at plan time. The values of all variables are known at plan time. Data blocks that rely on variables run at plan time, so they must therefore be available within resource block.
Attempted Solutions
The only way to solve the error error message is to rely on strictly Boolean values for count
Proposal
Terraform should, at plan-time, perform variable-base calculations and comparisons to that resource counts can rely on the truthiness of non-Boolean values - many languages consider 0 and "" to be false - in direct comparisons or including some calculations of function calls.
Or change the error message to say "will not be determined until apply time".
References
No response
The text was updated successfully, but these errors were encountered: