If you delete the VM via the cloud provider console and run Terraform apply again without changing code, what happens?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

If you delete the VM via the cloud provider console and run Terraform apply again without changing code, what happens?

Explanation:
Terraform uses the state file as the source of truth for what should exist in your cloud. When you delete the VM manually, the real infrastructure drifts away from that state, because the resource is no longer present even though the state still lists it. On the next apply, Terraform detects this drift and plans to bring the actual infrastructure back in line with the state by recreating the missing resource. Since your code hasn’t changed, Terraform will recreate the VM with the same configuration, restoring consistency between the state and the cloud. If you had removed the resource from the state, or tainted it, the behavior could differ.

Terraform uses the state file as the source of truth for what should exist in your cloud. When you delete the VM manually, the real infrastructure drifts away from that state, because the resource is no longer present even though the state still lists it. On the next apply, Terraform detects this drift and plans to bring the actual infrastructure back in line with the state by recreating the missing resource. Since your code hasn’t changed, Terraform will recreate the VM with the same configuration, restoring consistency between the state and the cloud. If you had removed the resource from the state, or tainted it, the behavior could differ.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy