I have a common TF code for different regions in my AWS, and similarly have a common autoscaling block in TF for all my regions.
Now I want to do time-based scheduling for my ASG, but since the timezones are different in different regions. I am not able to do the same with TF, because I do not see any option to specify timezone in aws_autoscaling_schedule resource of TF.
Following is my code :
resource "aws_autoscaling_schedule" "schedule1" {
scheduled_action_name = "scale_down"
min_size = var.min_size
max_size = var.max_size
recurrence = "0 18 * * 5"
desired_capacity = var.min_size
autoscaling_group_name = aws_autoscaling_group.example_asg.name
}
Now If you see the recurrence, I want to do scale down at 6pm as per respective region timings, but I am not able to achieve the same because the default timezone is UTC.
PS: I have different vars file for every region. And getting max_size and min_size, separately for every region.
I tried manipulating the recurrence block by passing one var in every regions's var file. But doesn't seem to work getting error as we can not pass vars in recurrence block :
resource "aws_autoscaling_schedule" "schedule1" {
scheduled_action_name = "scale_down"
min_size = var.min_size
max_size = var.max_size
recurrence = "0 var.temp_var * * 5"
desired_capacity = var.min_size
autoscaling_group_name = aws_autoscaling_group.example_asg.name
}
Any idea how can I achieve the same. Any help is appreciated.
Thanks!
To overcome your error and to correctly pass var.temp_var
into recurrence
you should do:
recurrence = "0 ${var.temp_var} * * 5"