Interview Prep/Terraform/Lost, Corrupted and Drifted State

Every plan wants to change `desired_capacity` on an Auto Scaling group back to 2, though autoscaling has raised it to 6.

BeginnerTroubleshootingLost, Corrupted and Drifted State
Answer

Likely causes → Terraform manages an attribute that something else (scaling policies, Karpenter, a human) also manages. That's expected drift, not a Terraform bug.

Diagnose → terraform plan shows ~ desired_capacity = 6 -> 2.

Fix →

resource "aws_autoscaling_group" "web" {
  # ...
  lifecycle {
    ignore_changes = [desired_capacity]
  }
}

Or don't set desired_capacity at all.

Prevent → For every attribute, pick one owner. Same pattern for ECS desired_count with service autoscaling.

All Terraform questions Roadmap: Terraform in production

More on Lost, Corrupted and Drifted State