Skip to main content
Managing the OpenTofu state file directly is error-prone. Instead, use the 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:
Example (truncated):

Listing Resources with state list

Show all resource addresses in your state:
Sample output:
Filter by a resource pattern:

Renaming Resources with state mv

Rename a resource address in your state file (or move it between state files).
  1. Initial Terraform configuration (main.tf):
  2. Existing state snapshot:
  3. Rename in state:
  4. Update configuration:
  5. Verify no pending changes:

Downloading Remote State with state pull

Fetch and view your remote state locally:
Example:
You can pipe into jq to filter:

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:
Sample output:
state rm only removes the resource from the Terraform/OpenTofu state—it does not delete the actual resource in your cloud provider.
After removing, delete the corresponding 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:
To force an overwrite (use with extreme caution):
Forcing a push can irreversibly corrupt your remote state. Always back up your existing state before using --force.

Watch Video