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 the difference between terraform destroy and removing a resource from code?
- What is a Terraform registry module, and how do you evaluate one for production use?
- How do you handle a Terraform apply that fails halfway through?
- How would you write a reusable module for a standard service?
- What is a policy-as-code check for Terraform (OPA, Sentinel, checkov)?
- What is the difference between Terraform and CloudFormation, and when choose each?
- How would you integrate Terraform into a CI/CD pipeline safely?
- What is OpenTofu, and why did it fork from Terraform?