If a Terraform run creates a VM in a shared cloud account and the state contains only that VM, what is the correct way to delete it with Terraform?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

If a Terraform run creates a VM in a shared cloud account and the state contains only that VM, what is the correct way to delete it with Terraform?

Explanation:
The test is about using Terraform’s state as the source of truth and how to remove resources that Terraform manages. When you want to delete a resource, you should rely on Terraform to perform the deletion based on what’s in its state. If the state contains only that one VM, running terraform destroy will target and remove exactly that VM, leaving nothing else to manage. This keeps Terraform in control of the lifecycle and ensures the state stays consistent with real resources. Deleting the state file would break Terraform’s ability to manage anything, and running apply afterward would either fail or attempt to recreate resources because Terraform wouldn’t know what to destroy. Removing the VM via the cloud console creates drift between the real world and Terraform’s state. A subsequent terraform apply would typically plan to recreate the VM to match the state, not reflect the removal. The proper approach is to let Terraform destroy handle the deletion so the state remains accurate.

The test is about using Terraform’s state as the source of truth and how to remove resources that Terraform manages. When you want to delete a resource, you should rely on Terraform to perform the deletion based on what’s in its state. If the state contains only that one VM, running terraform destroy will target and remove exactly that VM, leaving nothing else to manage. This keeps Terraform in control of the lifecycle and ensures the state stays consistent with real resources.

Deleting the state file would break Terraform’s ability to manage anything, and running apply afterward would either fail or attempt to recreate resources because Terraform wouldn’t know what to destroy.

Removing the VM via the cloud console creates drift between the real world and Terraform’s state. A subsequent terraform apply would typically plan to recreate the VM to match the state, not reflect the removal. The proper approach is to let Terraform destroy handle the deletion so the state remains accurate.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy