Terraform Associate 004 ยท Maintaining infrastructure
Inspecting state with the CLI
terraform state list, show, terraform show, terraform output, state pull (7b).
Key points
- terraform state list prints the addresses of resources in state. terraform state show <address> prints the recorded attributes of one resource. terraform show renders the whole state or a saved plan in readable form. terraform output prints root module outputs (-json and -raw for scripts). terraform state pull writes the raw state to stdout.
Source: https://developer.hashicorp.com/terraform/cli/commands/state/list
Practice questions
Which command prints the addresses of every resource tracked in state?
- terraform state list
- terraform state pull
- terraform output
- terraform validate
Show answer
Answer: A. terraform state list
state list returns addresses only. state pull dumps the raw state document and output shows output values.
Which statements about reading state and outputs are true?
- terraform state pull writes the raw state to standard output
- terraform output with no name lists root module outputs
- Child module outputs appear directly in terraform output
- terraform state list prints each resource's attributes
- terraform output -json shows sensitive values in plain text
Show answer
Answer: A. terraform state pull writes the raw state to standard output, B. terraform output with no name lists root module outputs, E. terraform output -json shows sensitive values in plain text
Pull goes to stdout, a bare output lists root outputs, and -json reveals sensitive values. Child outputs need a root output that references them, and state list shows addresses only.
Running terraform output db_password on a sensitive output keeps the value hidden as <sensitive>.
Show answer
Answer: False
False. Only the unnamed listing redacts sensitive values; asking for one output by name prints it unredacted.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
