Import blocks and reconciliation
Declare the adoption in configuration
An import block makes adoption part of the ordinary plan and apply review workflow. It names the destination instance and the existing object to bind. The matching resource configuration describes the desired settings. This fictional example is for reading only.
import { to = demo_record.catalog id = "rec-042"}
resource "demo_record" "catalog" { name = "catalog" retention = 30}During an authorized plan, Terraform can propose an import and other changes together. The import takes effect when the plan is applied, not merely when the file is written. The identifier must be known during planning. A retained import block can document the adoption and is not a request to repeatedly import an already-managed address. CLI import and this workflow are alternatives.
Import several known objects using stable keys
A map can associate a stable address key with each known identifier. The resource block and import block use the same keys; the resource name is the key in this fictional schema.
locals { catalog_ids = { east = "rec-042" west = "rec-079" }}
resource "demo_record" "catalogs" { for_each = local.catalog_ids name = each.key retention = 30}
import { for_each = local.catalog_ids to = demo_record.catalogs[each.key] id = each.value}East maps to rec-042 and west maps to rec-079. Both keys and import IDs must be available during planning. This is a separate scenario from the single catalog example. Verify the destination names and retention against actual inventory rather than assuming they match. Do not import duplicate IDs. Import for_each is version-dependent; the current documentation supports it but the pinned patch has not been tested.
Generate configuration as a starting point
When the destination resource is missing, Terraform can offer generated configuration for supported import cases. The following command illustrates a separate single-resource workflow; the output path must not already exist.
# Separate scenario: import block exists, destination block is absent.terraform plan -generate-config-out=generated.tfReview the resulting code against provider schema, required arguments, defaults and conflicting arguments. Generated values may contain sensitive details or be unsuitable for reuse; sanitize and review before version control. Replace repeated literals with variables only where meaningful. Replan after edits. Do not assume every provider or every import shape supports configuration generation. In particular do not rely on generation for the keyed batch example above.
Distinguish IDs, identity objects and discovery
Some providers support a structured identity rather than a single import string. The following keys are invented, not an actual provider contract.
import { to = demo_record.catalog identity = { account = "training" name = "catalog" }}Use either id or identity in one block, not both. Exact identity fields and support depend on the resource and provider. Current documentation also describes separate query files (.tfquery.hcl), list blocks and terraform query for supported discovery workflows. Bulk discovery is not part of this lab; its exact release and provider support require verification and explicit authorization for the inventory scope. Never enumerate an entire account just to find one object.
Reconcile the plan before accepting ownership
Read these synthetic summaries. They are teaching cases, not real Terraform output.
Synthetic plan A: import catalog; no add, update or destroy.Synthetic plan B: import catalog; retention 30 -> 7 (in-place update).Synthetic plan C: import catalog; replacement proposed.Synthetic plan D: catalog already imported; no changes.A may pass adoption review once the target and ownership checks are satisfied. B changes a retention policy and may affect data; block until the configuration reflects the approved policy or the owner separately approves the change. C is especially risky because replacement can destroy the existing object; stop and inspect the reason. D is an expected possibility after successful adoption with matching configuration, but a quiet plan is not a service health test. After an authorized apply, verify the state binding, rerun a plan and check the application behavior through approved checks.
Practice a review decision
Read the offline plan cases, classify each as adoption-only, needs reconciliation, already managed, or invalid/blocked. Write a short review note with the address, intended object, proposed action and next safe step. No real Terraform operation is required.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Import blocks and reconciliation — knowledge check
Review import identity, state binding and adoption safety.
When does configuration-driven import write the binding?
What must match the import block destination?
What is the correct treatment of generated configuration?
Can id and identity appear together in one import block?
An adoption plan includes replacement. What should a reviewer do?