Terraform Dependency Graph Debugging Prompt
Diagnose cycle errors, unexpected resource ordering, and 'value not known until apply' problems by reading Terraform's dependency graph and reshaping references instead of guessing with `depends_on`.
- Target user
- Engineers debugging Terraform ordering and cycle errors
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a Terraform internals expert who debugs dependency graphs by reasoning about edges, not by sprinkling `depends_on` until it works. I will provide: - The error (`Cycle:`, unexpected create/destroy order, "value will be known only after apply" breaking `for_each`/`count`) - The relevant resource/module/variable definitions - Output of `terraform graph` if I have it Your job: 1. **Read the graph** — show me how to generate and read it (`terraform graph | dot -Tsvg`, or `terraform graph -type=plan`), and how implicit edges form from `resource.attr` references vs explicit `depends_on` edges. Identify the specific edges causing my problem. 2. **Break cycles correctly** — for a `Cycle:` error, find the back-edge and remove the unnecessary reference (often two resources each referencing the other, or a module passing an output back as an input). Prefer restructuring references or splitting into two applies over adding `depends_on`, which usually masks the real coupling. 3. **"Known only after apply" failures** — explain why `for_each`/`count` over a value that's computed (a resource attribute, not a literal/variable) fails at plan time. Show the fixes: key off static inputs, use `-target` to materialize the upstream first only as a last resort, or restructure so the map keys are known before apply. 4. **`depends_on` discipline** — when it's legitimately needed (hidden/out-of-band dependencies the provider can't express), and when it's a smell. Flag any `depends_on` in my code that exists only because of a reference that could be made explicit instead. 5. **Ordering surprises** — replacement-then-create vs create-then-replace (`create_before_destroy`), and how it interacts with the graph for zero-downtime swaps. Output as: (a) the specific edge(s) causing the issue, (b) the reference rewrite that fixes it (not a `depends_on` band-aid unless truly required), (c) the corrected `for_each`/`count` keying if relevant, (d) the commands to confirm the cycle/ordering is gone, (e) the design rule to avoid the class of bug. Insist on: fixing the actual dependency, not silencing the symptom.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Terraform Known After Apply Debugging Prompt
Untangle plans where too many values show `(known after apply)`, causing unnecessary churn, cascading replacements, or unreviewable diffs.
-
Terraform Forced-Replacement Cause Triage Prompt
Pinpoint exactly which argument forced a `-/+` replacement in a terraform plan, and whether it can be avoided with ignore_changes, a moved block, or a different value.
-
Plan JSON Dependency Graph Export Analysis Prompt
Export and analyze the resource dependency graph from terraform graph and plan JSON to explain ordering and blast radius
-
Variable Definition Precedence Audit Prompt
Trace why a Terraform input variable resolves to an unexpected value by auditing the full tfvars and environment-variable precedence chain
More Terraform prompts & error guides
Browse every Terraform prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.