Terraform Remote Backend Migration Prompt
Move Terraform state from one backend to another (local → S3, S3 → Terraform Cloud, or cross-account/region) with locking intact, zero state loss, and a tested rollback at every step.
- Target user
- Platform engineers consolidating or relocating Terraform state
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who has migrated Terraform backends for production estates without ever losing or corrupting state. I will provide: - The current backend config and the target backend - Whether locking exists today (DynamoDB table, TFC, none) - How many stacks/workspaces share or will share the new backend - Constraints (cross-account, KMS, compliance, who can touch state) Your job: 1. **Pre-flight** — before touching anything: `terraform state pull > backup.tfstate`, record the current serial/lineage, confirm a clean `plan` (no pending diffs), and confirm everyone has stopped applying. Migrating with a dirty plan is how state gets clobbered. 2. **Target backend design** — for S3: versioning ON, default encryption (KMS), block public access, a DynamoDB lock table, and least-privilege IAM split between read (plan) and write (apply). Call out the bootstrap chicken-and-egg (the backend bucket can't store its own state cleanly — keep a tiny bootstrap stack or use `prevent_destroy`). 3. **The migration** — change the `backend` block, run `terraform init -migrate-state`, and verify the prompt's source→destination summary before answering yes. Show what `-reconfigure` does instead and when each is correct. 4. **Verify** — after migration, `terraform state pull` from the new backend, diff `lineage`/`serial` against the backup, run `terraform plan` and confirm it's empty. A non-empty plan post-migration means something moved or was lost — stop. 5. **Locking & concurrency** — prove the lock works (start a plan, attempt a second, confirm it blocks). Explain `force-unlock` and when it's dangerous. 6. **Cutover** — how to coordinate so no one applies against the old backend after migration; decommission the old state only after a retention window. Output as: (a) ordered runbook with exact commands, (b) the target backend Terraform + IAM, (c) verification checks with pass/fail criteria, (d) a rollback procedure using the pulled backup, (e) the team-coordination/freeze plan. Be conservative: every step must be reversible, and "the plan is empty afterward" is the only acceptable success signal.
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 State Backend Design Prompt
Design Terraform state backend — S3+DynamoDB, GCS, Azure Blob, encryption, locking, versioning, cross-account access.
-
Terraform Cross-State Resource Migration Prompt
Plan and execute moving resources between two separate Terraform state files — splitting a monolith state or consolidating stacks — using `terraform state mv -state-out` (or `removed`+`import`) safely, with locking, backups, and a verified zero-diff outcome.
-
Terraform Cross-Account Resource Migration Prompt
Plan moving Terraform-managed resources between cloud accounts or subscriptions without destroy/recreate or data loss.
-
Terraform State Disaster Recovery & Rebuild Prompt
Recover from a lost, corrupted, or diverged Terraform state file — rebuild state via bulk import, reconcile against live infrastructure, and harden the backend so it never happens again.
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.