How do you rename a resource in code, from `aws_instance.web` to `aws_instance.app`, without replacement?
BeginnerScenarioState Backends and Workspaces
Answer
Situation read → A rename without a state change looks like destroy plus create.
What I'd do → Add a moved block next to the renamed resource.
moved {
from = aws_instance.web
to = aws_instance.app
}
Plan should say aws_instance.web has moved to aws_instance.app.
Why → The move is tracked in code, so every environment migrates identically on its next apply.
Interview tip → terraform state mv achieves the same for one state but isn't reviewable.
More on State Backends and Workspaces
Two engineers keep overwriting each other's changes because state is local. What's the fix?BeginnerSet up a production-grade S3 backend. What do you configure for locking?IntermediateHow do you harden the S3 bucket that holds Terraform state?IntermediateWho creates the state bucket itself, given Terraform needs it to exist before `init`?IntermediateA laptop apply and a CI apply start at the same time. What stops state corruption?IntermediateWhen are Terraform workspaces appropriate?Beginner