Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of autoscaling metric #38

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
16 changes: 0 additions & 16 deletions modules/ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}