Skip to main content
TERRAFORM-BASICS5 MIN READ

Refactor Without Recreating

Use moved-block thinking to preserve resource identity during a Terraform refactor.

A readability rename changes a Terraform address and causes a destroy/create plan. Preserve state identity by explicitly moving the old address to the new address. The common shortcut is to treat a resource block rename like a normal variable rename. Terraform state makes it more consequential. Before aws_security_group.sg removed and aws_security_group.web added; plan proposes replacement. After State records the address move; plan preserves the same remote security group. Capture old address aws_security_group.sg The old state address is what Terraform currently manages. Choose new address aws_security_group.web The new address should be stable and meaningful. Verify the plan Plan should show a…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us