tofu state subcommands to list, inspect, rename, pull, remove, and push resources safely.
Viewing Resource Attributes with state show
To inspect resource attributes in the state file:
Listing Resources with state list
Show all resource addresses in your state:
Renaming Resources with state mv
Rename a resource address in your state file (or move it between state files).
-
Initial Terraform configuration (
main.tf): -
Existing state snapshot:
-
Rename in state:
-
Update configuration:
-
Verify no pending changes:
Downloading Remote State with state pull
Fetch and view your remote state locally:
Removing Resources from State with state rm
When you need Terraform/OpenTofu to stop managing a resource—but keep it running in the cloud—use:
state rm only removes the resource from the Terraform/OpenTofu state—it does not delete the actual resource in your cloud provider.resource block in your configuration.
Overwriting Remote State with state push
Use this command to replace the remote state with a local file. OpenTofu will refuse if the lineages don’t match:
Forcing a push can irreversibly corrupt your remote state. Always back up your existing state before using
--force.