-
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
Subsequent variable arithmetics / interpolation when count is zero #15993
Comments
Also affected by this. If count==0 the other variables shouldn't be interpolated. |
I am also impacted by this scenario. FWIW It doesn't seem to affect every resource type, as I have two different resource types defined doing a modulo on 0 when count for both resources is zero. However, the ebs volume attachment resource has problems and spits a divide by zero error.
I applied the workaround in this issue and it seems to resolve the plan problem. |
+1 |
Posting +1 comments doesn't do anything except create noise for the people following this issue. To influence prioritization, please add a 👍 reaction to the original comment. With this said: Terraform's behavior here is going to change slightly in the next major release to improve the situation here, but not in exactly the way described. It is intentional that Terraform validates the configuration within a I understand that there are some situations where this behavior is inconvenient, because as the author you know that in practice a certain problem only occurs with During validation, Terraform will check the expressions under the assumption that Taking the example from the original comment here: route_table_id = "${element(var.route_table_ids, ceil(count.index / length(var.peer_environment_groups)))}" Terraform will evaluate the argument to that This should therefore pass validation and then not be considered again by later passes due to the zero count. However (for completeness) if we were to instead write something like this: route_table_id = count.index - "not a number" ...the validation pass would still flag this as an error, even if It's likely that there will still be some cases where the static checker will flag things overly-conservatively. That's a consequence the safety/flexibility tradeoff we're trying to make here, but since the next major release is also planned to fix #15605 it should be possible to give the validator additional hints by placing the troublesome expression in a conditional clause that isn't evaluated when |
Hi all! The changes I mentioned in my previous comment were included in Terraform v0.12.0, which has now been released. |
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.9.11
Terraform Configuration Files
The above would fail with the following error (as var.peer_environment_groups in route_table_id is zero):
I've got a workaround for it, however it would be nice if I didn't have to do it:
Explanation: Dividing by 1 rather than 0 when peer_environment_groups length is zero, this won't actually do anything but unblocks the plan and doesn't produce the error anymore.
Expected Behavior
Ignore the subsequent variables/function calls when count is zero.
Actual Behavior
Terraform proceeded to interpolate the variables and carry out the arithmetics when the count of the resource is zero.
The text was updated successfully, but these errors were encountered: