Move resource in state terraform
Rename/refactor address without destroy; prefer moved{} block in newer TF
terraform state mv 'aws_instance.web' 'aws_instance.app'
more terraform
all 43 commands →
Remove orphan from state
terraform state rm 'aws_s3_bucket.legacy'
Inspect single resource state
terraform state show 'module.vpc.aws_subnet.private[0]'
Grep the state list
terraform state list | grep -i 'aws_iam'
Config-driven import block
cat > import.tf <<'EOF'
import {
to = aws_instance.web
id = "<id>"
}
EOF
terraform plan -generate-config-out=generated.tf
Refactor with moved block
cat >> moved.tf <<'EOF'
moved {
from = aws_instance.web
to = aws_instance.app
}
EOF