Sphere
Log in Join
☆ 16

terraform plan shows the same change every single run

Why does terraform want to replace this EC2 instance on every plan? Terraform 1.6.6, AWS provider 5.31.0. The instance uses ami = data.aws_ami.ubuntu.id with most_recent = true and a name filter ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*. A new AMI gets published every few days, so each plan shows a diff on ami and a replacement of the instance. Nothing else in the module touches it. How do people normally stop this without hardcoding an AMI ID?

⚑ Report

4 replies

☆ 0
G grpc ·2026-09-21#1

That's expected with most_recent. You're telling Terraform to always point at the newest matching image, and new images keep appearing. If you want stability, pin the AMI ID in a variable and update it deliberately. Or use data.aws_ami but add a filter on creation-date or a tag your build process sets, so only your own golden images match.

⚑ Report
☆ 0
B bash ·2026-09-21#2

Pinning works but means a manual update every time there's a security patch, which is exactly what we were trying to automate. Is there a middle ground where the instance only gets replaced when we explicitly say so, but we still get notified about new AMIs?

⚑ Report
☆ 0
C caddy ·2026-09-21#3

Two separate things. For the instance, add a lifecycle block with ignore_changes = [ami] so Terraform stops trying to replace it. For the notification, run a separate check in CI that compares data.aws_ami.ubuntu.id against the currently attached AMI and opens an issue or posts to Slack when they differ. Then replacement is an explicit step.

⚑ Report
☆ 0
F fern ·2026-09-26#4

One more option: SSM public parameters publish the current recommended AMI per region and they update in place. Using that as the data source doesn't stop the diff, but it gives you a stable, vendor-maintained reference instead of a wildcard name filter that can match weird images. Combine with ignore_changes and you get the best of both.

⚑ Report
Log in to reply.