terraform import Command Reference
Bring resources that already exist under Terraform management.
terraform import associates an existing real-world object with a resource address in state, so Terraform manages it instead of creating a duplicate.
What it does
terraform import ADDRESS ID records the existing object identified by ID in state under ADDRESS. You must still write matching configuration. Terraform 1.5+ also supports declarative import {} blocks with terraform plan -generate-config-out.
Common flags and usage
- ADDRESS ID: target resource address and provider-specific ID
- -var / -var-file: variables needed to evaluate the config
- -input=false: never prompt (required in CI)
- import {} block + plan -generate-config-out=FILE (1.5+) for reviewable imports
Example
shell
# Adopt an existing S3 bucket, then reconcile drift
terraform import aws_s3_bucket.logs my-logs-bucket
terraform plan -input=false # reconcile until the plan is cleanIn CI
Write the resource block first, then import; importing before a block exists fails. Prefer import {} blocks committed to the repo so adoption is reviewable and reproducible in the pipeline.
Key takeaways
- import binds an existing object to a resource address you have already written.
- Terraform 1.5+ import {} blocks make adoption reviewable in version control.
- After import, run plan and reconcile drift until it is clean.
Related guides
terraform apply Command ReferenceReference for terraform apply in CI/CD: apply a saved plan non-interactively, use -auto-approve, and cap para…
terraform state list Command ReferenceReference for terraform state list in CI/CD: enumerate and filter the resource addresses Terraform tracks, th…
terraform show Command ReferenceReference for terraform show in CI/CD: render a saved plan or state as human-readable or JSON for policy chec…