Skip to content
shiporbreak

No streak yet

Sign in

November 20, 2026 路 #65

TerraformHardOpen write-up

The plan that replaced every server

Nobody touched this module, yet today's plan replaces all 12 web servers at once. Which line made that happen?

data "aws_ami" "base" {
  most_recent = true
  owners      = ["amazon"]
  filter {
    name   = "name"
    values = ["al2023-ami-*-x86_64"]
  }
}

resource "aws_instance" "web" {
  count         = 12
  ami           = data.aws_ami.base.id
  instance_type = "t3.medium"
}

Next puzzle in UTC

One try. The first answer sticks.

How to fix it

The data source is read on every plan. A new Amazon Linux release changes the ID, and ami is a replace-on-change attribute, so all instances are recreated at once.

Data sources are not pinned. most_recent = true picks the newest image that matches the filter on every plan. Amazon publishes Amazon Linux 2023 images regularly, and when the ID changes, every aws_instance that references it shows -/+ must be replaced. With 12 instances under count, an unattended apply takes the whole fleet down together.

Fix

variable "web_ami" {
  description = "Pinned AMI, bumped by a reviewed PR"
  type        = string
}

resource "aws_instance" "web" {
  ami = var.web_ami
}

Or keep the lookup but add lifecycle { ignore_changes = [ami] } and roll images deliberately. Better still, run web servers in an Auto Scaling group with a launch template and instance refresh, which replaces a few at a time behind health checks.

Sponsor this spot

Put your tool on the puzzle
One labeled card, in front of engineers who show up every day from YouTube, TikTok, and Instagram.