What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Terraform state operations do different jobs: state rm forgets an object without destroying it, a move changes its Terraform address, a cross-state migration changes which state file manages it, and a backend migration changes where state is stored. Choose based on whether the infrastructure should remain, whether the state file changes, and whether the configuration should record the transition.
Choose the operation that matches your goal
| Goal | Recommended approach | Does it destroy infrastructure? | Does the resource stay in the same state file? | Version and main caution |
|---|---|---|---|---|
| Stop managing an object but leave it running | removed block with lifecycle { destroy = false } |
No | Yes; its management binding is removed from that state | Terraform 1.7 or newer; remove configuration references and review the plan |
| Immediately forget an object in state | terraform state rm ADDRESS |
No | Yes | Preview matching addresses; a later plan may propose creating a replacement |
| Rename or relocate a resource address | moved block or another configuration refactoring feature |
No, when Terraform recognizes the move | Yes | Keep the move history clear, especially for module users |
| Directly change an address in state | terraform state mv SOURCE DESTINATION |
No, when used as intended | Yes | Source and destination must be compatible objects; coordinate the change |
| Transfer a resource to another state file | removed and import blocks |
No, if the migration is configured correctly | No | Terraform 1.7 or newer for this workflow; confirm exclusive ownership and inspect both plans |
| Move state storage to another backend | Update backend configuration, then run terraform init -migrate-state |
No | Yes; the state is copied to different storage | Back up first and verify workspace prompts and mappings |
Remove Terraform management without destroying the object
If the infrastructure should continue to exist but Terraform should stop managing it, use a removed block with lifecycle { destroy = false } when possible. Terraform 1.7 introduced removed blocks. The configuration change can be reviewed through the usual plan and apply workflow; remove any configuration references to the resource’s attributes as needed. HashiCorp describes this reviewable approach as safer than directly editing state (resource removal documentation).
As an Amazon Associate I earn from qualifying purchases.
removed {
from = aws_instance.example
lifecycle {
destroy = false
}
}
Use terraform state rm ADDRESS when an immediate state edit is appropriate. It removes matching instance addresses from Terraform’s state; it does not delete the remote objects. Use -dry-run to see which addresses match before making the change, and leave state locking enabled unless there is a specific, understood reason to disable it (state rm command reference).
After Terraform forgets an object, a later plan may propose creating it again if the configuration still declares it. That can fail if the proposed replacement conflicts with the existing object’s name or identifier. Removing management is not the same as destroying the infrastructure; if destruction is intended, use the normal Terraform resource-destruction workflow instead.
#1 Best Overall
Rename or relocate an address within one state
A resource address changes when, for example, a resource block is renamed, moved into or out of a child module, or its instance structure changes. Without a declaration that connects the old and new addresses, Terraform can interpret the configuration change as one resource disappearing and another appearing, and propose deletion and creation.
Prefer a configuration-recorded move
For a refactor, use a moved block where supported. It records the relationship in configuration so Terraform can associate the existing object with its new address during planning. This is generally preferable for a change that should remain understandable to collaborators and users of a module (refactoring modules documentation).
Rank #2
Use state mv for a direct state edit
terraform state mv SOURCE DESTINATION directly changes an address in state. The source and destination must be the same kind of object, and a resource can move only to another address of the same resource type. Quote addresses containing bracketed count indices or for_each keys as required by your shell. Coordinate the configuration change and state operation so another run does not treat the transition as a destroy-and-create change (state mv command reference).
Transfer a resource between state files
A cross-state migration changes which state file is responsible for an object. First decide whether the object can reasonably be recreated: HashiCorp recommends recreating stateless resources when downtime and cost allow, while stateful databases and object stores may require a controlled transfer because deletion and recreation, or backup and restore, can be difficult (state move tutorial).
Rank #3
Use removed and import blocks for a new migration
For a new migration, HashiCorp recommends recording the handoff in configuration with removed and import blocks. These blocks are available for this workflow from Terraform 1.7 onward. Configure the source state to relinquish management without destroying the object, and the destination configuration to import it. Plan each side and confirm the object is managed by only one state before applying the changes.
Understand the legacy state mv route
Directly moving an object between state files with terraform state mv is a legacy alternative; the command supports this from Terraform 1.0 onward. For remote source and destination workspaces, HashiCorp’s documented procedure is to pull each state to a local file, move the resource between files with -state and -state-out, then push both updated files back. Back up both states and coordinate a freeze so concurrent Terraform runs cannot manage the object during the handoff. HashiCorp warns that manually updating remote state carries corruption risk and recommends the newer block workflow for new migrations (state move tutorial).
State commands are advanced operations. Treat direct state editing as a last resort, preserve backups, and check the resulting plans before proceeding (state commands overview).
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteMove state to a remote backend
A backend migration changes the storage location for state; it does not, by itself, transfer resource ownership to a different state file. Backend configuration belongs in Terraform configuration. After changing that configuration, initialize Terraform again before planning, applying, or running state commands.
- Back up the current state. HashiCorp says: “Before migrating to a new backend, we strongly recommend manually backing up your state by copying your terraform.tfstate file to another location.” (backend configuration documentation)
- Update the backend configuration in the Terraform configuration to specify the destination backend, following that backend’s current documentation.
- Run
terraform init -migrate-state. Terraform attempts to copy existing state to the new backend and may ask you to confirm migration of workspace states. - Review workspace prompts and mappings. Confirm that each source workspace will land in the intended destination before accepting the migration.
- Inspect the resulting state and plan before making follow-on infrastructure changes.
-force-copy automatically enables migration and answers yes to migration prompts. Use it only when you intend to skip interactive confirmation and have already checked the destination and workspace mapping. Do not use -reconfigure as a migration flag: it disregards the existing backend configuration and prevents state migration (terraform init command reference).
Protect credentials, locking, and collaboration
.terraform/stores the most recent backend configuration, including authentication parameters supplied to the CLI. Do not commit this directory because it may contain sensitive credentials (backend configuration documentation).- Preserve state locking where the backend supports it, and coordinate migration timing with collaborators so concurrent runs do not write state during the transition.
- Terraform state CLI commands can work with remote state, but each read and write requires a network round trip. Modifying commands also write backup files, which cannot be disabled (state command documentation).
- State is sensitive operational data. Store backups securely and verify that access controls for the destination backend are appropriate.
Migrate existing state to HCP Terraform
For existing local or state-backend data, the HCP Terraform CLI integration prompts during terraform init to migrate state to HCP workspaces and may also prompt to rename workspaces. Terraform CLI workspaces can represent environments that share configuration; HCP workspaces represent independent configurations and require unique names within an organization. If the directory already uses the HCP remote backend, HashiCorp documents replacing that backend block with a cloud block to continue using the same HCP workspaces (HCP Terraform migration documentation).
Do not treat tf-migrate as a universal migration tool: HashiCorp marks it deprecated and unsupported. Its documented source-backend coverage excludes existing cloud integration and remote backend sources (tf-migrate documentation).
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




