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
-
Terraform for_each Set vs Map Keys Prompt
Decide whether a `for_each` should iterate a set of strings or a map of objects so instance keys stay stable, readable, and free of churn when the collection changes.
-
Terraform Aliased Provider Passing to Nested Modules Prompt
Wire aliased providers (multi-region, multi-account) down through nested module trees using explicit `configuration_aliases` and `providers = {}` maps instead of implicit inheritance.
-
Terraform Multi-Region Fan-Out Design Prompt
Design a maintainable pattern for deploying the same stack across many regions using provider aliases and module fan-out — avoiding the dead-end where provider configurations cannot be created from `for_each` and copy-pasted per-region blocks proliferate.
-
Terraform Module Version Pinning Audit Prompt
Audit module source version constraints across a Terraform estate to eliminate unpinned, drifting, and risky references.
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.