Import and adoption planning
Adoption is not creation
Suppose a team created a catalog manually and now wants Terraform to manage it. Import connects that existing object to an address in Terraform state. It is not a copy, a backup, or a request to create another catalog. A configuration describes the intended settings; the state binding tells Terraform which existing object belongs to that configuration. These examples use a fictional resource type and identifiers; no provider exists for them. Do not execute the commands. The provisional Terraform CLI baseline is 1.14.8, not independently tested.
Identify the three parts of an import
Record the provider context (account and region), the provider-specific import identifier, and the Terraform destination address. In the example the object rec-042 belongs to the training account and is intended to be managed at demo_record.catalog. Retention is an imaginary configurable setting measured in days.
# Fictional resource schema; not executable.resource "demo_record" "catalog" { name = "catalog" retention = 30}The address is made from the resource type and local label, not from its remote name or identifier. If the object is already managed at another address or in another state, stop and agree an ownership transfer rather than binding it twice. Confirm the provider supports importing that resource type and verify the exact identifier format in its versioned documentation.
Plan the adoption before writing state
Before an authorized import, inventory the resource and dependencies, confirm the owner and target, check the selected backend/workspace and provider identity, coordinate concurrent changes and protect a recoverable state backup. Write the destination configuration using observed values as a starting point. Decide which settings should be preserved and defer unrelated changes. An import can call provider APIs and write sensitive state; it is not just a local file operation. Keep the state lock enabled. Never run these illustrative commands against a real account.
Understand the CLI import workflow
The CLI form takes an address followed by the import identifier. In an initialized, authorized environment with a real supported provider, the first command writes the state binding directly; it does not generate a resource block. The following two commands inspect the result and calculate a separate change proposal.
terraform import demo_record.catalog rec-042terraform state show demo_record.catalogterraform planRead the inspection output only in the approved environment; it can contain sensitive data. Compare the next plan with the intended adoption scope. For an import-only task, an update, replacement or deletion is a reason to stop and reconcile configuration first. Do not assume CLI import has a preceding plan approval stage like configuration-driven import.
Address an individual keyed instance
For a resource declared with for_each, include the correct instance key. The following POSIX-shell illustration assumes the destination configuration declares the east key.
terraform import 'demo_record.catalogs["east"]' rec-042The outer single quotes preserve the literal double quotes around the key for the CLI. Other shells have different quoting rules. The same remote record must not also be imported at demo_record.catalog. These are alternative scenarios, not a sequence.
Practice adoption planning
Use the synthetic inventory in the lab. For each object, identify its owner, context, ID and proposed address. Reject an already-managed object or an unverified target. Explain why a state binding alone is insufficient to manage desired settings.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Import and adoption planning — knowledge check
Review import identity, state binding and adoption safety.
What does a successful import primarily establish?
What determines the import ID format?
What does terraform import do to configuration?
A record is already managed in another state. What should happen?
Which command is the correct conceptual target for the east keyed instance?