Inspecting State with the CLI
Terraform provides several commands for looking at what it manages. This lesson covers listing and showing state, displaying plans and outputs, and the commands that change state directly.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the commands that inspect state, plans and outputs.
- Describe the state commands that change state directly.
Listing and showing resources
terraform state list prints the address of every resource instance in state, one per line, including data sources and resources inside modules. An address prefix filters the list, and -id finds the address that manages a given object.
$ terraform state list
data.aws_ami.ubuntu
aws_instance.web[0]
aws_instance.web[1]
module.network.aws_subnet.public["a"]
module.network.aws_vpc.this
$ terraform state list module.network
$ terraform state list -id=i-0abc1234def567890
$ terraform state show 'aws_instance.web[0]'terraform state show ADDRESS prints every attribute of one instance in an HCL-like format, with sensitive values redacted. Both commands read the latest state snapshot; they do not refresh from the real infrastructure, so the values are as of the last plan or apply that wrote state.
The following diagram shows the two state commands and their output.

terraform show and terraform output
terraform show displays the whole current state in human-readable form, or, given a plan file, the saved plan. With -json, it produces a machine-readable document that policy tools, cost tools and scripts consume. JSON output includes sensitive values in plain text.
terraform output displays root module outputs from state. The following table compares the inspection commands.
| Command | Shows |
|---|---|
| terraform state list | Addresses of all resource instances |
| terraform state show ADDRESS | All attributes of one instance |
| terraform show | The whole state, or a saved plan with a file argument |
| terraform show -json | State or plan as JSON, including sensitive values |
| terraform output [NAME] | Root outputs; -raw and -json for scripts |
| terraform providers | The providers each module requires |
| terraform graph | The dependency graph in DOT format |
Inspection commands
Commands that change state
The remaining terraform state subcommands modify or transfer state directly. They lock state, write a backup and should be used carefully.
terraform state mv SOURCE DESTINATIONchanges an object's address, for example after a rename; amovedblock is the reviewable alternative.terraform state rm ADDRESSremoves an object from state without destroying it; aremovedblock withdestroy = falseis the reviewable alternative.terraform state replace-provider OLD NEWchanges the provider source recorded for resources, for example when a provider moves to a new namespace.terraform state pullprints the raw state from the backend, andterraform state push FILEoverwrites remote state with a local file, which is dangerous and protected by lineage and serial checks.
State-changing commands
Finding a resource
An auditor asks which Terraform resource manages EC2 instance i-0abc1234def567890 and what its tags are. The configuration has dozens of modules.
The decisive need is to search state by object ID.
terraform state list -id=i-0abc1234def567890 prints the address, for example module.app.aws_instance.web[1], and terraform state show 'module.app.aws_instance.web[1]' prints its attributes, including tags. Because state show does not refresh, a terraform plan -refresh-only first confirms that the recorded tags still match reality.
Does terraform state show refresh the resource before displaying it?
Show answer
No. It shows the attributes recorded in the latest state snapshot.
Exam Tips
Remember for the exam
- state list for addresses (-id to search); state show for one instance.
- state list and state show do not refresh.
- show -json and state pull reveal sensitive values.
- state mv/rm change state immediately; prefer moved/removed blocks.