OpenTofu State Import & Migration Prompt
Bring existing, unmanaged infrastructure under OpenTofu safely using import blocks and generated config, or move resources between state files without recreating them.
- Target user
- Engineers adopting OpenTofu over existing infrastructure
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior OpenTofu engineer who imports live infrastructure into state and relocates resources between state files without ever destroying and recreating them.
I will provide:
- The resources to import (type, cloud IDs) or the resources to move
- The target module/state layout
- Whether config already exists for these resources
Your job:
1. **Choose the mechanism** — decide between declarative `import` blocks (with optional config generation via `tofu plan -generate-config-out`), the imperative `tofu import` command, or `state mv` / a `moved` block for relocating already-managed resources.
2. **Write import blocks** — produce `import { to = ..., id = ... }` entries with sanitized IDs, mapped to the right addresses.
3. **Generate & review config** — describe generating HCL for imported resources, then hand-review it: remove read-only attributes, fix defaults, and confirm the addresses match.
4. **Dry run** — sequence a `tofu plan` that should show import + zero (or minimal, explained) changes. Any proposed replacement is a red flag to stop.
5. **Cross-state moves** — for moving between state files, describe `state mv` with `-state-out`, or pull/push, always backing up both states first under a lock.
6. **Verify** — confirm a clean follow-up plan and that no resource is orphaned in the old state.
7. **Rollback** — describe restoring from the pre-change state backup.
Output as: (a) mechanism decision, (b) import/moved blocks, (c) a plan-review checklist flagging any replace, (d) a rollback procedure.
A plan that proposes to destroy and recreate an imported resource means the address or config is wrong — stop and fix 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
-
OpenTofu moved & removed Block Refactor Prompt
Refactor OpenTofu resource addresses safely using moved and removed blocks so renames and restructures never trigger a destroy-and-recreate.
-
OpenTofu S3 Backend Configuration Prompt
Stand up a secure, locked, versioned S3 backend for OpenTofu state — encryption, native S3 locking, IAM scoping, and state-path layout.
-
OpenTofu Plan Review Prompt
Turn a `tofu plan` into a structured risk review that flags replacements, destroys, and sensitive changes before anyone approves an apply.
-
OpenTofu azurerm Backend Configuration Prompt
Configure a secure OpenTofu state backend on Azure Blob Storage with blob versioning, lease-based locking, and RBAC-scoped access.
More OpenTofu prompts & error guides
Browse every OpenTofu 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.