diff --git a/main.tf b/main.tf index 0644e12..8999098 100644 --- a/main.tf +++ b/main.tf @@ -105,5 +105,7 @@ module "ecs" { sg_egress_with_cidr_blocks = var.ecs_sg_egress_with_cidr_blocks vpc_id = local.vpc_id + container_scale_up_when_cpu_pct_above = var.autoscaling_cpu_threshold_pct + depends_on = [module.lb] } diff --git a/modules/ecs/main.tf b/modules/ecs/main.tf index ad73979..24c40bb 100644 --- a/modules/ecs/main.tf +++ b/modules/ecs/main.tf @@ -162,22 +162,6 @@ resource "aws_appautoscaling_target" "superblocks" { service_namespace = "ecs" } -resource "aws_appautoscaling_policy" "memory" { - name = "${var.name_prefix}-scaling-policy-memory" - policy_type = "TargetTrackingScaling" - resource_id = aws_appautoscaling_target.superblocks.resource_id - scalable_dimension = aws_appautoscaling_target.superblocks.scalable_dimension - service_namespace = aws_appautoscaling_target.superblocks.service_namespace - - target_tracking_scaling_policy_configuration { - predefined_metric_specification { - predefined_metric_type = "ECSServiceAverageMemoryUtilization" - } - - target_value = var.container_scale_up_when_memory_pct_above - } -} - resource "aws_appautoscaling_policy" "cpu" { name = "${var.name_prefix}-scaling-policy-cpu" policy_type = "TargetTrackingScaling" diff --git a/variables.tf b/variables.tf index 3beefcb..dd681d5 100644 --- a/variables.tf +++ b/variables.tf @@ -369,3 +369,9 @@ variable "additional_ecs_execution_task_policy_arns" { default = [] description = "List of ARNs of Additional iam policy to attach to the ECS execution role" } + +variable "autoscaling_cpu_threshold_pct" { + type = number + default = 90 + description = "The CPU threshold percentage at which the autoscaling policy will scale up the number of tasks." +}