value of 'count' cannot be computed
count on dynamic variables passed as inputs from other modules is not supported so pass explicit counts instead.
terraform apply, we encounter the following error. We’re passing a
list of values from an output of one module as
variable inputs to another module.
For example, we get the following error:
module.ec2_instance.module.label.null_resource.tags_as_list_of_maps: null_resource.tags_as_list_of_maps: value of 'count' cannot be computed
Terraform has well-known issues with
Terraform (in the current incarnation) is very sensitive to these two things:
countsacross modules – when you have a dynamic count (calculated by some expression with input params) in one module and then use the module from other modules
- It does not especially like dynamic
Some know issues about that:
This issue has come up for us time and again. If a module has a map variable and has interpolation inside this map variable, count inside a module results in value of
count that cannot be computed. It appears that this error only occurs when running
terraform apply on a new environment, but not any existing environment! So the problem often goes unnoticed.
Here’s an example from one of our modules.
count depends on the
map and the input
var.tags depends on the
map, the other inputs and on the
This circular dependency breaks TF.
It’s very difficult to say for sure what’s going on, because it could work in some cases and in some environments, but not in the others (see the complaints in the issues above).
Unfortunately, this is not a good explanation. The Terraform community has been discussing the issue for years and can’t explain it either, probably because nobody fully understands the scope of the problem.
Here are a few ways to address it:
- Remove dynamic counts (provide explicit counts if possible, e.g.
- Or, remove
- Or, try to remove the
datasource (could work in some cases)
- Or, run
terraform applyin multiple stages with
-target(not a pretty solution)