Bitzu

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

Single choice

Which command prints the addresses of every resource tracked in state?

  1. terraform state list
  2. terraform state pull
  3. terraform output
  4. 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.

Select all that apply

Which statements about reading state and outputs are true?

  1. terraform state pull writes the raw state to standard output
  2. terraform output with no name lists root module outputs
  3. Child module outputs appear directly in terraform output
  4. terraform state list prints each resource's attributes
  5. 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.

True or false

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.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module