Index out of range — accessing empty resource attributes
This object does not have an attribute named "ids"
Focused incident mode — strips away everything but this runbook.
Symptoms
- This object does not have an attribute named "ids"
- terraform plan fails with index out of range on empty resource
- Reference to count or for_each on resource with 0 instances
Evidence to grab
Collect these artifacts before you change anything — they prove (or rule out) each cause.
Index error output
terraform plan 2>&1 | grep -A5 'attribute named'Resource instance count
terraform state list | grep <RESOURCE> | wc -l
Diagnostic flow
Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.
Guided decision tree is ready.
Steps with commands, expected output, and pass/fail branches.
Ranked root causes
Evidence checklist
- count = var.enabled ? 1 : 0 when var.enabled = false
- for_each = toset([]) produces zero instances
Confirm before fixing
terraform state list | grep <RESOURCE>Check if any instances exist
Fix
terraform console -e 'length(<RESOURCE>) > 0 ? <RESOURCE>[0].id : null'Use a conditional to safely reference the attribute
Resolution runbook
Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.
terraform plan 2>&1 | grep -A5 'attribute named'Read the exact attribute error
terraform state list | grep <RESOURCE> | wc -lCount instances of the resource
terraform console -e 'length(<RESOURCE>)'Check if the resource has any instances
terraform validateConfirm the fix compiles
Prevention
- Always check length() before indexing into resources with count or for_each.
- Use try() or conditional expressions for optional references.
- Test plans with the full set of variables (including disabled features).
- Use terraform validate in CI to catch type errors.
Related runbooks
Same stack, same failure family — worth a skim.
The given "for_each" argument value is unsuitable: must be a map, or set of strings
An argument named "instance_typo" is not expected here
Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.