
terraform state list— show addresses of all resources in stateterraform show— display the full state or render a plan fileterraform state show <address>— display attributes for a single resource
terraform state subcommands (still available but less emphasized):
terraform state mv— move resources in stateterraform state rm— remove resources from stateterraform state pull/terraform state push— manually pull/push state to/from backend
If you are preparing for the HashiCorp Certified: Terraform Associate exam, prioritize
terraform state list, terraform show, and terraform state show. Be aware legacy terraform state operations exist, but the exam focuses on configuration-driven alternatives (like moved and removed blocks).
terraform state list — quick inventory
terraform state list prints every resource address tracked in the current state. It returns only resource addresses (no attributes). Use it when you need the exact address to inspect a resource or to feed into another command.
Example:
terraform show prints a human-readable dump of the entire state by default, including all attributes, computed values, and metadata Terraform tracks. If you pass a binary plan file created by terraform plan -out=planfile, terraform show planfile renders the plan contents instead.
When to use terraform show:
- To review all attributes for resources in state (including computed values not in .tf files)
- To inspect generated IDs and ARNs
- To review a plan file in readable form before applying
terraform state show to target specific resources (below).
terraform state show — focused inspection of a single resource
If you only need details for one resource, terraform state show <address> is the fastest and least noisy option. Typical workflow:
- Run
terraform state listand find the exact address (for exampleaws_vpc.vpc). - Run
terraform state show aws_vpc.vpcto see all attributes for that resource.
terraform state commands and the configuration-driven alternative
Older tooling uses terraform state mv, terraform state rm, and terraform state pull/push to edit state directly. While these commands still work, the modern recommended approach is to capture state transitions in configuration using moved and removed blocks so the changes are version-controlled, reviewable, and plannable.
Mapping (legacy → config-driven):
terraform state mv→ declare amovedblock in configurationterraform state rm→ declare aremovedblock in configurationterraform state pull/terraform state push→ manual state operations only for special cases
Recording state changes in configuration (using
moved and removed blocks) makes them part of your codebase: you get version control, code review, and safer, reviewable plans. This is the recommended modern workflow.- Master
terraform state list,terraform show, andterraform state show. - Understand legacy CLI state operations exist, but know the recommended config-driven alternatives (
moved/removed) and why they are preferred.
- Create a small example (a VPC or single VM).
- Use
terraform state listto locate addresses. - Use
terraform state show <address>andterraform showto inspect attributes and computed values. - Experiment with a
movedblock in configuration to see how Terraform plans and applies state transitions.
- Terraform CLI documentation: https://www.terraform.io/docs/cli/index.html
- Moving and removing resources with configuration: https://www.terraform.io/docs/language/state/renaming-migration.html