Interview Infrastructure as Code (Terraform, Ansible)

What is Terraform, and what is the core plan/apply workflow?

Infrastructure as Code (Terraform, Ansible) · Basic level

Answer

Terraform is a declarative IaC tool that compares configuration, state, and real infrastructure to produce a plan, then applies that plan to create, update, or delete resources. The standard workflow is write HCL, terraform init, terraform fmt/validate, terraform plan, review, and terraform apply.

Technical explanation

plan is the safety checkpoint: it shows what Terraform intends to create, update, replace, or destroy.

apply executes the plan and writes updated state after provider operations succeed.

A mature workflow adds fmt, validate, linting, policy checks, and approval before production apply.

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. Build a small IaC workflow for: What is Terraform, and what is the core plan/apply workflow?

2. Create a Git repository with folders terraform/network and ansible/web. Put cloud resources in Terraform and host configuration in Ansible.

3. Add a minimal Terraform resource and run the standard workflow:

cd terraform/network

terraform init

terraform fmt -check

terraform validate

terraform plan -out=tfplan

terraform apply tfplan

4. Commit the plan output summary to the pull request, require approval, then use Ansible after infrastructure exists:

ansible-inventory -i inventory/aws_ec2.yml --graph

ansible-playbook -i inventory/aws_ec2.yml ansible/web/site.yml --check --diff

ansible-playbook -i inventory/aws_ec2.yml ansible/web/site.yml

5. Prove the benefit by rebuilding a dev environment from Git and confirming there are no manual console steps.

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