Skip to content
Latchkey

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 clean

In 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →