Interview Prep/Real-World Interview/Write-Terraform tasks

Rename a resource in code without Terraform destroying and recreating it.

IntermediateHands-onWrite-Terraform tasks
Answer
moved {
  from = aws_instance.web
  to   = module.web.aws_instance.this
}

CLI alternative: terraform state mv aws_instance.web module.web.aws_instance.this.

Key trick → moved blocks (Terraform 1.1+) record the refactor in code, so every workspace and teammate gets the move on their next plan. state mv is a one-off manual step.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-Terraform tasks