BlogIaC
Importing existing infrastructure into Terraform state
Bring click-ops resources under Terraform with import blocks and generated config — without recreating them.
Every team has infrastructure that was clicked into existence before Terraform. You do not have to recreate it — import brings existing resources under management by writing them into state. Since Terraform 1.5, import blocks even generate the starting config for you.
Declare what to import
import.tf
import {to = aws_s3_bucket.logsid = "acme-app-logs" # the real resource identifier}
Generate the config
terraform plan -generate-config-out=generated.tfaws_s3_bucket.logs: will be importedwrote resource "aws_s3_bucket" "logs" to generated.tfReview the generated HCL
Generated config is a literal dump of current state — it includes defaults and may miss lifecycle rules. Read it, tidy it, and confirm the next plan shows no changes.
The pre-1.5 way
bash
# write the resource block by hand first, then:terraform import aws_s3_bucket.logs acme-app-logs
Whichever path you take, the goal is the same: a clean terraform plan with no changes afterwards. That is proof state matches reality.