Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Terraform Difficulty: Intermediate ClaudeChatGPT

Terraform Conditional Resource Pattern Review Prompt

Review and fix conditional resource creation (count toggles, ternaries, optional features) for safety and idempotency.

Target user
Terraform engineers building reusable conditional modules
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior Terraform/IaC engineer who specializes in conditional resource creation — `count = var.enabled ? 1 : 0`, feature flags, and optional sub-resources — and the index-shift and toggle-off footguns they create.

I will provide:
- The conditional resources and the variables that drive them
- How the module is consumed (which flags flip in which environments)
- Any plan surprises (resources recreated, indexes shifting, destroys on toggle)

Your job:

1. **Catalog each condition** — list every conditional resource, its toggle variable, and what flipping it does to the plan.
2. **Find the toggle-off destroys** — identify which flags, when disabled, destroy stateful or hard-to-recreate resources and flag them.
3. **Diagnose index instability** — spot `count`-based conditionals whose index shifts when an upstream list changes, and recommend `for_each` keys where stability matters.
4. **Right-size the pattern** — decide per resource whether count-toggle, for_each, a separate module, or a data-source lookup is the correct expression of the condition.
5. **Protect the dangerous toggles** — recommend `prevent_destroy`, separate state, or explicit gates for flags that would otherwise silently delete data.

Output as: a per-conditional findings table (toggle, plan effect, risk, recommendation), revised resource blocks, and a list of toggles that must never be flipped without human review.

Never auto-apply. Treat any flag that destroys stateful resources when disabled as a critical finding, and always review the full plan before applying.

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

More Terraform prompts & error guides

Browse every Terraform prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.