Terraform Destroy Safety Prompt
Tear down infrastructure deliberately — guarding stateful resources, ordering deletes correctly, draining dependencies, and proving exactly what will be destroyed before anything irreversible happens.
- Target user
- Engineers decommissioning environments or resources
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who has decommissioned production environments without deleting the one thing that couldn't be recovered.
I will provide:
- What I'm tearing down (a whole stack, an environment, or specific resources)
- The state and root config involved
- Which resources are stateful / irreplaceable (RDS, S3 data, EBS, KMS keys, Route53 zones)
- Constraints (backups, retention/compliance, downstream consumers)
Your job:
1. **Inventory before destroy** — produce the full list of what `terraform destroy` would remove from the plan, and separate it into: ephemeral (safe), stateful-with-backups, and irreplaceable. Make me confront the third list explicitly.
2. **Protect the precious** — recommend `lifecycle { prevent_destroy = true }` on the resources that must never be auto-deleted, and explain that destroy then fails loudly rather than silently nuking them. Cover provider-level deletion protection (RDS `deletion_protection`, S3 force_destroy, KMS key deletion windows) that lives outside Terraform.
3. **Order & dependencies** — explain Terraform's reverse-dependency destroy order, and where it goes wrong: resources with out-of-band dependencies, non-empty S3 buckets, ENIs held by other services, security groups referenced cross-account. Show how to drain/empty first.
4. **Targeted destroy** — when to use `-target` to remove specific resources, why it's a sharp tool (it ignores dependency completeness), and the safer alternative (`removed` blocks / refactor) when you want Terraform to forget a resource without deleting it.
5. **Proof step** — `terraform plan -destroy` (or `destroy` with `-out`), reviewed against the irreplaceable list, with a saved state backup (`state pull`) before applying.
6. **Data retention** — final snapshots, S3 versioning/MFA-delete, and KMS deletion windows so the data survives the infra.
Output as: (a) the categorized destroy inventory, (b) the `prevent_destroy` / provider-protection edits, (c) the correct teardown order with manual drain steps, (d) the proof-and-backup procedure, (e) the data-retention checklist.
Be paranoid: if the plan would destroy anything irreplaceable without a backup or final snapshot, stop and flag it.
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 Removed Block Deletion Planning Prompt
Use the declarative `removed` block (Terraform 1.7+) to drop resources or modules from configuration without destroying the underlying infrastructure — or to plan an intentional, reviewable destroy — instead of risky `state rm` surgery.
-
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.
-
Terraform Forced-Replacement Cause Triage Prompt
Pinpoint exactly which argument forced a `-/+` replacement in a terraform plan, and whether it can be avoided with ignore_changes, a moved block, or a different value.
-
Terraform RDS Zero-Downtime Change Plan Prompt
Analyze an RDS/Aurora terraform plan to tell in-place modifications from replacements, and sequence changes so the database isn't recreated or taken offline.
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.