Three sources; a plan is a diff of two of them
CONFIG is the only truth · STATE says which objects to ask about ·
REALITY is refreshed in at every plan.
plan = refresh state from reality, then diff config against reality.
Anything in reality that config doesn't mention, inside a managed attribute, is deleted on the next apply.
Reconcile a hand-change — three moves
Reading -refresh-only against a normal plan
apply -refresh-only writes drift into state only — the next normal plan still reverts it.
It never resolves drift. Run it on a CI schedule to catch console cowboys.
Tags are a managed map
All-or-nothing. A key missing from config gets - key = ... -> null, i.e. deleted.
tags_all = tags plus the provider's default_tags; computed, never written by you.
import — the modern form (TF >= 1.5)
import {
to = aws_s3_bucket.imported
id = "bucket-name"
}
terraform plan -generate-config-out=generated.tf # Terraform writes the HCL for you
terraform apply # "1 to import"
terraform plan # must say: no changes
Then delete the import block — it's a one-time instruction, not permanent config.
Generated config is experimental: review and trim before committing.
import — legacy CLI
terraform import aws_s3_bucket.imported bucket-name
The block is plan-first, writes the HCL, lives in git and is CI-safe. The CLI mutates state
immediately, you write the HCL yourself, and it has to be re-run by hand in every environment.
Gotchas
- A plain
plan with an import block but no resource block → resource has no configuration.
- Clean-import proof is
plan saying no changes — state and config both match reality.
- Import brings one object. Bucket policy, versioning, SG rules each need their own.
- The ID format is per-resource and always a lookup: the registry page's "Import" section.