Interview › Infrastructure as Code (Terraform, Ansible)
How would you onboard an existing manually-built environment into IaC with confidence?
Infrastructure as Code (Terraform, Ansible) · Advanced level
Answer
To onboard a manually built environment, I inventory resources, identify ownership boundaries, create modules or resource blocks, import in small batches, compare generated configuration with standards, fix drift deliberately, add tests and policy, and only then enable automated applies for production.
Technical explanation
Do not import everything into a single state file; choose lifecycle boundaries first.
Run no-op plans before enabling automated apply to prove code matches reality.
Preserve rollback options and backups during the transition.
Keep source manifests or IaC definitions readable enough that reviewers can understand the final desired state.
Use overlays, modules, or roles for reuse, but keep environment-specific differences explicit and reviewable.
Validate generated output in CI before applying it through kubectl, Argo CD, Terraform, or Ansible.
Hands-on example
1. Onboard an existing resource for: How would you onboard an existing manually-built environment into IaC with confidence?
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?