Move resource in state

Rename/refactor address without destroy; prefer moved{} block in newer TF

terraform state mv 'aws_instance.web' 'aws_instance.app'

tool
terraform43 commands
tags
terraformgitopstroubleshooting

More terraform commands

  • terraform state rm 'aws_s3_bucket.legacy'

    Forget resource from state without deleting real infra; note: object keeps existing

  • terraform state show 'module.vpc.aws_subnet.private[0]'

    Dump all attributes of one resolved address for drift/debug investigation

  • terraform state list | grep -i 'aws_iam'

    Filter managed addresses to find what TF tracks before surgery

  • cat > import.tf <<'EOF' import { to = aws_instance.web id = "<id>" } EOF terraform plan -generate-config-out=generated.tf

    Declarative import; -generate-config-out scaffolds HCL for the imported object

  • cat >> moved.tf <<'EOF' moved { from = aws_instance.web to = aws_instance.app } EOF

    Rename addresses in code with no destroy/recreate; survives in version control

all 43 terraform commands