What occurs if a VM created by Terraform is deleted via the cloud provider console and terraform apply is executed again?

Prepare for your Terraform Associate Exam with our engaging quiz. Test your knowledge with multiple choice questions and receive detailed explanations to enhance your understanding. Ace your exam with confidence!

When a VM created by Terraform is deleted directly through the cloud provider's console and then a terraform apply command is executed again, Terraform will indeed recreate the VM. This occurs because Terraform maintains a state file that keeps track of all the resources it manages. When the VM is deleted outside of Terraform, the state file no longer reflects the actual state of the infrastructure.

During the next execution of terraform apply, Terraform compares the current state (as noted in the state file) with the desired configuration defined in the Terraform code. Since the VM no longer exists in the actual environment but is still present in the state file, Terraform recognizes that there is a discrepancy. To reconcile this difference and ensure that the infrastructure matches the defined configuration, Terraform will proceed to recreate the VM as specified in the configuration files.

This automatic reconciliation process is one of the core functionalities of Terraform and underscores its purpose of managing infrastructure lifecycle efficiently.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy