Interview Infrastructure as Code (Terraform, Ansible)

What is terraform import, and when do you need it?

Infrastructure as Code (Terraform, Ansible) · Basic level

Answer

terraform import brings an existing real-world object under Terraform state management. It is needed when infrastructure was created manually, by another tool, or before Terraform adoption. Modern Terraform supports import blocks so imports can be reviewed, automated, and run through the normal plan/apply workflow.

Technical explanation

Import only updates Terraform state; you must still write configuration that matches the imported object.

Import blocks make imports reviewable and repeatable in pull requests.

After import, run plan and reconcile differences until the plan is clean or intentionally corrective.

Keep Terraform's ownership boundary clear: one state should own a resource or field, and other tools should consume published outputs instead of modifying it.

Use fmt, validate, linting, policy checks, plan review, and state locking before production applies.

Design for small blast radius by splitting state around lifecycle, permissions, and recovery boundaries.

Hands-on example

1. Onboard an existing resource for: What is terraform import, and when do you need it?

2. Inventory the existing object, then create a matching resource block and import block:

import {

to = aws_s3_bucket.logs

id = "existing-company-logs"

}

resource "aws_s3_bucket" "logs" {

bucket = "existing-company-logs"

}

3. Run terraform plan -generate-config-out=generated.tf in a scratch branch when supported for the resource, then clean up the generated configuration to match module standards.

4. Apply the import, run a normal plan, and reconcile every proposed change as intentional, accidental drift, or provider default noise.

5. Repeat in small batches and do not enable automated production apply until no-op plans are reliable.

Preparing for an interview?

Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.

More Infrastructure as Code (Terraform, Ansible) interview questions

← All Infrastructure as Code (Terraform, Ansible) questions