Interview Prep/Terraform/Import Refactoring Drift and Lifecycle

An Auto Scaling group's desired capacity is changed by autoscaling, and Terraform keeps resetting it.

IntermediateScenarioImport Refactoring Drift and Lifecycle
Answer

Situation read → Another system legitimately owns this attribute.

What I'd do → Tell Terraform to ignore it.

resource "aws_autoscaling_group" "web" {
  min_size         = 2
  max_size         = 20
  desired_capacity = 2
  lifecycle {
    ignore_changes = [desired_capacity]
  }
}

Why → ignore_changes removes that attribute from diff computation; the initial value is still set at creation.

Interview tip → Use it for attributes owned by other controllers (HPA, ASG, image pipelines), not to hide mistakes.

All Terraform questions Roadmap: Terraform in production

More on Import Refactoring Drift and Lifecycle