What does Terraform do when you run terraform apply after accidentally deleting cloud instances?

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 you run terraform apply after accidentally deleting cloud instances, Terraform operates by reconciling the desired state defined in your configuration files with the current state of your resources in the cloud provider.

The correct answer indicates that Terraform will rebuild only the instances that were deleted. This behavior occurs because Terraform maintains a state file that keeps track of all resources that it manages. When you run the apply command, it compares the current state of those resources (as seen in the state file) with the defined configuration in your Terraform files.

If it detects that certain resources—like cloud instances—are missing in the current state compared to what is defined in the Terraform configuration, it will take action to bring the current state back into alignment with the desired state specified in the configuration. Therefore, only the instances that were deleted are recreated, as Terraform is designed to make the minimum necessary changes to achieve the desired state.

This efficient resource management allows for quick recovery from unintentional deletions without affecting other resources that are still intact.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy