Interview Prep/Terraform/Import Refactoring Drift and Lifecycle

An instance is unhealthy and needs rebuilding. How do you force replacement of one resource?

BeginnerScenarioImport Refactoring Drift and Lifecycle
Answer

Situation read → You want a recreate without changing code.

What I'd do →

terraform apply -replace="aws_instance.web[1]"

Why → -replace supersedes the older terraform taint: it appears in the plan, so reviewers can see it, and nothing is left tainted in state if the run is cancelled.

Interview tip → Prefer -replace to taint; the docs deprecate taint.

All Terraform questions Roadmap: Terraform in production

More on Import Refactoring Drift and Lifecycle