What is Infrastructure as Code (IaC)? What problems does it solve?
Infrastructure as Code (IaC) is the practice of provisioning and managing infrastructure (servers, networks, databases, Kubernetes clusters) using code and configuration files instead of manual clicks in a console.
Declarative IaC — describe the desired state; the tool figures out how to get there. Examples: Terraform, AWS CloudFormation, Pulumi, Kubernetes manifests.
Imperative IaC — describe the steps to get there. Examples: Bash + AWS CLI, Boto3 scripts.
Problems IaC solves:
Snowflake servers — no two manually-configured servers are the same.
Configuration drift — manual changes diverge from intended state.
No audit trail — who changed what, when?
Slow disaster recovery — rebuilding by hand is error-prone.
Benefits: version control, reproducibility, automation, drift detection, easy disaster recovery, peer review of infra changes.
# main.tf — Terraform IaC example
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
tags = {
Name = "web-server"
Env = "prod"
}
}
# Apply: terraform init && terraform applyDefines an EC2 instance using Terraform HCL syntax. The configuration is declarative: you describe the desired state (instance type, AMI, tag) and Terraform handles creation.
Running terraform apply will provision the instance; running it again with no changes is a no-op (idempotent).
IaC is more than just 'using Terraform.' Mention the four key benefits: version control, reproducibility, automation, and drift detection. Bonus: contrast declarative (Terraform, CloudFormation) vs imperative (Pulumi imperative APIs, Boto3 scripts).