From 9edd15bbf3c4313efa01b7f44714a53a6dc81426 Mon Sep 17 00:00:00 2001 From: Andy B <51922180+brooksClo19@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:24:14 -0700 Subject: [PATCH] adding memory based autoscaling --- autoscaling.tf | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/autoscaling.tf b/autoscaling.tf index 99a9de0..a0f97aa 100644 --- a/autoscaling.tf +++ b/autoscaling.tf @@ -15,7 +15,7 @@ resource "aws_appautoscaling_target" "target" { ## App Autoscaling Policy ## ############################ -resource "aws_appautoscaling_policy" "auto_scaling" { +resource "aws_appautoscaling_policy" "auto_scaling_cpu" { count = var.enable_asg ? 1 : 0 name = "${var.environment}-${var.name}-cpu-scale" @@ -36,4 +36,27 @@ resource "aws_appautoscaling_policy" "auto_scaling" { depends_on = [aws_appautoscaling_target.target] -} \ No newline at end of file +} + +resource "aws_appautoscaling_policy" "auto_scaling_mem" { + + count = var.enable_asg ? 1 : 0 + name = "${var.environment}-${var.name}-mem-scale" + policy_type = "TargetTrackingScaling" + resource_id = aws_appautoscaling_target.target[0].resource_id + service_namespace = aws_appautoscaling_target.target[0].service_namespace + scalable_dimension = aws_appautoscaling_target.target[0].scalable_dimension + + target_tracking_scaling_policy_configuration { + target_value = var.asg_threshold_mem_to_scale_up + scale_in_cooldown = var.asg_cooldown_to_scale_up_again + scale_out_cooldown = var.asg_cooldown_to_scale_up_again + + predefined_metric_specification { + predefined_metric_type = "ECSServiceAverageMemoryUtilization" + } + } + + depends_on = [aws_appautoscaling_target.target] + +}