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.
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?
- Manual cloud setup does not scale.
- Humans forget, click the wrong thing, and create inconsistent environments.
- Teams need reviewable, repeatable, versioned infrastructure changes.
- Disaster recovery is faster when the platform can be recreated from code.
🔧 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 Infrastructure | Terraform / IaC |
|---|---|
| Portal clicks | Code in version control |
| Hard to audit | Reviewed in pull requests |
| Environment drift is common | Same configuration can be reused |
| Rebuilds are slow and error-prone | Reprovisioning is predictable |
Terraform is especially popular because it supports many providers, uses a readable configuration language, and gives a plan before applying changes.
🌍 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 focus | ARM/Bicep can be a pragmatic fit |
| Multi-cloud or hybrid platform tooling | Terraform is usually stronger |
| Need one shared IaC workflow across teams/tools | Terraform often simplifies standardization |
There is no universal winner. Choose based on operating model, team capability, governance, and cloud scope.
See the full interview-grade comparison in Lesson 16: Terraform vs ARM/Bicep.
🛠️ Hands-on
Install Terraform and Verify
terraform version terraform -help
- Install Terraform from HashiCorp releases or a package manager.
- Open a terminal and run
terraform version. - Confirm the CLI is available before moving to the workflow lesson.
Try It Yourself
- List three infrastructure tasks your team still does manually.
- Identify one environment inconsistency that IaC would prevent.
- Explain why recreating from code is safer than relying on memory.
🐛 Debugging Scenario
Problem: Two environments were built manually and now behave differently.
- Compare the actual cloud resources and configuration.
- Identify which settings are undocumented or portal-only.
- Move the missing configuration into code so future environments are identical.
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
It is the practice of defining and managing infrastructure using files and automation instead of manual UI-based changes.
Because it provides declarative infrastructure, execution planning, reuse, and support for many cloud providers and services.
You describe the desired final state, and Terraform determines the steps required to reach that state.
Terraform tracks desired state and calculates changes, while ad hoc scripts often just execute imperative commands without strong state awareness.
It gives review history, rollback context, collaboration, and auditability for infrastructure changes.
Intermediate
Because the same configuration can recreate environments consistently, which improves reliability, onboarding, and disaster recovery.
Terraform usually provisions the platform resources such as AKS, ACR, networking, and identity. Helm then deploys workloads into the running cluster.
Author code, run fmt and validate, generate plan, review in a pull request, apply through CI/CD, then monitor for drift or failed changes.
Because infrastructure changes can be highly impactful, so review, approvals, and environment protections still matter even when automation is used.
If infrastructure code exists but the real environment is still changed directly in the portal without updating the codebase.
Scenario-Based
The portal can be faster for one isolated change, but Terraform is faster and safer for repeated, reviewed, and team-visible changes over time.
Terraform would have kept the network design, dependencies, and configuration in versioned code so the platform could be understood and recreated without guesswork.
Because it supports reviewable change history, predictable execution, and clearer audit trails than unmanaged manual provisioning.
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 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.