tfimport - Terraform Import Auto-Pilot

2 min read Original article ↗

# 1. Write your manifests to match the infrastructure that already exists

cat main.tf

# 2. Run tfimport to generate an import.tf file

tfimport

✔ Executing plan (tofu)...

✔ Parsing tfplan...

✔ Computing import IDs...

✔ Import file generated at /home/user/project/import.tf

You can now run `tofu apply` to import the resources

# Alternatively, run import directly via CLI

tfimport --run-import

✓ These resources will be imported:

Address: aws_s3_bucket.main, ImportID: my-app-bucket

Want to proceed with import? [y/N]: y

✔ Successfully imported aws_s3_bucket.main

# 1. Write your manifests to match the infrastructure that already exists

cat main.tf

# 2. Run tfimport to generate an import.tf file

tfimport --terraform

✔ Executing plan (terraform)...

✔ Parsing tfplan...

✔ Computing import IDs...

✔ Import file generated at /home/user/project/import.tf

You can now run `terraform apply` to import the resources

# Alternatively, run import directly via CLI

tfimport --terraform --run-import

✓ These resources will be imported:

Address: aws_s3_bucket.main, ImportID: my-app-bucket

Want to proceed with import? [y/N]: y

✔ Successfully imported aws_s3_bucket.main

# 1. Write your manifests to match the infrastructure that already exists

cat terragrunt.hcl

# 2. Run tfimport to generate an import.tf file

tfimport --tg

✔ Executing plan (terragrunt)...

✔ Parsing tfplan...

✔ Computing import IDs...

✔ Import file generated at /home/user/project/import.tf

You can now run `terragrunt apply` to import the resources

# Alternatively, run import directly via CLI

tfimport --tg --run-import

✓ These resources will be imported:

Address: aws_s3_bucket.main, ImportID: my-app-bucket

Want to proceed with import? [y/N]: y

✔ Successfully imported aws_s3_bucket.main