TF-Associate-004 - Maintain infrastructure with Terraform (8% of the exam) - Section 7b
Use the CLI to inspect state.
terraform state list and terraform state show read the state without changing it, and terraform show renders current state or a saved plan. Candidates should pick the right read-only command to answer a stated question about what Terraform manages.
terraform state listterraform state showterraform showread-only state inspection
Practice question for this objective
lock_openFree sampleMaintain infrastructure with Terraformmedium
Which statement most accurately describes the effect of the state inspection commands 'terraform state list', 'terraform state show', and 'terraform show' on the state file?
AThey are read-only and leave the recorded state unchanged when they run.check_circle Correct
BThey refresh and overwrite the state with current provider values before displaying it.
CThey remove any resource instances that no longer exist in the provider from the state.
DThey acquire a write lock and modify the serial number of the state on each run.
Understand that CLI state inspection commands read and display state without modifying it. State inspection is deliberately non destructive: listing addresses, showing one instance, and rendering the whole state all operate on the stored data for display only. None of them writes changes, prunes instances, or bumps the state serial, which is why they are safe to run at any time.
Why A is correct: Correct. All three commands only read and display state; they inspect what is recorded without writing back or altering any instance.
Why B is wrong: Tempting because a plan refresh does update state, but these inspection commands display stored data and do not trigger a refresh or rewrite.
Why C is wrong: Pruning missing instances is associated with mutating commands such as 'state rm' or a refresh, not with read-only inspection.
Why D is wrong: Incrementing the serial and taking a write lock happens on operations that persist state; inspection commands do not need to modify the file to display it.
Exam traps in Maintain infrastructure with Terraform
Answers that look right on this material and are not. Each one is a distractor from a different question in the TF-Associate-004 bank for this domain.
terraform show
errorWhy it is wrong: terraform show does read state read-only, but it prints the full human-readable attributes of every resource rather than a bare list of addresses, which is more than was asked for.
It rewrites the state file for the named address, whereas the list command only reads state.
errorWhy it is wrong: Tempting because some state subcommands do mutate state, but 'state show' is read-only; it displays attributes without modifying anything.
terraform state list
errorWhy it is wrong: terraform state list prints only the resource addresses, so it gives an inventory but not the full human-readable attributes the reviewer asked to see.