BasicsLesson 1 of 16

What is Infrastructure as Code?

Understand why modern infrastructure is managed like software and why Terraform became one of the most important IaC tools in real-world platform engineering.

🧒 Simple Explanation (ELI5)

Imagine building the same office in ten cities. If every crew just "figures it out" by clicking around in cloud portals, each office ends up slightly different. One gets the wrong doors, another misses fire alarms, and nobody remembers exactly what was built.

Infrastructure as Code means you write the building instructions once and reuse them consistently. Terraform is one of the tools that reads those instructions and creates the cloud resources for you.

🤔 Why Do We Need It?

🔧 Technical Explanation

Infrastructure as Code is the practice of defining infrastructure in files instead of configuring it manually through UI clicks. Terraform uses a declarative model: you describe the desired end state, and Terraform calculates the actions needed to get there.

Manual InfrastructureTerraform / IaC
Portal clicksCode in version control
Hard to auditReviewed in pull requests
Environment drift is commonSame configuration can be reused
Rebuilds are slow and error-proneReprovisioning is predictable

Terraform is especially popular because it supports many providers, uses a readable configuration language, and gives a plan before applying changes.

IaC Flow
Code
Plan
Apply
Cloud Resources
💡
Key Mindset

Terraform is not just a provisioning tool. It is a change-management tool for infrastructure. The code matters, but so do planning, review, drift control, and safe rollout.

🌍 Real-World Use Case

A platform team might use Terraform to create resource groups, VNets, subnets, AKS clusters, ACR registries, and storage accounts for remote state. Application teams then deploy into that platform using Helm and CI/CD. Terraform defines the platform foundation; other tools deploy workloads on top of it.

🧭 Quick Decision: Terraform vs ARM/Bicep

If Your Context Is...Likely Better Starting Point
Azure-only, strong native Azure focusARM/Bicep can be a pragmatic fit
Multi-cloud or hybrid platform toolingTerraform is usually stronger
Need one shared IaC workflow across teams/toolsTerraform often simplifies standardization

There is no universal winner. Choose based on operating model, team capability, governance, and cloud scope.

💡
Go Deeper

See the full interview-grade comparison in Lesson 16: Terraform vs ARM/Bicep.

🛠️ Hands-on

Install Terraform and Verify

powershell
terraform version
terraform -help
  1. Install Terraform from HashiCorp releases or a package manager.
  2. Open a terminal and run terraform version.
  3. Confirm the CLI is available before moving to the workflow lesson.

Try It Yourself

🐛 Debugging Scenario

Problem: Two environments were built manually and now behave differently.

⚠️
Common Mistake

Teams adopt Terraform but still make emergency portal changes without feeding them back into code. That creates drift and breaks trust in IaC.

📋 Interview Questions

Beginner

What is Infrastructure as Code?

It is the practice of defining and managing infrastructure using files and automation instead of manual UI-based changes.

Why do teams use Terraform?

Because it provides declarative infrastructure, execution planning, reuse, and support for many cloud providers and services.

What does declarative mean here?

You describe the desired final state, and Terraform determines the steps required to reach that state.

How is IaC different from scripts that run cloud CLI commands?

Terraform tracks desired state and calculates changes, while ad hoc scripts often just execute imperative commands without strong state awareness.

Why is version control important for infrastructure?

It gives review history, rollback context, collaboration, and auditability for infrastructure changes.

Intermediate

Why is reproducibility a major Terraform benefit?

Because the same configuration can recreate environments consistently, which improves reliability, onboarding, and disaster recovery.

Where does Terraform fit compared with AKS and Helm?

Terraform usually provisions the platform resources such as AKS, ACR, networking, and identity. Helm then deploys workloads into the running cluster.

What is a typical enterprise IaC workflow?

Author code, run fmt and validate, generate plan, review in a pull request, apply through CI/CD, then monitor for drift or failed changes.

Why is manual change control still relevant with Terraform?

Because infrastructure changes can be highly impactful, so review, approvals, and environment protections still matter even when automation is used.

What is a sign a team has not really adopted IaC?

If infrastructure code exists but the real environment is still changed directly in the portal without updating the codebase.

Scenario-Based

A developer says the portal is faster than Terraform. How do you respond?

The portal can be faster for one isolated change, but Terraform is faster and safer for repeated, reviewed, and team-visible changes over time.

Your team lost track of how production networking was created. How would IaC have helped?

Terraform would have kept the network design, dependencies, and configuration in versioned code so the platform could be understood and recreated without guesswork.

Why is Terraform especially useful in regulated environments?

Because it supports reviewable change history, predictable execution, and clearer audit trails than unmanaged manual provisioning.

How would you explain Terraform to a project manager?

It is a way to define cloud infrastructure the same way engineers define application code, making the environment more repeatable, testable, and easier to change safely.

When would Terraform not be enough on its own?

When you also need workload deployment, application packaging, secret rotation workflows, or runtime operations. Terraform is one layer of the platform toolchain, not the entire toolchain.

🧾 Summary

Infrastructure as Code replaces fragile manual cloud setup with repeatable, reviewable, versioned infrastructure definitions. Terraform is one of the most important IaC tools because it lets teams describe desired state, preview changes safely, and build real platforms consistently.