diff --git a/infrastructure/deploy/ecs_services.tf b/infrastructure/deploy/ecs_services.tf index 8056e3004..8fdb2af27 100644 --- a/infrastructure/deploy/ecs_services.tf +++ b/infrastructure/deploy/ecs_services.tf @@ -90,3 +90,41 @@ resource "aws_ecs_service" "meadow_all" { tags = var.tags } + +resource "aws_appautoscaling_target" "ecs_target" { + max_capacity = 2 + min_capacity = 1 + resource_id = "service/${ aws_ecs_cluster.meadow.name}/${aws_ecs_service.meadow.name}" + scalable_dimension = "ecs:service:DesiredCount" + service_namespace = "ecs" +} + +# Scheduled action to scale UP at 7:15 AM Central +resource "aws_appautoscaling_scheduled_action" "scale_up" { + name = "scale-up-to-2-tasks" + service_namespace = aws_appautoscaling_target.ecs_target.service_namespace + resource_id = aws_appautoscaling_target.ecs_target.resource_id + scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension + + schedule = "cron(15 13 ? * MON-FRI *)" # 7:15 AM Central in UTC (13:15 UTC) + + scalable_target_action { + min_capacity = 2 + max_capacity = 2 + } +} + +# Scheduled action to scale DOWN at 6:00 PM Central +resource "aws_appautoscaling_scheduled_action" "scale_down" { + name = "scale-down-to-1-task" + service_namespace = aws_appautoscaling_target.ecs_target.service_namespace + resource_id = aws_appautoscaling_target.ecs_target.resource_id + scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension + + schedule = "cron(0 0 ? * MON-FRI *)" # 6:00 PM Central in UTC (00:00 UTC next day) + + scalable_target_action { + min_capacity = 1 + max_capacity = 1 + } +}