Infrastructure as Code
In one line
IaC defines infrastructure in code files — versioned, reusable, and automated instead of manual clicking.
In simple words
Infrastructure as Code (IaC) means defining your infrastructure in code files rather than configuring them manually. The code is version-controlled, reviewed, and applied automatically.
Benefits: 1. Version control 2. Reproducibility 3. Consistency 4. Speed 5. Documentation — the code IS the documentation
Two approaches: Declarative (Terraform) — describe desired state; Imperative (Ansible) — describe steps. Popular tools: Terraform, CloudFormation, Pulumi.
Example
resource "aws_instance" "web" {
ami = "ami-12345678"
instance_type = "t3.micro"
count = 3 # 3 identical servers
tags = { Name = "web-server", Env = "production" }
}
# Apply: terraform plan && terraform applyTerraform code defines 3 web servers. terraform apply creates them. The code is version-controlled and reproducible.
Common confusions
Confused with: Configuration Management
The difference: IaC (Terraform) provisions infrastructure. Configuration management (Ansible) configures existing servers. IaC is for creation; config management is for setup.
Related terms
Related Resources
Related Lessons
- Infrastructure as Code
IaC overview.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.