HashiCorp Certified: Terraform Associate (003) — Question 6
You have a Terraform configuration that defines a single virtual machine with no references to it. You have run terraform apply to create the resource, then removed the resource definition from your Terraform configuration file.
What will happen when you run terraform apply in the working directory again?
Answer options
- A. Terraform will destroy the virtual machine.
- B. Terraform will remove the virtual machine from the state file, but the resource will still exist.
- C. Terraform will error.
- D. Nothing.
Correct answer: A
Explanation
The correct answer is A because when the resource definition is removed and terraform apply is executed, Terraform identifies that the resource is no longer defined and proceeds to destroy it. Option B is incorrect because while Terraform does update the state, it does not leave the resource intact; option C is wrong as Terraform handles this scenario without error; and option D is incorrect since the removal of the resource definition triggers a destroy action.