terraform state rm command removes items from the Terraform state, causing Terraform to “forget” those items without destroying them in the remote system.
Synopsis
Remove instances from the state.Usage
terraform state list.
If you give the address of an entire module, all of the instances in that module and any of its child modules will be removed from the state.
If you give the address of a resource that has count or for_each set, all of the instances of that resource will be removed from the state.
Options
If set, prints out what would’ve been removed but doesn’t actually remove anything.
Path where Terraform should write the backup state.
Don’t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.
Duration to retry a state lock.
Path to the state file to update. Defaults to the current workspace state. Legacy option for the local backend only.
Continue even if remote and local Terraform versions are incompatible. This may result in an unusable workspace, and should be used with extreme caution.
Arguments
One or more resource addresses to remove. Can be resource instances, entire resources, or modules.
Examples
Remove a single resource
Remove a specific resource instance from the state:Remove multiple resources
Remove multiple resource instances at once:Remove a counted resource instance
Remove a specific instance from a resource with count:Remove all instances of a resource
Remove all instances when using count or for_each:Remove an entire module
Remove all resources in a module:Dry run
Preview what would be removed without making changes:Use custom state file
Remove resources from a specific state file:Remove module resource
Remove a specific resource within a module:Common Use Cases
Stop managing resources
When you want Terraform to stop managing a resource without destroying it. This is useful when:- Transferring resource management to another Terraform configuration
- Manually managing a resource going forward
- A resource was created by mistake in Terraform
Clean up orphaned resources
Remove resources from state that have already been manually deleted from the cloud provider.Prevent resource destruction
Before runningterraform destroy, selectively remove critical resources from state to prevent their destruction.
Fix state inconsistencies
Resolve state issues by removing problematic resources, then re-importing them if needed.Import workflow
When re-importing resources with different configurations, first remove the old state entry.Important Notes
- Resources removed from state are not destroyed in the actual infrastructure
- Terraform will no longer track or manage removed resources
- A backup of the state is created before removal
- On the next
terraform plan, removed resources will appear as needing creation unless they’re also removed from your configuration - Use
-dry-runto preview changes before committing to them