module-base-ecs-appasg-ttscaling-predefined

This terraform module creates an ECS Application AutoScaling Target Tracking Scaling Policy with policies predefined and scheduled actions

This resources are only attached to the specific ECS Service, if you remove the service, this policies and scheduled actions are remove. If you makes changes in ECS Service which required #force replacement in the ECS Service, this policies an schedule are removed and you need apply this terraform them again

Usage example

Application AutoScaling Target Tracking Scaling Policy: ECSServiceAverageMemoryUtilization and ECSServiceAverageCPUUtilization

module "appasg" {
 source = "git::https://gitlab.vectoritcgroup.com/vectordigital/iac/terraform/modules/aws/compute/module-base-ecs-appasg-ttscaling-predefined.git?ref=vX.Y.Z"

 aws_region = var.aws_region
 prefix     = var.prefix

 cluster_name = module.cluster.cluster_name
 service_name = module.nginx.service_name

 target_min_capacity = 2
 target_max_capacity = 4

 predefined_policy = {
   "memory-avg" = {
     disable_scale_in       = false
     target_value           = 60
     predefined_metric_type = "ECSServiceAverageMemoryUtilization"
     scale_in_cooldown      = 0
     scale_out_cooldown     = 0
   },
   "cpu-avg" = {
     disable_scale_in       = false
     target_value           = 80
     predefined_metric_type = "ECSServiceAverageCPUUtilization"
     scale_in_cooldown      = 0
     scale_out_cooldown     = 0
   }
 }

 tags = {
   "Project"     = "test"
   "Environment" = "basic"
 }
}

Application AutoScaling Target Tracking Scaling Policy: ECSServiceAverageMemoryUtilization, ECSServiceAverageCPUUtilization and ALBRequestCountPerTarget

module "appasg" {
 source = "git::https://gitlab.vectoritcgroup.com/vectordigital/iac/terraform/modules/aws/compute/module-base-ecs-appasg-ttscaling-predefined.git?ref=vX.Y.Z"

 aws_region = var.aws_region
 prefix     = var.prefix

 cluster_name = module.cluster.cluster_name
 service_name = module.nginx.service_name

 target_min_capacity = 2
 target_max_capacity = 4

 predefined_policy = {
   "memory-avg" = {
     disable_scale_in       = false
     target_value           = 60
     predefined_metric_type = "ECSServiceAverageMemoryUtilization"
     scale_in_cooldown      = 300
     scale_out_cooldown     = 120
   },
   "cpu-avg" = {
     disable_scale_in       = false
     target_value           = 80
     predefined_metric_type = "ECSServiceAverageCPUUtilization"
     scale_in_cooldown      = 300
     scale_out_cooldown     = 120
   }
 }

 predefined_requests_policy = {
   "request-count" = {
     disable_scale_in         = false
     target_value             = 1000
     load_balancer_arn_suffix = module.alb.alb_arn_suffix
     target_group_arn_suffix  = module.nginx.target_group_arn_suffix
     scale_in_cooldown        = 300
     scale_out_cooldown       = 120
   }
 }

 tags = {
   "Project"     = "test"
   "Environment" = "basic"
 }
}

Application AutoScaling Target Tracking Scaling Policy: ECSServiceAverageMemoryUtilization, ECSServiceAverageCPUUtilization and schedulen actions

module "appasg" {
 source = "git::https://gitlab.vectoritcgroup.com/vectordigital/iac/terraform/modules/aws/compute/module-base-ecs-appasg-ttscaling-predefined.git?ref=vX.Y.Z"

 aws_region = local.aws_region
 prefix     = local.prefix

 cluster_name = module.cluster.cluster_name
 service_name = module.nginx.service_name

 target_min_capacity = 2
 target_max_capacity = 4

 predefined_policy = {
   "memory-avg" = {
     disable_scale_in       = false
     target_value           = 60
     predefined_metric_type = "ECSServiceAverageMemoryUtilization"
     scale_in_cooldown      = 300
     scale_out_cooldown     = 120
   },
   "cpu-avg" = {
     disable_scale_in       = false
     target_value           = 80
     predefined_metric_type = "ECSServiceAverageCPUUtilization"
     scale_in_cooldown      = 300
     scale_out_cooldown     = 120
   }
 }

 scheduled_actions = {
   "start" = {
     scheduled_action_cron         = "cron(58 12 ? * MON-FRI *)"
     scheduled_action_min_capacity = 2
     scheduled_action_max_capacity = 4
   },
   "stop" = {
     scheduled_action_cron         = "cron(12 13 ? * MON-FRI *)"
     scheduled_action_min_capacity = 0
     scheduled_action_max_capacity = 0
   },
   "weekend-start" = {
     scheduled_action_cron         = "cron(00 8 ? * SAT *)"
     scheduled_action_min_capacity = 0
     scheduled_action_max_capacity = 0
   },
   "weekend-stop" = {
     scheduled_action_cron         = "cron(00 20 ? * SUN *)"
     scheduled_action_min_capacity = 0
     scheduled_action_max_capacity = 0
   }
 }

 tags = {
   "Project"     = "test"
   "Environment" = "basic"
 }
}

Module argument reference

Modules

No modules.

Inputs

Name Description Type Default Required

AWS Region name where you deploy VPC

string

n/a

yes

The Cluster name for all resources

string

n/a

yes

A list of objects for create predefined policies for CPU and Memory. The valid values for predefined_metric_type are: ECSServiceAverageMemoryUtilization for memory and ECSServiceAverageCPUUtilization for CPU

map(object({
    disable_scale_in       = bool   // Indicates whether scale in by the target tracking policy is disabled. If the value is true, scale in is disabled and the target tracking policy won't remove capacity from the scalable resource. Otherwise, scale in is enabled and the target tracking policy can remove capacity from the scalable resource
    target_value           = number // The target value for the metric
    predefined_metric_type = string // A predefined metric. See supported fields below
    scale_in_cooldown      = number // The amount of time, in seconds, after a scale in activity completes before another scale in activity can start
    scale_out_cooldown     = number // The amount of time, in seconds, after a scale out activity completes before another scale out activity can start
  }))

{}

no

A list of objects for create predefined policy for Load Balancer request count per target

map(object({
    disable_scale_in         = bool   // Indicates whether scale in by the target tracking policy is disabled. If the value is true, scale in is disabled and the target tracking policy won't remove capacity from the scalable resource. Otherwise, scale in is enabled and the target tracking policy can remove capacity from the scalable resource
    target_value             = number // The target value for the metric
    load_balancer_arn_suffix = string
    target_group_arn_suffix  = string
    scale_in_cooldown        = number // The amount of time, in seconds, after a scale in activity completes before another scale in activity can start
    scale_out_cooldown       = number // The amount of time, in seconds, after a scale out activity completes before another scale out activity can start
  }))

{}

no

The prefix to be attached to every resource name

string

n/a

yes

A list of objects for create scheduled actions for application autoscaling

map(object({
    scheduled_action_cron         = string
    scheduled_action_min_capacity = number
    scheduled_action_max_capacity = number
  }))

{}

no

The Service name for naming all resources

string

n/a

yes

Specific tags for all module resources

map(string)

n/a

yes

The max capacity of the scalable target

number

n/a

yes

The min capacity of the scalable target

number

n/a

yes

Outputs

No outputs.