9

How can I manage changes in desired capacity due to scaling policies in AutoScaling Group state in terraform?

Specifically, suppose I provision an aws_autoscaling_group resource with terraform with a desired_capacity of 4 and a scaleup policy on high CPU utilization. Later, the autoscaling group has updated via scaling policies to a desired capacity of 6 but this state isn't captured in my terraform .tfstate.

If I want to make a subsequent change to my autoscaling group state via terraform, how can I make the change without resetting the desired_capacity (since it has not changed in the .tf)? Can I automate updating the desired_capacity to match current group size somehow, or should I just not set desired_capacity at all?

chicks
  • 1,911
  • 1
  • 13
  • 29
Anthony Neace
  • 1,494
  • 1
  • 12
  • 17

1 Answers1

10

The desired_capacity in Terraform is marked in the documentation as optional. So with a proper min_size value, Terraform can wait until the minimum capacity is reached before continuing.

The above, with the addition of scale policy can effectively manage capacity without being specific about desired_capacity in your Terraform code. This will prevent you from having Terraform override the capacity in place at the moment of execution.

Evgeny Zislis
  • 9,023
  • 5
  • 39
  • 72