Terraform: Error: Invalid count argument — The "count" value depends on resource attributes that cannot be determined until apply
count depends on something unknown at plan time, so Terraform can't decide how many instances to create.
Error: Invalid count argumentThe "count" value depends on resource attributes that cannot be determined until applyThe "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be createdInvalid count argument count cannot be determined until apply Meaning
Make the count depend on known inputs (variables, length(var.list)), not on computed attributes of resources in the same plan. For conditional creation use a boolean variable: count = var.enabled ? 1 : 0. Two-stage apply (-target) is a workaround, not a design.
Common causes
count = length(aws_x.y)/data.*with unknown inputs- Conditional on a computed attribute
- Module output unknown
countusing IDs from not-yet-created resources- Data source depending on a resource
⚡ Quick fix
count = var.create ? 1 : 0with a plain variable- Compute counts from inputs (list lengths)
- Restructure dependencies or split applies
Detailed fix by platform
Terraform
count = var.enable_feature ? 1 : 0
How to diagnose
- Count — Known at plan?
- Source — Computed attribute?
- Alternative — Variable?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Error: Cycle (dependency cycle) Terraform: Error: Cycle: aws_security_group.a, aws_security_group.b
- Invalid AWS Region Terraform: Error: Invalid AWS Region: us-east-3 / Error: configuring Terraform AWS Provider: validating provider credentials: operation error STS: GetCallerIdentity
- Invalid for_each argument (keys cannot be determined until apply) Terraform: Error: Invalid for_each argument — The "for_each" map includes keys derived from resource attributes that cannot be determined until apply
Most viewed in Terraform
- Error acquiring the state lock Terraform: Error: Error acquiring the state lock — ConditionalCheckFailedException / state blob is already locked
- Inconsistent dependency lock file Terraform: Error: Inconsistent dependency lock file — provider x: required by this configuration but no version is selected
- Reference to undeclared resource Terraform: Error: Reference to undeclared resource / Reference to undeclared input variable
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026