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.
More on Import Refactoring Drift and Lifecycle
An S3 bucket was created by hand in the console and now must be managed by Terraform. How do you bring it in?BeginnerYou must adopt 200 existing resources and don't want to write all the HCL by hand.IntermediateHow do you find out that someone changed infrastructure outside Terraform?BeginnerSomeone opened port 22 on a security group in the console. Terraform wants to remove it. What's your process?IntermediateAn Auto Scaling group's desired capacity is changed by autoscaling, and Terraform keeps resetting it.IntermediateHow do you protect a production database from an accidental `terraform destroy`?Beginner