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.
More on Import Refactoring Drift and Lifecycle
An S3 bucket was created by hand in the console and now must be managed by Terraform. How do you bring it in?BeginnerYou must adopt 200 existing resources and don't want to write all the HCL by hand.IntermediateHow do you find out that someone changed infrastructure outside Terraform?BeginnerSomeone opened port 22 on a security group in the console. Terraform wants to remove it. What's your process?IntermediateHow do you protect a production database from an accidental `terraform destroy`?BeginnerA load balancer's TLS certificate must be rotated with no outage.Intermediate