diff --git a/_variables.tf b/_variables.tf index 28235ea..4348cb9 100644 --- a/_variables.tf +++ b/_variables.tf @@ -511,32 +511,24 @@ variable "alarm_ecs_running_tasks_threshold" { description = "Alarm when the number of ecs service running tasks is lower than a certain value. CloudWatch Container Insights must be enabled for the cluster." } -variable "enable_schedule" { - default = false - type = bool - description = "Enables schedule to shut down and start up instances outside business hours." -} - variable "scale_in_schedules" { type = list(object({ cron = string name = string })) - default = null + default = null + description = "Cron expression to define when to trigger a stop of the auto-scaling group. E.g. 'cron(00 21 ? * SUN-THU *)' to start at 8am UTC time." } -variable "schedule_cron_start" { - type = string - default = "" +variable "scale_out_schedules" { + type = list(object({ + cron = string + name = string + })) + default = null description = "Cron expression to define when to trigger a start of the auto-scaling group. E.g. 'cron(00 21 ? * SUN-THU *)' to start at 8am UTC time." } -variable "schedule_cron_stop" { - type = string - default = "" - description = "Cron expression to define when to trigger a stop of the auto-scaling group. E.g. 'cron(00 09 ? * MON-FRI *)' to start at 8am UTC time" -} - variable "command" { type = list(string) default = null diff --git a/appautoscaling.tf b/appautoscaling.tf index 9a0bab4..6c564c0 100644 --- a/appautoscaling.tf +++ b/appautoscaling.tf @@ -91,6 +91,20 @@ resource "aws_appautoscaling_scheduled_action" "scale_in_schedules" { } } +resource "aws_appautoscaling_scheduled_action" "scale_out_schedules" { + for_each = { for schedule in var.scale_out_schedules : schedule.name => schedule } + name = "${var.name}-${each.key}-scale-out" + service_namespace = aws_appautoscaling_target.ecs[0].service_namespace + resource_id = aws_appautoscaling_target.ecs[0].resource_id + scalable_dimension = aws_appautoscaling_target.ecs[0].scalable_dimension + schedule = each.value.cron + timezone = var.schedule_timezone + scalable_target_action { + min_capacity = var.autoscaling_min + max_capacity = var.autoscaling_max + } +} + #resource "aws_appautoscaling_scheduled_action" "scale_service_in" { # count = var.enable_schedule ? 1 : 0 # name = "${var.name}-scale-in"