count is derived from an attribute known only after apply
CommonAn ID, ARN, IP address or a value computed from one, often through a module output, feeds count. On a fresh environment it is unknown at plan time.
Confirm
terraform plan 2>&1 | grep -A4 'Invalid count argument'
The count expression, and which resource attribute it reads
Fix
- Base count on values you control: a variable, a local list, or the input you passed to the other resource (for example length(var.subnet_cidrs) rather than length(aws_subnet.this[*].id)).
- Use a boolean variable for create-or-not: count = var.enable_x ? 1 : 0.
- Where the set of things is keyed by known names, switch to for_each over a map of those names; for_each has the same rule, so the keys must also be known.
count = length(var.names)
A value from configuration is known at plan time; an attribute the provider computes may not be.