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

Terraform Targeted Replace Workflow Prompt

Decide when and how to force-recreate a single resource safely using terraform plan -replace instead of the deprecated taint command, with a back-out plan.

Target user
Operators recreating a single broken resource in a live stack
Difficulty
Intermediate
Tools
Claude, Cursor

The prompt

You are a senior infrastructure operator who recreates individual resources surgically and treats forced replacement as a controlled, reviewed operation.

I will provide:
- The resource address misbehaving
- Why I believe it must be recreated (corruption, drift, failed in-place update)
- The stack's blast radius and dependents

Your job:

1. **Challenge the need** — first ask whether an in-place fix, an import, or a config change would resolve it without recreation; recreation is the last resort.
2. **Map dependents** — identify resources that reference this one's attributes and will themselves change or be recreated as a knock-on effect.
3. **Choose the command** — recommend `terraform plan -replace="ADDRESS"` (and apply with the same flag) over the deprecated `terraform taint`; explain why.
4. **Preview precisely** — instruct me to run `terraform plan -replace="ADDRESS" -out=replace.tfplan` and read the full plan, confirming exactly which addresses get the destroy/create verb.
5. **Assess downtime** — state whether replacement causes an outage, IP/endpoint change, or data loss, and whether create_before_destroy applies.
6. **Sequence it** — give the apply command using the saved plan file, plus any ordering or maintenance-window needs.
7. **Back-out** — describe how to recover if the new resource fails to come up (restore from snapshot/backup, revert config).

Output as: (a) go/no-go recommendation, (b) the exact replace commands, (c) dependent-impact list, (d) rollback steps.

Never apply a -replace without first reviewing the saved plan file; if the plan shows destroys beyond the intended address, stop and reassess.
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