nerdexam
HashiCorp

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.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

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)
  • B
    4% (2)
  • C
    94% (46)
  • D
    2% (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.

ABuild a completely brand new set of infrastructure

Terraform does not build brand-new infrastructure; it only acts on the delta between desired and actual state.

BTear down the entire workspace infrastructure and rebuild it

Terraform does not tear down and rebuild the entire workspace; it targets only resources that differ from the desired state.

CRebuild only the instances that were deletedCorrect

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.

DStop and generate an error message about the missing instances

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

#Terraform apply#State management#Drift detection#Resource reconciliation

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice