Rename a resource in state
Change a resource address without destroying it; in newer Terraform, use a moved{} block instead
terraform state mv 'aws_instance.web' 'aws_instance.app'
- tool
- terraform43 commands
More terraform commands
-
terraform state rm 'aws_s3_bucket.legacy'Forget a resource in state without deleting the real infrastructure; the object keeps running
-
terraform state show 'module.vpc.aws_subnet.private[0]'Show all attributes of one address to investigate drift or bugs
-
terraform state list | grep -i 'aws_iam'Filter managed addresses to see what Terraform tracks before any state surgery
-
cat > import.tf <<'EOF' import { to = aws_instance.web id = "<id>" } EOF terraform plan -generate-config-out=generated.tfDeclarative import; -generate-config-out writes the HCL for the imported object
-
cat >> moved.tf <<'EOF' moved { from = aws_instance.web to = aws_instance.app } EOFRename addresses in code without destroy and recreate; the change stays in version control