HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 190 of 223

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

HashiCorp Terraform Associate (004) Question 190

Single answer7b Use the CLI to inspect state

Your team stores Terraform state remotely in an S3 backend. After a recent apply, a developer reports that an EC2 instance was created but is not sure which Terraform resource address in state maps to that instance. You need to inspect the current state without modifying infrastructure and view the attributes for a specific tracked resource. Which CLI command should you use?

  1. A

    terraform state show aws_instance.web

  2. B

    terraform show aws_instance.web

  3. C

    terraform state list aws_instance.web

  4. D

    terraform refresh aws_instance.web

Show answer and explanation

Correct answer: A

Explanation

To inspect Terraform state from the CLI, the key commands are terraform state list to enumerate resource addresses and terraform state show <resource_address> to display detailed state attributes for one resource instance. In this scenario, the goal is to inspect a specific tracked object without changing infrastructure, so terraform state show aws_instance.web is the correct choice. terraform show is useful for displaying the full state or a saved plan, but not for targeted lookup by resource address. HashiCorp documentation for the Terraform CLI state subcommands distinguishes these inspection tasks clearly: state list for addresses and state show for detailed resource data.

  • A. Correct.

    Correct. terraform state show <address> displays the attributes of a single resource instance currently tracked in state, using its full resource address. It is intended for state inspection and does not modify infrastructure. This is the right command when you already know or suspect the resource address and want to inspect the stored state data for that object.

  • B. Incorrect.

    Incorrect. terraform show displays a human-readable view of the entire state or a plan file, but it does not accept a resource address argument in this way to inspect one specific state object. A candidate might choose this because terraform show is also used for inspection, but it is not the correct command for targeted resource-level state inspection.

  • C. Incorrect.

    Incorrect. terraform state list is used to list resource addresses in the state, which can help you discover the correct address, but it does not display detailed attributes for a resource. Someone might pick this if they are thinking about identifying resources in state, but the scenario specifically requires viewing the attributes for a tracked resource.

  • D. Incorrect.

    Incorrect. terraform refresh updates the state to match real infrastructure and is not the appropriate command for simply inspecting state. In addition, using it with a resource address in this form is not how state inspection is performed. This option reflects the common misconception that refresh is an inspection command rather than a state reconciliation operation.

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