2 min read | by Jordi Prats
Some of the resources we create using terraform might be externally changed, for example an AutoScalingGroup desired_capacity can be changed externally (not modifying terraform's state) in order to handle more traffic. That's the case for the worker's ASG on an EKS cluster, which will be usually modified by the cluster autoscaler
(...)
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the last "terraform apply":
# module.eks.aws_autoscaling_group.workers["pet2cattle_eu-west-1a"] has been changed
~ resource "aws_autoscaling_group" "workers" {
~ desired_capacity = 7 -> 6
id = "pet2cattle_eu-west-1a2021082509502468370000000a"
name = "pet2cattle_eu-west-1a2021082509502468370000000a"
# (22 unchanged attributes hidden)
# (16 unchanged blocks hidden)
}
Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes.
(...)
So if we want terraform to ignore changes on the desired_capacity (for example,s of a given ASG) we will have to add the lifecycle block specifying which changes we want it to ignore using the ignore_changes option as follows:
resource "aws_autoscaling_group" "workers" {
(...)
lifecycle {
ignore_changes = [
desired_capacity, # managed by cluster-autoscaler
]
}
}
Now if we perform a terraform plan we will see that it's no longer trying to change the desired_capacity of this ASG
Posted on 13/10/2021