HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 193 of 223

Terraform Associate 004. Associate level, HashiCorp. Free question with the correct answer and a full explanation.

HashiCorp Terraform Associate (004) Question 193

Single answer7b Use the CLI to inspect state

Your team stores Terraform state remotely in an S3 backend. After a recent apply, an engineer reports that the EC2 instance in the production workspace has the wrong instance type. You want to inspect the current Terraform state from the CLI to confirm the exact attributes Terraform has recorded for that specific resource, without modifying infrastructure or editing the state. Which command should you run?

  1. A

    terraform state list

  2. B

    terraform show

  3. C

    terraform state show aws_instance.web

  4. D

    terraform output aws_instance.web

Show answer and explanation

Correct answer: C

Explanation

To inspect Terraform state from the CLI for a specific resource, the most precise command is terraform state show <resource_address>. This is commonly used when troubleshooting drift, validating what Terraform believes exists, or comparing recorded attributes against real infrastructure. terraform state list helps you discover resource addresses, while terraform show provides a broader view of the state or plan, but terraform state show is the best fit for focused inspection of one resource. According to Terraform CLI documentation, the terraform state subcommands are intended for advanced state inspection and management, and state show specifically prints the attributes of a single resource instance from the state.

  • A. Incorrect.

    Incorrect. terraform state list only lists the addresses of resources tracked in state, such as aws_instance.web, but it does not display the resource's stored attribute values like instance_type. A candidate might choose this because it is part of the terraform state subcommands used for inspection, but it is insufficient when you need detailed resource data.

  • B. Incorrect.

    Incorrect. terraform show displays a human-readable representation of the current state or a plan file, and it can be useful for broad inspection. However, in this scenario you need to confirm the exact recorded attributes for one specific resource address directly from state. terraform state show aws_instance.web is the more targeted and appropriate command for that task.

  • C. Correct.

    Correct. terraform state show aws_instance.web displays the attributes Terraform currently has recorded in state for the resource at that address. This is the right CLI command when you need to inspect one resource's state data without changing infrastructure. It works with remote backends as well; Terraform reads the current state and shows the stored attributes for that resource.

  • D. Incorrect.

    Incorrect. terraform output is used to display root module output values, not arbitrary resource attributes from state. Unless the configuration explicitly defines an output that exposes the instance type, this command cannot inspect aws_instance.web directly. This distractor reflects a common misunderstanding between outputs and state inspection.

Timed practice exam

Take a HashiCorp Terraform Associate (004) practice test under exam conditions

70 questions in 60 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam