-
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
<computed> * 0 should equal 0, not <computed> #15498
Comments
Hi @ask0n! Thanks for reporting this. Would you mind sharing some example config here so we can see what you're getting at? I think what you're saying here is that the unknown value propagation could make some assumptions about things like However, your mention of |
@apparentlymart you're absolutely right, I meant that I mentioned about My use case for this is "green/blue" deployment. I have reusable ec2 module which creates ec2 instances for both "green" and "blue" configuration. I can't use separate environment for this (with VPC peering, own subnets, etc.) because I have configured VPN and it can't be shared in AWS via VPC peering. Depending on the result of deployment I'm shutting down "green" or "blue" version. After this I need to generate ansible inventory file, using output values for created stack.
Now I need to create text file for ansible with this lines:
Separate ansible module is used to create this inventory and run ansible. It looks like:
Since I didn't find a way to get item index using
And in resulting template I have such var: The issue is master_index template. It count becomes not computed, when for example my "green" stack is not needed. My ec2 module skips all resources for green module, but since terraform can't compute Maybe I have selected too complicated path for such task, but now I don't see other way to disable parts of configuration without commenting out parts of code. |
Thanks for this detailed use-case description, @ask0n. Adding a special case that multiplying by zero always produces zero does seem reasonable, and I think it works within our rules for the behavior of unknown values. One thing we have on the list for improving the configuration language in future is to remove the distinction between integer and floating point numbers in the configuration language, at which point it'll be easier to make assumptions that the operands to arithmetic operators can always be assumed to be numbers (or convertible to numbers.) Eventually something like #4149 will also help here, because it'll allow Terraform to proceed with a computed count, deferring certain operations (which in your case will actually be a no-op). I think these two features together will make your use-case work most smoothly, but we can get part-way there by implementing either of them in isolation. |
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. |
Hi,
I faced with situation when I need run tasks as module depending on other variables.
Since module resource doesn't support count, I have to use trigger variable like var.run_task which I use in the reusable module as multiplier for count. So when I don't need module to be executed I just pass run_task = 0 to it.
The strange behavior is: even if one of the multipliers set to 0 explicitly, terraform still tries to calculate value for other multipliers. Since some of module tasks are missed result couldn't be calculated and I'm getting "value of 'count' cannot be computed".
I think this is bug, because we can be pretty sure that result will be equal to 0 if one of the multipliers is 0. At least terraform should check first variable value in the count before looking up others.
UPD: Using in module output
coalesce(aws_autoscaling_group.ec2_instance_as.desired_capacity, 0)
also doesn't produce 0 value for future use.The text was updated successfully, but these errors were encountered: