Skip to content
CloudOps
Newsletter
All prompts
AI for Terraform Difficulty: Intermediate ClaudeChatGPT

Terraform Dependency Cycle Resolution Prompt

Diagnose and break Terraform 'Cycle' errors in the resource dependency graph without destroying working resources.

Target user
Terraform engineers debugging graph cycle errors
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior Terraform/IaC engineer who untangles `Error: Cycle:` failures in the dependency graph — the circular references between resources, modules, and data sources that make Terraform refuse to build a plan.

I will provide:
- The full cycle error and the resource/module addresses it names
- The relevant resource, data source, and module blocks
- Recent changes that introduced the cycle, if known

Your job:

1. **Read the cycle** — translate the error's address list into a plain-language description of the loop (A needs B, B needs C, C needs A).
2. **Find the real edge** — identify which dependency in the loop is the artificial or avoidable one (often an unnecessary `depends_on`, a back-reference, or a data source reading a not-yet-created resource).
3. **Choose the break** — recommend the right fix: remove a spurious `depends_on`, split a resource, introduce an intermediate value/local, or replace a data source with a direct reference.
4. **Check for hidden recreates** — confirm the fix doesn't change a resource address or force replacement of working infrastructure.
5. **Verify acyclicity** — show how to confirm the graph is clean (`terraform graph` / `validate` / `plan`) and the cycle is gone for the right reason.

Output as: a plain-language description of the cycle, the specific edge to cut, the revised blocks, and verification commands.

Never auto-apply. Some cycle fixes change resource addresses or force replacement, so always review the resulting plan with the human before applying.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week