D1 · IaC and Terraform Fundamentals

Infrastructure as Code concepts

IaC fundamentals: what it is, its two main approaches, advantages over manual management, and key differences between tools in the ecosystem.

What is Infrastructure as Code?

Infrastructure as Code (IaC) is the practice of defining, provisioning, and managing IT infrastructure through machine-readable configuration files, instead of manual processes or graphical interfaces.

Infrastructure code is treated the same as application code: it's versioned in Git, reviewed in Pull Requests, tested, and deployed in an automated way.

Without IaC (manual management)

  • ✗Clicks in the web console — undocumented steps
  • ✗Ad-hoc scripts nobody maintains
  • ✗Impossible to reproduce environments exactly
  • ✗No history of who changed what
  • ✗Dependence on one person "knowing" things

With IaC (Terraform)

  • ✓Code in Git — full history
  • ✓PR review before applying
  • ✓Reproducible, identical environments
  • ✓Rollback with git revert + apply
  • ✓The code IS the documentation

Declarative vs. Imperative

There are two approaches to defining infrastructure as code. Terraform uses the declarative approach.

CharacteristicDeclarativeImperative
What do you describe?The DESIRED state ("I want 3 VMs")The steps to execute ("create VM, configure, start")
Who calculates it?Terraform automatically calculates the diff with You define each step explicitly
IdempotencyNative — running it twice = same resultYou must program it manually
LanguageHCL (Terraform), YAML (K8s, CF)Python, Bash, Go, DSL (Ansible)
ExamplesTerraform, CloudFormation, PulumiAnsible, Chef, Puppet, Bash scripts

💡 A real-world analogy

Declarative: You tell a chef "I want a Margherita pizza" — they decide how to make it.
Imperative: You tell the chef exactly: "preheat the oven to 220°C, roll out the dough, add sauce, add cheese, bake for 12 minutes..."

Advantages of the IaC approach

Versioning

Every change lives in Git. You can see who changed what, when, and why (PR description).

Reproducibility

Clone the repo, run , and get exactly the same infrastructure in any account/region.

Idempotency

Running apply multiple times produces the same result. If it already exists, Terraform doesn't recreate it.

Collaboration

Multiple people working on the same infra with Pull Requests, code review, and CI/CD.

Speed

Spin up a complex environment (VPC, subnets, VMs, DBs, load balancers) in minutes, not days.

Living documentation

The HCL code is the most up-to-date documentation of your infrastructure.

IaC tools compared

ToolApproachCloudMain use case
TerraformDeclarativeMulti-cloudCloud/on-prem infrastructure provisioning
AWS CloudFormationDeclarativeAWS onlyNative AWS infra for AWS-only teams
Azure Bicep / ARMDeclarativeAzure onlyNative Azure infra
Google Deployment MgrDeclarativeGCP onlyNative GCP infra
PulumiDeclarativeMulti-cloudIaC using programming languages (Python, TS)
AnsibleImperativeMulti-cloudOS and app configuration (not provisioning)
Chef / PuppetImperativeMulti-cloudConfig management with a server-side agent

🎯 For the exam

  • • Terraform ≠ Ansible: they are complementary. Terraform creates the infra (VMs, networks, DBs). Ansible configures what's inside it (installs packages, deploys apps).
  • • Terraform vs. CloudFormation: both declarative, but Terraform is multi-cloud while CloudFormation is exclusive to AWS.
  • • Terraform vs. Pulumi: same purpose (declarative, multi-cloud), but Pulumi uses Python/TypeScript/Go instead of HCL.

Did you get this topic?

Test what you just learned

A company wants to manage infrastructure on AWS and Azure using the same language and workflow. It also needs changes to be reviewed in Pull Requests before being applied. Which tool is best suited?

Ready to test "Infrastructure as Code Concepts"?

Put what you learned to the test with original Terraform Associate exam questions.

Start Terraform Associate mock exam

Unlimited mock exams with the Pro plan

Log in to track your progress.