# Terraform: Error: Invalid count argument — The "count" value depends on resource attributes that cannot be determined until apply

**Code:** `Invalid count argument (value unknown until apply)` · **Category:** Terraform · **Seen on:** Terraform

`count` depends on something unknown at plan time, so Terraform can't decide how many instances to create.

## 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
- `count` using IDs from not-yet-created resources
- Data source depending on a resource

## Quick fix

1. `count = var.create ? 1 : 0` with a plain variable
2. Compute counts from inputs (list lengths)
3. Restructure dependencies or split applies

## Detailed fix by platform

### Terraform

1. `count = var.enable_feature ? 1 : 0`

## How to diagnose

1. **Count** — Known at plan?
2. **Source** — Computed attribute?
3. **Alternative** — Variable?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/terraform/invalid-count-argument-unknown-value)
