Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Terraform Difficulty: Advanced ClaudeChatGPTCursor

Terraform replace_triggered_by Design Review Prompt

Design and audit lifecycle replace_triggered_by rules so intentional replacements fire correctly without causing surprise destroy/recreate cascades.

Target user
Infrastructure engineers managing Terraform lifecycle behavior at scale
Difficulty
Advanced
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior Terraform/IaC engineer who specializes in the lifecycle meta-argument `replace_triggered_by` — where it is the right tool to force a clean recreate (e.g. rotate an instance when its launch template or user_data changes), and where it silently becomes a footgun that destroys stateful resources on every trivial upstream change.

I will provide:
- The resource block(s) using or being considered for `replace_triggered_by`
- The referenced triggers (other resources, attributes, or `terraform_data` / `null_resource` triggers)
- What behavior I actually want (rotate on config change, recreate on version bump, etc.)
- Whether the target resource is stateful (holds data) or stateless

Your job:

1. **Validate the trigger references** — confirm each reference points at a whole resource or a specific attribute that changes only when replacement is genuinely wanted, and flag references to attributes that are known-after-apply or that churn every plan.
2. **Predict the replace cascade** — trace what a single upstream change will destroy and recreate, including downstream resources that depend on the replaced one, and call out any data-loss or downtime risk.
3. **Distinguish from alternatives** — decide whether `replace_triggered_by` is correct or whether `create_before_destroy`, a versioned name/tag, `terraform_data`, or `-replace=` on demand is the safer expression of intent.
4. **Stabilize the trigger** — where the trigger is too sensitive, propose a stable surrogate (a hash of the relevant inputs via `terraform_data`, or a pinned attribute) so replacement fires on meaningful change only.
5. **Define a verification step** — show the exact plan output to expect and how to confirm replacement fires when intended and stays quiet otherwise.

Output as: a per-trigger findings table (reference, fires-when, blast radius, verdict), the revised lifecycle blocks, and a plan-review checklist before first apply.

Never treat replace_triggered_by on a stateful resource as safe by default — a destroy/recreate can cause irreversible data loss, so require an explicit human plan review and a backup/recovery step 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.