Skip to main content

Terraform Import

Terraform import brings an existing cloud resource created outside Terraform under its management by recording it in state. After import, Terraform can plan and apply changes to it without recreating it.

What Is Terraform Import?

Import writes to state only, so you still need a matching resource block. From Terraform 1.5, use an import block, which is reviewed in a PR.

HCL
import {
to = aws_s3_bucket.assets
id = "shopify-assets-prod"
}
Bash
terraform plan -generate-config-out=generated.tf # draft the resource block

After importing, run terraform plan and edit your code until it shows no changes.

Common Mistake

Applying right after import without reading the plan. If your code is incomplete, apply changes the live resource to match it.

Frequently Asked Questions

Does import write the configuration for me?

The classic command only updates state. With an import block and -generate-config-out on Terraform 1.5 and later, Terraform drafts a resource block you can review.

How do I import safely?

Import, then run terraform plan before anything else. Adjust the code until the plan shows no changes.

Found a mistake, an outdated step or a broken link?