Terraform-Associate-004 practice question 28 of 35

A developer accidentally launched a VM (virtual machine) outside of the Terraform workflow and ended up with two servers with the same name. They don't know which VM Terraform manages but do have a list of all active VM IDs. Which of the following methods could you use to discover which instance Terraform manages?

Full set: 360 questions
Answer options
A: Run terraform state list to find the names of all VMs, then run terraform state show for each of them to find which VM ID Terraform manages Correct answer
B: Update the code to include outputs for the ID of all VMs, then run terraform plan to view the outputs
C: Run terraform taint/code on all the VMs to recreate them
D: Use terraform refresh/code to find out which IDs are already part of state
Correct Answer:
A. Run terraform state list to find the names of all VMs, then run terraform state show for each of them to find which VM ID Terraform manages
Explanation

The most direct and non-destructive method to identify which resource is managed by Terraform is to inspect the state file. The terraform state list command will display the addresses of all resources currently tracked in the state. Using the resource address for the VM, the terraform state show command can then be used to display all the stored attributes for that specific resource, including its unique provider-assigned ID. This ID can then be compared against the list of active VM IDs to determine which one is managed by Terraform.

Why Incorrect

B. terraform plan is used to preview changes that would be made to the infrastructure. It is not the primary tool for inspecting the current state of existing resources.
C. terraform taint is a destructive action that marks a resource to be destroyed and recreated on the next apply. This does not help identify the resource.
D. terraform refresh updates the state file against real infrastructure but is not the ideal command for inspecting the specific attributes of a resource in a user-friendly way.

References

1. HashiCorp Developer - Terraform CLI Documentation, state list command: "The terraform state list command is used to list resources within a Terraform state." This command allows the user to find the resource address needed for the next step.

2. HashiCorp Developer - Terraform CLI Documentation, state show command: "The terraform state show command is used to show the attributes of a single resource in the Terraform state... This command can be useful for inspecting the current state of a resource." This documentation confirms that state show is the correct tool for inspecting resource attributes like an ID.

3. HashiCorp Developer - Terraform CLI Documentation, plan command: "The terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure." This highlights its purpose as a preview tool, not an inspection tool.

4. HashiCorp Developer - Terraform CLI Documentation, taint command: "The terraform taint command manually marks a Terraform-managed resource as tainted, forcing it to be destroyed and recreated on the next apply." This confirms it is a destructive command, unsuitable for this scenario.

Scroll to Top