← All insightsIaC

Immutable infrastructure and golden images

Nir Geier, CodeWizard · 24 June 2025 · 3 min read · Intermediate

Mutable servers drift. Every manual patch, hotfix and config tweak makes a host a little more unique until nobody can reproduce it. Immutable infrastructure ends that: you never change a running server, you replace it with a new image.

Bake a golden image

hcl
# Packer template: build a versioned AMI
source "amazon-ebs" "web" {
  ami_name      = "web-{{timestamp}}"
  instance_type = "t3.micro"
  source_ami_filter { filters = { name = "ubuntu/images/*-24.04-*" } }
}
build {
  sources = ["source.amazon-ebs.web"]
  provisioner "shell" { script = "install.sh" }
}

Roll it out by replacement

  • New version = new image = new instances; old ones are terminated
  • Rollback is redeploying the previous image, not un-patching
  • No SSH-and-fix in production - changes go through the image pipeline
bash
# replace, don't mutate: new launch template version + instance refresh
aws autoscaling start-instance-refresh --auto-scaling-group-name web-asg
If you have to SSH into a box to fix it, the next identical box has the same bug waiting.

Containers make this the default (a new image per deploy), but the same discipline applies to VMs via Packer and instance refreshes. Rebuild, replace, and keep every server disposable.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult