Infrastructure as Code (IaC)

The practice of managing and provisioning infrastructure through code files rather than manually clicking buttons in a web console.

🖱️ The "ClickOps" Problem

Configuring servers manually (ClickOps) is slow, error-prone, and impossible to replicate perfectly. If you lose the server, you have to remember every single button you clicked to rebuild it.

📜 The IaC Solution

You write a "Blueprint" (Code). You run a tool (Terraform/CloudFormation). The tool builds the servers. If disaster strikes, you just run the code again.

🕵️ Drift Detection

IaC tools ensure your live infrastructure matches your code. If someone manually changes a firewall rule, the IaC tool detects the "Drift" and fixes it automatically.

🏎️ The SysAdmin Race: Manual vs. Code

Mission: Deploy 10 Servers. See which method scales better.

Player 1: ClickOps
0 / 10

Task: Click the button 10 times. Wait for each to finish.

Player 2: IaC
0 / 10

Task: Write code once. Apply.

resource "aws_instance" "web" {
  count = 10
  ami = "ami-12345678"
}

🧠 Imperative vs. Declarative

🗣️ Imperative (Scripting)

You tell the computer HOW to do it.

# Bash Script
1. Create Server
2. Install Nginx
3. Start Service

If you run this twice, you might get 2 servers or an error.

📜 Declarative (IaC)

You tell the computer WHAT you want.

# Terraform / CloudFormation
I want: 1 Server
State: Running

If you run this twice, nothing happens (because you already have 1 server). This is called Idempotency.

🛠️ The Tool Landscape

Tool Type Best For Description
Terraform Declarative Multi-Cloud The industry standard. Uses HCL language. Works with AWS, Azure, Google, etc.
CloudFormation Declarative AWS Only Native to AWS. Deep integration but verbose (YAML/JSON).
Ansible Imperative* Config Management Best for configuring software inside servers (installing packages, patching).
Pulumi / CDK Code Developers Use real programming languages (Python, TypeScript) to define infrastructure.