Infrastructure as Code
Infrastructure as code describes servers, databases and networks in files — so environments are repeatable, reviewable and versioned like application code.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Oct 29, 2026
Related tutorials
Learning objectives#
- Explain IaC and its benefits
- Compare declarative tools
- Understand plan, apply, state and drift
- Review infrastructure changes safely
Explanation#
Declarative IaC describes the end state (“a storage account with these settings”); the tool works out the steps.
Popular tools: Terraform/OpenTofu (multi-cloud), Bicep (Azure), CloudFormation/CDK (AWS), Pulumi (general-purpose languages).
A plan previews changes; apply makes them. State records what the tool manages. Drift is when someone changes resources by hand.
Infrastructure changes go through pull requests with the plan output attached for review.
Code example: The IaC workflow#
1. Edit main.tf / main.bicep in a branch
2. Open PR → CI runs: fmt check · validate · plan
3. Reviewer reads the plan: "+ create 1 storage account, ~ update 1 app setting"
4. Merge → CD runs apply with an approved plan
5. Nightly job runs plan again → any difference = drift alert
Every infrastructure change is reviewed, repeatable and recorded in Git history.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Infrastructure is edited like code, in a branch.
- CI shows exactly what will change.
- Apply runs only after review.
- Scheduled plans detect manual drift.
Real-world use case#
Recreating an identical staging environment in minutes, or rebuilding production in another region after a disaster.
Common mistakes#
Manual changes are overwritten or cause drift. Change the code instead.
A rename can destroy and recreate a database. Read every plan.
Best practices#
- All infra in Git
- Plan in PRs, apply after approval
- Remote, locked state
- Small modules reused across environments
Remember this#
Declare the end state; the tool does the steps.
plan → review → apply.
Drift = reality ≠ code.
Practice exercise#
Your task: Name the native IaC language for Azure and for AWS.
Show solution
Azure: Bicep (ARM templates). AWS: CloudFormation (or the CDK).
Mini quiz#
What is configuration drift?
Want more? Practise all DevOps MCQs · DevOps interview questions
My notes#
Saved in this browser.