Infrastructure as Code: Principles That Actually Matter
Writing infrastructure as code is easy. Writing good infrastructure as code requires discipline.
February 23, 2026 · 6 min · 1251 words · Rob Washington
Table of Contents
Infrastructure as Code (IaC) means your servers, networks, and services are defined in version-controlled files rather than clicked into existence through consoles. The benefits are obvious: reproducibility, auditability, collaboration.
But IaC done poorly creates its own problems: state drift, copy-paste sprawl, untestable configurations. The principles matter more than the tools.
# Idempotent - creates if missing, updates if different, no-op if same
resource"aws_s3_bucket" "data" {
bucket="my-data-bucket"}# Not idempotent - would fail on second run
resource"null_resource" "setup" {
provisioner"local-exec" {
command="aws s3 mb s3://my-data-bucket" # Fails if exists
}
}
If you must use provisioners or scripts, add guards:
# Bad - secret in code
resource"aws_db_instance" "main" {
password="supersecretpassword123" # In git history forever
}# Good - from secret manager
data"aws_secretsmanager_secret_version" "db_password" {
secret_id="prod/database/password"}
resource"aws_db_instance" "main" {
password=data.aws_secretsmanager_secret_version.db_password.secret_string}# Good - from variable (injected at runtime)
variable"db_password" {
sensitive=true}
resource"aws_db_instance" "main" {
password=var.db_password}
Use sensitive = true to prevent values from appearing in logs.
Infrastructure changes outside of IaC (console clicks, scripts) create drift:
1
2
3
4
5
6
7
# Detect driftterraform plan
# If plan shows changes you didn't make:# 1. Import the manual change into state# 2. Or revert the manual change# 3. Never ignore it
Regular drift detection (daily or per-deploy) catches unauthorized changes before they cause problems.
# This VPC hosts all production workloads.
# CIDR chosen to not overlap with office network (192.168.0.0/16)
# for VPN connectivity.
resource"aws_vpc" "production" {
cidr_block="10.0.0.0/16"tags= {
Name="production" CostCenter="engineering" ManagedBy="terraform" }
}
Tags and comments explain why, not just what.
Infrastructure as Code is a practice, not a tool. Terraform, Pulumi, CloudFormation — they all work. What matters is the discipline: declarative definitions, immutable deployments, versioned state, tested changes, no secrets in repos.
Write infrastructure like you write application code: reviewed, tested, versioned, and understood by the team. The server you can recreate in minutes is worth more than the server you’ve been nursing for years.
📬 Get the Newsletter
Weekly insights on DevOps, automation, and CLI mastery. No spam, unsubscribe anytime.