forked from terraform-community-modules/tf_aws_ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduled-scaling.tf
42 lines (36 loc) · 1.7 KB
/
scheduled-scaling.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
locals {
autoscaling_time_based_max = toset(var.autoscaling_time_based_max)
autoscaling_time_based_min = toset(var.autoscaling_time_based_min)
autoscaling_time_based_custom = {
for custom in toset(var.autoscaling_time_based_custom) : "${custom["min"]}-${custom["max"]} ${custom["cron"]}" => custom
}
}
resource "aws_autoscaling_schedule" "ecs_infrastructure_time_based_max" {
for_each = local.autoscaling_time_based_max
autoscaling_group_name = aws_autoscaling_group.ecs.name
scheduled_action_name = "asg-${aws_launch_template.ecs.name}-schedule-max ${each.value}"
time_zone = "Europe/London"
desired_capacity = var.max_servers
min_size = -1
max_size = -1
recurrence = each.value
}
resource "aws_autoscaling_schedule" "ecs_infrastructure_time_based_min" {
for_each = local.autoscaling_time_based_min
autoscaling_group_name = aws_autoscaling_group.ecs.name
scheduled_action_name = "asg-${aws_launch_template.ecs.name}-schedule-min ${each.value}"
time_zone = "Europe/London"
desired_capacity = var.min_servers
min_size = -1
max_size = -1
recurrence = each.value
}
resource "aws_autoscaling_schedule" "ecs_infrastructure_time_based_custom" {
for_each = local.autoscaling_time_based_custom
autoscaling_group_name = aws_autoscaling_group.ecs.name
scheduled_action_name = "asg-${aws_launch_template.ecs.name}-schedule-custom ${each.value["cron"]} ${each.value["min"]}-${each.value["max"]}"
desired_capacity = each.value["min"]
min_size = each.value["min"]
max_size = each.value["max"]
recurrence = each.value["cron"]
}