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 questionsThe 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.
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.
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.
Keep practicing
Take the free Terraform-Associate-004 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Terraform-Associate-004 practice questions
- Question 1You should run terraform fnt to rewrite all Terraform configurations within the current w…
- Question 2Module variable assignments are inherited from the parent module and you do not need to e…
- Question 3terraform validate confirms thesyntaxof Terraform files.
- Question 4Using the terraform state rm command against a resource will destroy it.
- Question 5Variables declared within a module are accessible outside of the module.
- Question 6terraform init retrieves and caches the configuration for all remote modules.
