Skip to content
Latchkey

How to Import Existing Resources Into Terraform in CI

A config-driven import block lets Terraform adopt an existing resource during a normal plan, which you can review on a PR before applying.

Add an import block with the target address and real resource id, then run terraform plan -generate-config-out=generated.tf to scaffold the config. Review the generated resource on the PR, then apply to record it in state.

import block

main.tf
import {
  to = aws_s3_bucket.logs
  id = "acme-prod-logs"
}

Generate config in CI

Terminal
terraform plan -generate-config-out=generated.tf -input=false

Gotchas

  • Import blocks are planned like any change, so the import shows up in the PR plan for review.
  • Generated config is a starting point; refine it before apply so future plans show no diff.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →