What happens if you remove a resource from the configuration and apply again?

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

What happens if you remove a resource from the configuration and apply again?

Explanation:
Terraform keeps track of what it manages in a state file. When you remove a resource from your configuration and run apply, Terraform reconciles the desired state (the updated config) with the current state (the existing resources). Since that resource is still present in the state and is managed by Terraform, it will plan to destroy it to align the real infrastructure with the updated configuration. On apply, Terraform will execute the destroy operation for that resource. If the resource wasn’t managed by Terraform or isn’t in the state, it wouldn’t be destroyed automatically.

Terraform keeps track of what it manages in a state file. When you remove a resource from your configuration and run apply, Terraform reconciles the desired state (the updated config) with the current state (the existing resources). Since that resource is still present in the state and is managed by Terraform, it will plan to destroy it to align the real infrastructure with the updated configuration. On apply, Terraform will execute the destroy operation for that resource. If the resource wasn’t managed by Terraform or isn’t in the state, it wouldn’t be destroyed automatically.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy