Interview Prep/Terraform/Import Refactoring Drift and Lifecycle

A new AMI release makes Terraform want to replace every EC2 instance in prod. How do you control this?

IntermediateScenarioImport Refactoring Drift and Lifecycle
Answer

Situation read → most_recent AMI lookups change the AMI attribute, which forces replacement.

What I'd do →

  1. Pin the AMI ID per environment via a variable.
  2. Promote new AMIs through dev and stage first.
  3. For fleets, use a launch template plus an ASG with instance_refresh so rollout is rolling instead of all-at-once.

Why → You choose when a new image reaches prod, and rollouts replace instances gradually.

Interview tip → ignore_changes = [ami] hides the problem; use it only where an external pipeline owns the AMI.

All Terraform questions Roadmap: Terraform in production

More on Import Refactoring Drift and Lifecycle