What is the purpose of the `terraform state list` command?
This command directly queries the active Terraform state, which serves as the authoritative record of the infrastructure Terraform is managing. It meticulously enumerates every resource instance, module, and data source address stored within that state file, providing a precise inventory of the deployed components. This output is crucial for understanding the current managed infrastructure without needing to interact with the cloud provider APIs directly.
Why this answer
`terraform state list` lists all resources currently tracked in the Terraform state file, providing their resource addresses. Option B correctly describes this. Option A is incorrect because `terraform state list` does not show planned resources; that is the role of `terraform plan`.
Option C lists resources from configuration (not from state), D lists workspaces, and E lists providers.
Exam trap
The Terraform exam often tests the distinction between state-based commands and configuration-based commands, so the trap here is confusing `terraform state list` (which reads the state file) with `terraform show` or `terraform plan` (which read the configuration or generate a plan).
How to eliminate wrong answers
Option A is wrong because it is identical to the correct answer (B) and is listed as a duplicate; the question expects B as the correct choice. Option C is wrong because `terraform state list` lists resources from the state file, not from the Terraform configuration; resources defined in configuration but not yet applied will not appear. Option D is wrong because listing workspaces is done with `terraform workspace list`, not `terraform state list`.
Option E is wrong because listing providers is done with `terraform providers` or by inspecting the configuration, not with `terraform state list`.