Interview › Infrastructure as Code (Terraform, Ansible)
How do you import existing infrastructure into Terraform at scale?
Infrastructure as Code (Terraform, Ansible) · Intermediate level
Answer
At scale, I import existing infrastructure by inventorying resources, grouping them by ownership and risk, generating resource and import blocks, running plans in small batches, reconciling drift, and adding tests and policy. Modern import blocks and bulk import workflows are better than one-off CLI imports because they are reviewable and repeatable.
Technical explanation
Start with read-only inventory and tagging so ownership is clear before import.
Import low-risk resources first to validate naming and module design.
For large estates, automate discovery and generated import blocks but review each batch.
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: How do you import existing infrastructure into Terraform at scale?
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.
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
- What is Infrastructure as Code, and what problems does it solve over click-ops?
- What is the difference between declarative and imperative IaC, and where do Terraform and Ansible fall?
- What is the difference between configuration management and provisioning?
- What is Terraform, and what is the core plan/apply workflow?
- What does terraform init do?
- What is the Terraform state file, and why is it critical?
- Why should state be stored remotely, and what backend would you use on AWS?
- What is state locking, and why does it matter for teams?