Cloud & DevOps5 min read10 interview questions
Infrastructure as code
Describing servers and networks in files instead of clicking in a console.
In one sentenceYou write down the servers, networks and settings you want in a file, and a tool builds them for you, the same way every time.
Think of it like thisIt is a recipe instead of cooking from memory: anyone can follow it and get the same dish, and you can see exactly what changed.
The big picture
Tap any step to see where to use it, how to use it and an example result.
Why not click in the console
Clicking is quick the first time and impossible to repeat exactly. Nobody remembers what was changed, and rebuilding after a disaster is slow and error-prone.
How it works
Tools like Terraform and OpenTofu read your files, compare them with what exists, show a plan, and then make the changes. You change the file to change the system, never the console.
Good habits
Keep the files in Git and review changes in pull requests. Keep secrets out of the files. Split large setups into small reusable modules, and run a plan on every change before applying it.
Common mistakes
- Changing things by hand in the console after the code manages them.
- Committing secrets or state files that contain them.
- Applying changes without reading the plan.
Quick recap
- Describe infrastructure in files
- Plan first, then apply
- Store files in Git and review changes
- Never edit managed resources by hand
Try it yourself
Use Terraform or OpenTofu with a free cloud account to create one storage bucket from a file, change a setting in the file, and then destroy it.
Top 10 interview questions
Ordered from basic to advanced. Try answering out loud first, then open the answer.
What is infrastructure as code?Basic
Describing servers, networks and other infrastructure in files that are kept in version control and applied by tools, instead of clicking in a console.
Why use infrastructure as code?Basic
It is repeatable, reviewable, versioned, faster and less error-prone. You can rebuild an environment from the files and see exactly what changed and who changed it.
Name some infrastructure as code tools.Basic
Terraform and OpenTofu, Pulumi, AWS CloudFormation, Azure Bicep, and configuration tools such as Ansible.
What is the difference between declarative and imperative styles?Basic
Declarative describes the end state you want and the tool works out the steps. Imperative lists the exact steps to run. Terraform is declarative.
What is state in Terraform and why is it important?Intermediate
A record of the real resources Terraform manages. It compares it with your code to decide what to create, change or destroy. Store it remotely with locking, and protect it because it can contain secrets.
What does terraform plan do?Intermediate
It shows what would be created, changed or destroyed without doing it, so you can review the effect before running apply.
What is drift and how do you deal with it?Intermediate
When real infrastructure differs from the code, usually because of manual changes. Detect it with plan or drift checks, then fix the code or revert the change, and limit manual access.
What is idempotency in this context?Intermediate
Applying the same configuration repeatedly gives the same result, creating only what is missing, so it is safe to run again.
How do you structure and reuse infrastructure code?Advanced
Use modules for reusable parts, separate environments with their own state, pin versions of providers and modules, and keep inputs as variables rather than copying files.
How do you keep infrastructure code safe in a team?Advanced
Pull requests with plan output, automated checks and policy tests, least-privilege credentials for pipelines, secrets kept in a vault and not in code, and approvals before changes reach production.
Guides are simplified on purpose. Tool names and details change, so check the official documentation before relying on a detail.