Move a Terraform resource between two separate state files using state mv with the -state and -state-out flags

domain: developer.hashicorp.com/terraform · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Back up both state files first (cp <SOURCE_STATE_PATH> <SOURCE_STATE_PATH>.bak and likewise for the destination), since state mv rewrites state files directly.
  2. Identify the exact resource address in the source state, e.g. terraform state list -state=<SOURCE_STATE_PATH>.
  3. Run terraform state mv -state=<SOURCE_STATE_PATH> -state-out=<DEST_STATE_PATH> <SOURCE_RESOURCE_ADDRESS> <DEST_RESOURCE_ADDRESS>, for example: terraform state mv -state=./project-a/terraform.tfstate -state-out=./project-b/terraform.tfstate aws_vpc.main aws_vpc.main.
  4. Update the destination project's Terraform configuration to include a matching resource block of the same resource type/address so a subsequent plan doesn't try to recreate or destroy it, and remove the corresponding block from the source configuration.
  5. Run terraform plan in both the source (resource block removed) and destination (resource block added) working directories to confirm a zero-diff outcome - no create or destroy actions - before applying anywhere.

Known gotchas

Related routes

Use Terraform moved blocks and the terraform state mv command together to safely refactor a root module that splits into child modules without destroying resources
Terraform · 6 steps · unrated
Manage multi-environment Terraform state with Terragrunt remote_state blocks and path_relative_to_include
terragrunt.gruntwork.io · 6 steps · unrated
Use Terraform removed blocks to drop resources from state without destroying the underlying infrastructure
developer.hashicorp.com/terraform · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans