HashiCorp Certified: Terraform Associate — Question 340
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, and 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. Nothing
- B. Terraform will destroy the virtual machine
- C. Terraform will error
- D. Terraform will remove the virtual machine from the state file, but the resource will still exist
Correct answer: B
Explanation
When you remove the resource definition from the Terraform configuration and run terraform apply again, Terraform will recognize that the resource no longer exists in the configuration and will proceed to destroy it. The other options are incorrect because 'Nothing' would imply the resource still exists in some form, 'error' would indicate a problem, and 'removal from the state file' suggests the resource would still be active, which it won't be.