Interview Prep/Terraform/State Backends and Workspaces

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.

All Terraform questions Roadmap: Terraform in production

More on State Backends and Workspaces