Back to sections

Infrastructure as Code Interview Questions & Answers

A sample of real Infrastructure as Code interview questions with full answers and explanations - practice for interviews or certification exams.

easy

1. [CloudFormation] Which section defines values you can pass when creating/updating a stack?

Resources
ParametersCorrect
Outputs
Mappings

The Parameters section is how you make a CloudFormation template reusable: instead of hardcoding a value, you define it as a parameter, and then you can plug in different values each time you create or update a stack without ever touching the template itself.

medium

2. Two engineers accidentally run terraform apply at the same time against the same remote state file, using a backend that supports locking. What should happen?

Both applies run simultaneously and merge their changes automatically
The second apply is blocked or fails until the first one finishes and releases the lockCorrect
Terraform silently overwrites one engineer's changes without warning
The state file is duplicated so each engineer gets their own copy

State locking prevents two processes from writing to the same state file at the same time, which could corrupt it or cause conflicting changes. The second engineer's apply has to wait, or fails with a lock error, until the first operation completes.

hard

3. [CloudFormation] How do you perform a blue/green deployment for an Auto Scaling Group?

Manually update launch template
Delete old ASG, create new
Use CodeDeploy with CODE_DEPLOY deployment option in CloudFormationCorrect
Use UpdatePolicy: AutoScalingRollingUpdate

CloudFormation has a built-in integration with CodeDeploy specifically for blue/green rollouts on an Auto Scaling Group: it spins up a brand new group alongside the old one, gradually shifts traffic over, and only terminates the old instances once the new ones are confirmed healthy, rather than you manually swapping things yourself.

easy

4. [CloudFormation] What happens when you update a stack and the change fails?

CloudFormation automatically rolls back to the previous working stateCorrect
You must manually delete the stack
Partial changes remain applied
It pauses and waits for user input

CloudFormation treats a whole stack update as one all-or-nothing operation. If even one resource fails partway through, it automatically undoes everything and puts the stack back to the last state that was known to work, rather than leaving things half-changed.

medium

5. [IaC General] Which practice minimizes "configuration drift"?

Regularly re-applying declarative IaC (e.g., terraform apply, ansible-playbook)
Using immutable infrastructure (rebuild instead of patch)
Both B and CCorrect
Manual SSH fixes

Configuration drift is when the real infrastructure slowly stops matching what your code says it should be, usually from manual tweaks. Regularly re-applying your IaC catches and corrects that drift after the fact, while immutable infrastructure (replacing servers instead of patching them) prevents most manual tweaks from ever happening in the first place, so using both together covers it from two directions.

hard

6. [Terraform] You manage 100+ AWS accounts. How do you avoid monolithic state and blast radius?

Store state in Git
Use local state files
Terragrunt to enforce DRY, remote state, and dependency ordering across directoriesCorrect
One huge main.tf

One giant Terraform configuration for 100+ accounts means one mistake can affect everything at once, and the state file becomes a nightmare to manage. Terragrunt keeps the code DRY across many separate account directories, gives each its own remote state, and manages the order dependencies get applied in, all without one single, risky state file.

easy

7. A junior engineer is about to run terraform apply on a production environment for a new set of changes. A senior engineer tells them to run terraform plan first. Why?

terraform plan is faster than terraform apply, so it should always be run instead
terraform plan is required by law for compliance reasons
terraform plan shows a preview of what will be added, changed, or destroyed before anything actually happensCorrect
terraform plan automatically fixes any mistakes in the code

terraform plan lets you review the exact changes Terraform intends to make without touching real infrastructure, so mistakes like an accidental resource deletion can be caught before they happen. terraform apply is the step that actually performs those changes.

medium

8. [Ansible] What is the difference between copy and template modules?

template is faster
copy only works on Windows
template requires root
copy transfers static files; template renders Jinja2 files (e.g., config.j2) with variablesCorrect

copy is for files that don't need to change, it just transfers them as-is. template is for files that need customization per host, like a config file, it renders a Jinja2 template (such as config.j2) and substitutes in your variables before delivering the final, host-specific file.

hard

9. [Ansible] How do you run a playbook against hosts with different OSes (e.g., Ubuntu/CentOS) using correct package managers?

Use raw module
Assume all are Ubuntu
Write separate playbooks
Use ansible_os_family fact + conditional tasksCorrect

Ubuntu uses apt and CentOS uses yum, so a single hardcoded package-install task would break on one of them. The ansible_os_family fact tells you which family a host belongs to, so a task can branch and use the right package manager automatically instead of you maintaining entirely separate playbooks per OS.

easy

10. [IaC General] Which tool is agentless and uses SSH by default?

AnsibleCorrect
Terraform
Chef
Puppet

Ansible doesn't need any special software installed on the machines it manages, it just connects over the SSH you probably already have set up and pushes what it needs to run. Puppet and Chef, by contrast, both require an agent process running persistently on every managed machine.

Want to practice under real conditions?

Try the full timed Infrastructure as Code quiz.

    Welcome to OpsQuiz!

    Real scenario-based DevOps questions, hands-on practice, and clear explanations for every answer.