What is Terraform state?
Terraform stores a state file that serves as the authoritative record of resources Terraform manages. This file contains the mapping between resource addresses in your configuration and the actual provider-managed resources (IDs, computed attributes, metadata). Terraform relies on state to plan changes and detect drift.Inspecting state
Use theterraform state family of commands to inspect and manage the state. To see all tracked resources:
state show output includes both configuration-declared attributes and provider-populated fields (IDs, defaults, and runtime properties). This detailed view is essential for debugging, auditing, and preparing precise state changes.
State management subcommands
Theterraform state command exposes subcommands for advanced state maintenance. Terraform automatically creates a timestamped backup of state before any operation that modifies it. Below is a concise reference:
The commands are intentionally simple and script-friendly (work well with grep, awk, etc.) for advanced automation and auditing.
State modification commands can cause drift between Terraform and your real infrastructure if used incorrectly. Always work against a backup and prefer non-destructive commands unless you fully understand the implications.
Refreshing state

terraform refresh to reconcile Terraform’s state with the provider by re-querying resource attributes and updating the state file. Important: terraform refresh updates only the state file; it does not change infrastructure.
Example configuration using a variable for the storage account name:
Modern Terraform performs an automatic refresh during operations like
terraform plan and terraform apply, so manually running terraform refresh is less common. Still, it’s valuable when resolving drift or preparing for direct state edits.Key takeaways
- The Terraform state file is the authoritative record of managed infrastructure.
- Inspect state with
terraform state listandterraform state show. - Use
terraform statesubcommands for advanced maintenance — Terraform creates backups automatically for safety. - Run
terraform refreshto update the state from provider data; it updates only the state file and does not alter resources. - Be cautious with state-modifying commands; test on non-production state or use backups to recover if needed.