How do Terraform import blocks reduce risk vs ad hoc terraform import commands during production adoption?
Quick Answer
Import blocks make import intent reviewable in configuration, while ad hoc CLI imports mutate state immediately and can be hard to audit. They still require matching resource blocks and careful address selection.
Detailed Answer
Think of importing infrastructure like adding existing buildings to a city map. You need the right address, the right owner, and the right description; otherwise future construction permits target the wrong building.
Terraform import exists so unmanaged resources can come under infrastructure-as-code control. Modern import blocks make that workflow declarative, reviewable, and repeatable instead of a one-off terminal action.
The workflow is to identify resource identity, declare an import block with the destination address, create or generate a matching resource block, run plan, then apply. Terraform records the remote object in state at the declared address.
In production, risk lives in the address and configuration match. If attributes do not match real infrastructure, the first post-import plan may propose dangerous changes. Engineers check lifecycle rules, tags, provider aliases, and module paths carefully.
The non-obvious gotcha is assuming import means Terraform understands the whole resource relationship. It only records the target object; you still need to model dependencies, ownership, and ignored provider-managed fields correctly.
Code Example
import {
to = module.network.aws_security_group.payments # Imports into the final module address, not a temporary root address.
id = "sg-0abc1234def567890" # Uses the provider-specific security group identity.
}
terraform plan -generate-config-out=generated.tf # Generates starter configuration for review when supported.Interview Tip
A junior engineer typically answers with the command or product feature, but for a senior/architect role, the interviewer is actually looking for how you operate Terraform under pressure. Tie the answer to ownership, rollout safety, observability, rollback, and blast-radius control. Mention what signal proves the change is healthy and what you would never do during an incident without first checking live state.