Import with an import block

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

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

tool
terraform43 commands
tags
terraformgitopscloud

More terraform commands

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

    Rename addresses in code without destroy and recreate; the change stays in version control

  • terraform apply -replace='aws_instance.web'

    Force one resource to be destroyed and created again; replaces the deprecated terraform taint

  • terraform plan -target='module.db.aws_db_instance.main'

    Limit the plan to one address; -target is for emergencies and can hide drift

  • terraform plan -refresh-only

    Compare state with the real infrastructure without proposing changes; shows drift made outside Terraform

  • terraform init -migrate-state -backend-config=backend.hcl

    Move state to a new backend; use -reconfigure to skip the migration and reset the backend settings

all 43 terraform commands