TA-002-P · Question #406
A junior admin accidentally deleted some of your cloud instances. What does Terraform do when you run terraform apply?
The correct answer is C. Rebuild only the instances that were deleted. Terraform reconciles the desired state in configuration files against the current state file; if resources are missing from the real infrastructure, it recreates only those missing resources.
Question
A junior admin accidentally deleted some of your cloud instances. What does Terraform do when you run terraform apply?
Options
- ABuild a completely brand new set of infrastructure
- BTear down the entire workspace infrastructure and rebuild it
- CRebuild only the instances that were deleted
- DStop and generate an error message about the missing instances
How the community answered
(49 responses)- B4% (2)
- C94% (46)
- D2% (1)
Why each option
Terraform reconciles the desired state in configuration files against the current state file; if resources are missing from the real infrastructure, it recreates only those missing resources.
Terraform does not build brand-new infrastructure; it only acts on the delta between desired and actual state.
Terraform does not tear down and rebuild the entire workspace; it targets only resources that differ from the desired state.
When terraform apply runs, it compares the state file (which still records the deleted instances) against the live infrastructure. Because the instances are absent from the actual cloud environment but present in state, Terraform creates a plan to recreate only those specific resources, leaving everything else untouched.
Terraform does not stop with an error for missing resources; detecting and correcting drift is a core function of the tool.
Concept tested: Terraform drift detection and reconciliation on apply
Source: https://developer.hashicorp.com/terraform/intro/use-cases#resource-drift
Topics
Community Discussion
No community discussion yet for this question.