From aa460903e0389dbaeb1794913d7b29ca673dad40 Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Thu, 2 Jun 2022 16:54:55 -0600 Subject: [PATCH 1/9] initial --- main.tf | 44 ++++++++++++++++++++++---------------------- variables.tf | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/main.tf b/main.tf index e5452cb..259d994 100644 --- a/main.tf +++ b/main.tf @@ -558,13 +558,13 @@ resource "aws_appautoscaling_policy" "up" { service_namespace = aws_appautoscaling_target.default[0].service_namespace step_scaling_policy_configuration { - adjustment_type = "ChangeInCapacity" - metric_aggregation_type = "Average" - cooldown = 300 + adjustment_type = var.autoscaling_advanced_config.up_adjustment_type + metric_aggregation_type = var.autoscaling_advanced_config.up_metric_aggregation_type + cooldown = var.autoscaling_advanced_config.up_cooldown step_adjustment { - scaling_adjustment = 1 - metric_interval_lower_bound = 0 + scaling_adjustment = var.autoscaling_advanced_config.up_scaling_adjustment + metric_interval_lower_bound = var.autoscaling_advanced_config.up_metric_interval_lower_bound } } } @@ -576,12 +576,12 @@ resource "aws_cloudwatch_metric_alarm" "up" { ClusterName = local.cluster_name ServiceName = aws_ecs_service.service.name } - statistic = "Average" - metric_name = "CPUUtilization" - comparison_operator = "GreaterThanThreshold" - threshold = 75 - period = 300 - evaluation_periods = 5 + statistic = var.autoscaling_advanced_config.up_statistic + metric_name = var.autoscaling_advanced_config.up_metric_name + comparison_operator = var.autoscaling_advanced_config.up_comparison_operator + threshold = var.autoscaling_advanced_config.up_threshold + period = var.autoscaling_advanced_config.up_period + evaluation_periods = var.autoscaling_advanced_config.up_evaluation_periods alarm_actions = [aws_appautoscaling_policy.up[0].arn] tags = var.tags } @@ -593,13 +593,13 @@ resource "aws_appautoscaling_policy" "down" { service_namespace = aws_appautoscaling_target.default[0].service_namespace step_scaling_policy_configuration { - adjustment_type = "ChangeInCapacity" - metric_aggregation_type = "Average" - cooldown = 300 + adjustment_type = var.autoscaling_advanced_config.down_adjustment_type + metric_aggregation_type = var.autoscaling_advanced_config.down_metric_aggregation_type + cooldown = var.autoscaling_advanced_config.down_cooldown step_adjustment { - scaling_adjustment = -1 - metric_interval_upper_bound = 0 + scaling_adjustment = var.autoscaling_advanced_config.down_scaling_adjustment + metric_interval_upper_bound = var.autoscaling_advanced_config.down_metric_interval_upper_bound } } } @@ -611,12 +611,12 @@ resource "aws_cloudwatch_metric_alarm" "down" { ClusterName = local.cluster_name ServiceName = aws_ecs_service.service.name } - statistic = "Average" - metric_name = "CPUUtilization" - comparison_operator = "LessThanThreshold" - threshold = 25 - period = 300 - evaluation_periods = 5 + statistic = var.autoscaling_advanced_config.down_statistic + metric_name = var.autoscaling_advanced_config.down_metric_name + comparison_operator = var.autoscaling_advanced_config.down_comparison_operator + threshold = var.autoscaling_advanced_config.down_threshold + period = var.autoscaling_advanced_config.down_period + evaluation_periods = var.autoscaling_advanced_config.down_evaluation_periods alarm_actions = [aws_appautoscaling_policy.down[0].arn] tags = var.tags } diff --git a/variables.tf b/variables.tf index 066a4ca..98321eb 100644 --- a/variables.tf +++ b/variables.tf @@ -202,6 +202,58 @@ variable "autoscaling_config" { }) description = "Configuration for default autoscaling policies and alarms. Set to null if you want to set up your own autoscaling policies and alarms." } + +variable "autoscaling_advanced_config" { + type = object({ + up_adjustment_type = string + up_metric_aggregation_type = string + up_cooldown = number + up_scaling_adjustment = number + up_metric_interval_lower_bound = number + up_statistic = string + up_metric_name = string + up_comparison_operator = string + up_threshold = number + up_period = number + up_evaluation_periods = number + down_adjustment_type = string + down_metric_aggregation_type = string + down_cooldown = number + down_scaling_adjustment = number + down_metric_interval_upper_bound = number + down_statistic = string + down_metric_name = string + down_comparison_operator = string + down_threshold = number + down_period = number + down_evaluation_periods = number + }) + description = "Adjust the configuration for scaling. Limited to ECS metrics." + default = { + up_adjustment_type = "ChangeInCapacity" + up_metric_aggregation_type = "Average" + up_cooldown = 300 + up_scaling_adjustment = 1 + up_metric_interval_lower_bound = 0 + up_statistic = "Average" + up_metric_name = "CPUUtilization" + up_comparison_operator = "GreaterThanThreshold" + up_threshold = 75 + up_period = 300 + up_evaluation_periods = 5 + down_adjustment_type = "ChangeInCapacity" + down_metric_aggregation_type = "Average" + down_cooldown = 300 + down_scaling_adjustment = -1 + down_metric_interval_upper_bound = 0 + down_statistic = "Average" + down_metric_name = "CPUUtilization" + down_comparison_operator = "LessThanThreshold" + down_threshold = 25 + down_period = 300 + down_evaluation_periods = 5 + } +} variable "log_group_name" { type = string description = "CloudWatch log group name." From a171a05dc86723c3fc6d7d306584d713c3114da4 Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Thu, 2 Jun 2022 17:07:02 -0600 Subject: [PATCH 2/9] pull vars into object --- main.tf | 44 ++++++++++----------- variables.tf | 106 +++++++++++++++++++++++++++++---------------------- 2 files changed, 83 insertions(+), 67 deletions(-) diff --git a/main.tf b/main.tf index 259d994..fde6ccd 100644 --- a/main.tf +++ b/main.tf @@ -558,13 +558,13 @@ resource "aws_appautoscaling_policy" "up" { service_namespace = aws_appautoscaling_target.default[0].service_namespace step_scaling_policy_configuration { - adjustment_type = var.autoscaling_advanced_config.up_adjustment_type - metric_aggregation_type = var.autoscaling_advanced_config.up_metric_aggregation_type - cooldown = var.autoscaling_advanced_config.up_cooldown + adjustment_type = var.autoscaling_advanced_config.up_scaling_policy_config.adjustment_type + metric_aggregation_type = var.autoscaling_advanced_config.up_scaling_policy_config.metric_aggregation_type + cooldown = var.autoscaling_advanced_config.up_scaling_policy_config.cooldown step_adjustment { - scaling_adjustment = var.autoscaling_advanced_config.up_scaling_adjustment - metric_interval_lower_bound = var.autoscaling_advanced_config.up_metric_interval_lower_bound + scaling_adjustment = var.autoscaling_advanced_config.up_scaling_policy_config.scaling_adjustment + metric_interval_lower_bound = var.autoscaling_advanced_config.up_scaling_policy_config.metric_interval_lower_bound } } } @@ -576,12 +576,12 @@ resource "aws_cloudwatch_metric_alarm" "up" { ClusterName = local.cluster_name ServiceName = aws_ecs_service.service.name } - statistic = var.autoscaling_advanced_config.up_statistic - metric_name = var.autoscaling_advanced_config.up_metric_name - comparison_operator = var.autoscaling_advanced_config.up_comparison_operator - threshold = var.autoscaling_advanced_config.up_threshold - period = var.autoscaling_advanced_config.up_period - evaluation_periods = var.autoscaling_advanced_config.up_evaluation_periods + statistic = var.autoscaling_advanced_config.up_alarm_config.statistic + metric_name = var.autoscaling_advanced_config.up_alarm_config.metric_name + comparison_operator = var.autoscaling_advanced_config.up_alarm_config.comparison_operator + threshold = var.autoscaling_advanced_config.up_alarm_config.threshold + period = var.autoscaling_advanced_config.up_alarm_config.period + evaluation_periods = var.autoscaling_advanced_config.up_alarm_config.evaluation_periods alarm_actions = [aws_appautoscaling_policy.up[0].arn] tags = var.tags } @@ -593,13 +593,13 @@ resource "aws_appautoscaling_policy" "down" { service_namespace = aws_appautoscaling_target.default[0].service_namespace step_scaling_policy_configuration { - adjustment_type = var.autoscaling_advanced_config.down_adjustment_type - metric_aggregation_type = var.autoscaling_advanced_config.down_metric_aggregation_type - cooldown = var.autoscaling_advanced_config.down_cooldown + adjustment_type = var.autoscaling_advanced_config.down_scaling_policy_config.adjustment_type + metric_aggregation_type = var.autoscaling_advanced_config.down_scaling_policy_config.metric_aggregation_type + cooldown = var.autoscaling_advanced_config.down_scaling_policy_config.cooldown step_adjustment { - scaling_adjustment = var.autoscaling_advanced_config.down_scaling_adjustment - metric_interval_upper_bound = var.autoscaling_advanced_config.down_metric_interval_upper_bound + scaling_adjustment = var.autoscaling_advanced_config.down_scaling_policy_config.adjustment_type + metric_interval_upper_bound = var.autoscaling_advanced_config.down_scaling_policy_config.metric_interval_upper_bound } } } @@ -611,12 +611,12 @@ resource "aws_cloudwatch_metric_alarm" "down" { ClusterName = local.cluster_name ServiceName = aws_ecs_service.service.name } - statistic = var.autoscaling_advanced_config.down_statistic - metric_name = var.autoscaling_advanced_config.down_metric_name - comparison_operator = var.autoscaling_advanced_config.down_comparison_operator - threshold = var.autoscaling_advanced_config.down_threshold - period = var.autoscaling_advanced_config.down_period - evaluation_periods = var.autoscaling_advanced_config.down_evaluation_periods + statistic = var.autoscaling_advanced_config.down_alarm_config.statistic + metric_name = var.autoscaling_advanced_config.down_alarm_config.metric_name + comparison_operator = var.autoscaling_advanced_config.down_alarm_config.comparison_operator + threshold = var.autoscaling_advanced_config.down_alarm_config.threshold + period = var.autoscaling_advanced_config.down_alarm_config.period + evaluation_periods = var.autoscaling_advanced_config.down_alarm_config.evaluation_periods alarm_actions = [aws_appautoscaling_policy.down[0].arn] tags = var.tags } diff --git a/variables.tf b/variables.tf index 98321eb..642182d 100644 --- a/variables.tf +++ b/variables.tf @@ -205,53 +205,69 @@ variable "autoscaling_config" { variable "autoscaling_advanced_config" { type = object({ - up_adjustment_type = string - up_metric_aggregation_type = string - up_cooldown = number - up_scaling_adjustment = number - up_metric_interval_lower_bound = number - up_statistic = string - up_metric_name = string - up_comparison_operator = string - up_threshold = number - up_period = number - up_evaluation_periods = number - down_adjustment_type = string - down_metric_aggregation_type = string - down_cooldown = number - down_scaling_adjustment = number - down_metric_interval_upper_bound = number - down_statistic = string - down_metric_name = string - down_comparison_operator = string - down_threshold = number - down_period = number - down_evaluation_periods = number + up_scaling_policy_config = object({ + adjustment_type = string + metric_aggregation_type = string + cooldown = number + scaling_adjustment = number + metric_interval_lower_bound = number + }) + up_alarm_config = object({ + statistic = string + metric_name = string + comparison_operator = string + threshold = number + period = number + evaluation_periods = number + }) + down_scaling_policy_config = object({ + adjustment_type = string + metric_aggregation_type = string + cooldown = number + scaling_adjustment = number + metric_interval_upper_bound = number + }) + down_alarm_config = object({ + statistic = string + metric_name = string + comparison_operator = string + threshold = number + period = number + evaluation_periods = number + }) }) - description = "Adjust the configuration for scaling. Limited to ECS metrics." + description = "Adjust the advanced configuration for scaling. Limited to ECS metrics." default = { - up_adjustment_type = "ChangeInCapacity" - up_metric_aggregation_type = "Average" - up_cooldown = 300 - up_scaling_adjustment = 1 - up_metric_interval_lower_bound = 0 - up_statistic = "Average" - up_metric_name = "CPUUtilization" - up_comparison_operator = "GreaterThanThreshold" - up_threshold = 75 - up_period = 300 - up_evaluation_periods = 5 - down_adjustment_type = "ChangeInCapacity" - down_metric_aggregation_type = "Average" - down_cooldown = 300 - down_scaling_adjustment = -1 - down_metric_interval_upper_bound = 0 - down_statistic = "Average" - down_metric_name = "CPUUtilization" - down_comparison_operator = "LessThanThreshold" - down_threshold = 25 - down_period = 300 - down_evaluation_periods = 5 + up_scaling_policy_config = { + adjustment_type = "ChangeInCapacity" + metric_aggregation_type = "Average" + cooldown = 300 + scaling_adjustment = 1 + metric_interval_lower_bound = 0 + } + up_alarm_config = { + statistic = "Average" + metric_name = "CPUUtilization" + comparison_operator = "GreaterThanThreshold" + threshold = 75 + period = 300 + evaluation_periods = 5 + } + down_scaling_policy_config = { + adjustment_type = "ChangeInCapacity" + metric_aggregation_type = "Average" + cooldown = 300 + scaling_adjustment = -1 + metric_interval_upper_bound = 0 + } + down_alarm_config = { + statistic = "Average" + metric_name = "CPUUtilization" + comparison_operator = "LessThanThreshold" + threshold = 25 + period = 300 + evaluation_periods = 5 + } } } variable "log_group_name" { From ee486f56ffe069e94e894a5a7d6ccfc548238ef5 Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Thu, 2 Jun 2022 17:20:59 -0600 Subject: [PATCH 3/9] diffent variables --- main.tf | 44 +++++++++--------- variables.tf | 128 ++++++++++++++++++++++++++------------------------- 2 files changed, 88 insertions(+), 84 deletions(-) diff --git a/main.tf b/main.tf index fde6ccd..3fcf787 100644 --- a/main.tf +++ b/main.tf @@ -558,13 +558,13 @@ resource "aws_appautoscaling_policy" "up" { service_namespace = aws_appautoscaling_target.default[0].service_namespace step_scaling_policy_configuration { - adjustment_type = var.autoscaling_advanced_config.up_scaling_policy_config.adjustment_type - metric_aggregation_type = var.autoscaling_advanced_config.up_scaling_policy_config.metric_aggregation_type - cooldown = var.autoscaling_advanced_config.up_scaling_policy_config.cooldown + adjustment_type = var.up_scaling_policy_config.adjustment_type + metric_aggregation_type = var.up_scaling_policy_config.metric_aggregation_type + cooldown = var.up_scaling_policy_config.cooldown step_adjustment { - scaling_adjustment = var.autoscaling_advanced_config.up_scaling_policy_config.scaling_adjustment - metric_interval_lower_bound = var.autoscaling_advanced_config.up_scaling_policy_config.metric_interval_lower_bound + scaling_adjustment = var.up_scaling_policy_config.scaling_adjustment + metric_interval_lower_bound = var.up_scaling_policy_config.metric_interval_lower_bound } } } @@ -576,12 +576,12 @@ resource "aws_cloudwatch_metric_alarm" "up" { ClusterName = local.cluster_name ServiceName = aws_ecs_service.service.name } - statistic = var.autoscaling_advanced_config.up_alarm_config.statistic - metric_name = var.autoscaling_advanced_config.up_alarm_config.metric_name - comparison_operator = var.autoscaling_advanced_config.up_alarm_config.comparison_operator - threshold = var.autoscaling_advanced_config.up_alarm_config.threshold - period = var.autoscaling_advanced_config.up_alarm_config.period - evaluation_periods = var.autoscaling_advanced_config.up_alarm_config.evaluation_periods + statistic = var.up_metric_alarm_config.statistic + metric_name = var.up_metric_alarm_config.metric_name + comparison_operator = var.up_metric_alarm_config.comparison_operator + threshold = var.up_metric_alarm_config.threshold + period = var.up_metric_alarm_config.period + evaluation_periods = var.up_metric_alarm_config.evaluation_periods alarm_actions = [aws_appautoscaling_policy.up[0].arn] tags = var.tags } @@ -593,13 +593,13 @@ resource "aws_appautoscaling_policy" "down" { service_namespace = aws_appautoscaling_target.default[0].service_namespace step_scaling_policy_configuration { - adjustment_type = var.autoscaling_advanced_config.down_scaling_policy_config.adjustment_type - metric_aggregation_type = var.autoscaling_advanced_config.down_scaling_policy_config.metric_aggregation_type - cooldown = var.autoscaling_advanced_config.down_scaling_policy_config.cooldown + adjustment_type = var.down_scaling_policy_config.adjustment_type + metric_aggregation_type = var.down_scaling_policy_config.metric_aggregation_type + cooldown = var.down_scaling_policy_config.cooldown step_adjustment { - scaling_adjustment = var.autoscaling_advanced_config.down_scaling_policy_config.adjustment_type - metric_interval_upper_bound = var.autoscaling_advanced_config.down_scaling_policy_config.metric_interval_upper_bound + scaling_adjustment = var.down_scaling_policy_config.adjustment_type + metric_interval_upper_bound = var.down_scaling_policy_config.metric_interval_upper_bound } } } @@ -611,12 +611,12 @@ resource "aws_cloudwatch_metric_alarm" "down" { ClusterName = local.cluster_name ServiceName = aws_ecs_service.service.name } - statistic = var.autoscaling_advanced_config.down_alarm_config.statistic - metric_name = var.autoscaling_advanced_config.down_alarm_config.metric_name - comparison_operator = var.autoscaling_advanced_config.down_alarm_config.comparison_operator - threshold = var.autoscaling_advanced_config.down_alarm_config.threshold - period = var.autoscaling_advanced_config.down_alarm_config.period - evaluation_periods = var.autoscaling_advanced_config.down_alarm_config.evaluation_periods + statistic = var.down_metric_alarm_config.statistic + metric_name = var.down_metric_alarm_config.metric_name + comparison_operator = var.down_metric_alarm_config.comparison_operator + threshold = var.down_metric_alarm_config.threshold + period = var.down_metric_alarm_config.period + evaluation_periods = var.down_metric_alarm_config.evaluation_periods alarm_actions = [aws_appautoscaling_policy.down[0].arn] tags = var.tags } diff --git a/variables.tf b/variables.tf index 642182d..6001aff 100644 --- a/variables.tf +++ b/variables.tf @@ -203,71 +203,75 @@ variable "autoscaling_config" { description = "Configuration for default autoscaling policies and alarms. Set to null if you want to set up your own autoscaling policies and alarms." } -variable "autoscaling_advanced_config" { +variable "up_scaling_policy_config" { type = object({ - up_scaling_policy_config = object({ - adjustment_type = string - metric_aggregation_type = string - cooldown = number - scaling_adjustment = number - metric_interval_lower_bound = number - }) - up_alarm_config = object({ - statistic = string - metric_name = string - comparison_operator = string - threshold = number - period = number - evaluation_periods = number - }) - down_scaling_policy_config = object({ - adjustment_type = string - metric_aggregation_type = string - cooldown = number - scaling_adjustment = number - metric_interval_upper_bound = number - }) - down_alarm_config = object({ - statistic = string - metric_name = string - comparison_operator = string - threshold = number - period = number - evaluation_periods = number - }) + adjustment_type = string + metric_aggregation_type = string + cooldown = number + scaling_adjustment = number + metric_interval_lower_bound = number }) - description = "Adjust the advanced configuration for scaling. Limited to ECS metrics." default = { - up_scaling_policy_config = { - adjustment_type = "ChangeInCapacity" - metric_aggregation_type = "Average" - cooldown = 300 - scaling_adjustment = 1 - metric_interval_lower_bound = 0 - } - up_alarm_config = { - statistic = "Average" - metric_name = "CPUUtilization" - comparison_operator = "GreaterThanThreshold" - threshold = 75 - period = 300 - evaluation_periods = 5 - } - down_scaling_policy_config = { - adjustment_type = "ChangeInCapacity" - metric_aggregation_type = "Average" - cooldown = 300 - scaling_adjustment = -1 - metric_interval_upper_bound = 0 - } - down_alarm_config = { - statistic = "Average" - metric_name = "CPUUtilization" - comparison_operator = "LessThanThreshold" - threshold = 25 - period = 300 - evaluation_periods = 5 - } + adjustment_type = "ChangeInCapacity" + metric_aggregation_type = "Average" + cooldown = 300 + scaling_adjustment = 1 + metric_interval_lower_bound = 0 + } +} + +variable "up_metric_alarm_config" { + type = object({ + statistic = string + metric_name = string + comparison_operator = string + threshold = number + period = number + evaluation_periods = number + }) + default = { + statistic = "Average" + metric_name = "CPUUtilization" + comparison_operator = "GreaterThanThreshold" + threshold = 75 + period = 300 + evaluation_periods = 5 + } +} + +variable "down_scaling_policy_config" { + type = object({ + adjustment_type = string + metric_aggregation_type = string + cooldown = number + scaling_adjustment = number + metric_interval_upper_bound = number + }) + default = { + adjustment_type = "ChangeInCapacity" + metric_aggregation_type = "Average" + cooldown = 300 + scaling_adjustment = -1 + metric_interval_upper_bound = 0 + } +} + +variable "down_metric_alarm_config" { + type = object({ + statistic = string + metric_name = string + comparison_operator = string + threshold = number + period = number + evaluation_periods = number + }) + default = { + statistic = "Average" + metric_name = "CPUUtilization" + comparison_operator = "LessThanThreshold" + threshold = 25 + period = 300 + evaluation_periods = 5 } } variable "log_group_name" { From 7bbc15057afd01bd0d81226e37569c51692fcaef Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Thu, 2 Jun 2022 17:26:58 -0600 Subject: [PATCH 4/9] tweaks --- variables.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/variables.tf b/variables.tf index 6001aff..6c68660 100644 --- a/variables.tf +++ b/variables.tf @@ -211,6 +211,7 @@ variable "up_scaling_policy_config" { scaling_adjustment = number metric_interval_lower_bound = number }) + description = "Advanced configuration for the scaling up policy if 'autoscaling_config' is in use." default = { adjustment_type = "ChangeInCapacity" metric_aggregation_type = "Average" @@ -229,6 +230,7 @@ variable "up_metric_alarm_config" { period = number evaluation_periods = number }) + description = "Advanced configuration for the scaling up metric alarm if 'autoscaling_config' is in use." default = { statistic = "Average" metric_name = "CPUUtilization" @@ -247,6 +249,7 @@ variable "down_scaling_policy_config" { scaling_adjustment = number metric_interval_upper_bound = number }) + description = "Advanced configuration for the scaling down policy if 'autoscaling_config' is in use." default = { adjustment_type = "ChangeInCapacity" metric_aggregation_type = "Average" @@ -265,6 +268,7 @@ variable "down_metric_alarm_config" { period = number evaluation_periods = number }) + description = "Advanced configuration for scaling the down metric alarm if 'autoscaling_config' is in use." default = { statistic = "Average" metric_name = "CPUUtilization" From 7fd0ebcf1fb9dfdd6fb81ffcc0425c4b3190273c Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Thu, 2 Jun 2022 18:22:25 -0600 Subject: [PATCH 5/9] tweaks --- README.md | 4 ++++ variables.tf | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b3e3c6f..7dbc310 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,10 @@ module "my_app" { | hosted_zone | [object](#hosted_zone) | Hosted Zone object to redirect to ALB. (Can pass in the aws_hosted_zone object). A and AAAA records created in this hosted zone | | | https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain | | | autoscaling_config | [object](#autoscaling_config) | Configuration for default autoscaling policies and alarms. Set to `null` if you want to set up your own autoscaling policies and alarms. | | +| up_scaling_policy_config | [object](#autoscaling_config) | Advanced configuration for the scaling up policy if 'autoscaling_config' is in use. | todo | | +| up_metric_alarm_config | [object](#autoscaling_config) | Advanced configuration for the scaling up metric alarm if 'autoscaling_config' is in use. | todo | | +| down_scaling_policy_config | [object](#autoscaling_config) | Advanced configuration for the scaling down policy if 'autoscaling_config' is in use. | todo | | +| down_metric_alarm_config | [object](#autoscaling_config) | Advanced configuration for scaling the down metric alarm if 'autoscaling_config' is in use." | todo | | log_group_name | string | CloudWatch log group name. | | | log_retention_in_days | number | CloudWatch log group retention in days | 120 | | tags | map(string) | A map of AWS Tags to attach to each resource created | {} | diff --git a/variables.tf b/variables.tf index 6c68660..120242c 100644 --- a/variables.tf +++ b/variables.tf @@ -202,7 +202,6 @@ variable "autoscaling_config" { }) description = "Configuration for default autoscaling policies and alarms. Set to null if you want to set up your own autoscaling policies and alarms." } - variable "up_scaling_policy_config" { type = object({ adjustment_type = string @@ -220,7 +219,6 @@ variable "up_scaling_policy_config" { metric_interval_lower_bound = 0 } } - variable "up_metric_alarm_config" { type = object({ statistic = string @@ -240,7 +238,6 @@ variable "up_metric_alarm_config" { evaluation_periods = 5 } } - variable "down_scaling_policy_config" { type = object({ adjustment_type = string @@ -258,7 +255,6 @@ variable "down_scaling_policy_config" { metric_interval_upper_bound = 0 } } - variable "down_metric_alarm_config" { type = object({ statistic = string From 919b30bda0ceea3e18a9ccc4e828a14b9e63342a Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Fri, 3 Jun 2022 08:56:18 -0600 Subject: [PATCH 6/9] refactoring --- README.md | 214 +++++++++++++++++++++++++++++++++++---------------- main.tf | 44 +++++------ variables.tf | 8 +- 3 files changed, 175 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index 7dbc310..6baec82 100644 --- a/README.md +++ b/README.md @@ -76,54 +76,54 @@ module "my_app" { ## Inputs -| Name | Type | Description | Default | -|-----------------------------------|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------| -| app_name | string | Application name to name your Fargate API and other resources (Must be <= 24 alphanumeric characters) | | -| ecs_cluster_name | string | Existing ECS Cluster name to host the fargate server. Defaults to creating its own cluster. | | -| primary_container_definition | [object](#container_definition) | The primary container definition for your application. This one will be the only container that receives traffic from the ALB, so make sure the `ports` field contains the same port as the `image_port` | | -| extra_container_definitions | list([object](#container_definition)) | A list of extra container definitions (side car containers) | [] | -| container_port | number | The port the primary docker container is listening on | | -| health_check_path | string | Health check path for the image | "/" | -| health_check_matcher | string | Expected status code for health check. [See docs for syntax](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html) | 200 | -| health_check_interval | number | Amount of time, in seconds, between health checks of an individual target | 30 | -| health_check_timeout | number | Amount of time, in seconds, during which no response means a failed health check | 5 | -| health_check_healthy_threshold | number | Number of consecutive health checks required before considering target as healthy | 3 | -| health_check_unhealthy_threshold | number | Number of consecutive failed health checks required before considering target as unhealthy | 3 | -| health_check_grace_period | number | Health check grace period in seconds | 0 | -| task_policies | list(string) | List of IAM Policy ARNs to attach to the task execution IAM Policy | [] | -| task_cpu | number | CPU for the task definition | 256 | -| task_memory | number | Memory for the task definition | 512 | -| security_groups | list(string) | List of extra security group IDs to attach to the fargate task | [] | -| vpc_id | string | VPC ID to deploy the ECS fargate service and ALB | | -| public_subnet_ids | list(string) | List of subnet IDs for the ALB | | -| alb_internal_flag | bool | Marks an ALB as Internal (Inaccessible to public internet) | false | -| alb_sg_ingress_cidrs | list(string) | List of cidrs to allow alb ingress for | ["0.0.0.0/0"] | -| alb_sg_ingress_sg_ids | llist(string) | List of security groups to allow ingress | [] | -| private_subnet_ids | list(string) | List of subnet IDs for the fargate service | | -| codedeploy_service_role_arn | string | ARN of the IAM Role for the CodeDeploy to use to initiate new deployments. (usually the PowerBuilder Role) | | -| codedeploy_termination_wait_time | number | the number of minutes to wait after a successful blue/green deployment before terminating instances from the original environment | 15 | -| codedeploy_test_listener_port | number | The port for a codedeploy test listener. If provided CodeDeploy will use this port for test traffic on the new replacement set during the blue-green deployment process before shifting production traffic to the replacement set | null | -| codedeploy_lifecycle_hooks | [object](#codedeploy_lifecycle_hooks) | Define Lambda Functions for each CodeDeploy [lifecycle event hooks](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html). Use the Lambda function names as the values. Use null if you don't want to invoke a lambda function at that specific hook. Or set this variable to null to not have any lifecycle hooks invoked | `null` | -| appspec_filename | string | Filename (including path) to use when outputing appspec json. | `appspec.json` in the current working directory (i.e. where you ran `terraform apply`) | -| role_permissions_boundary_arn | string | ARN of the IAM Role permissions boundary to place on each IAM role created | | -| target_group_deregistration_delay | number | Deregistration delay in seconds for ALB target groups | 60 | -| target_group_sticky_sessions | boolean | Enables sticky sessions on the ALB target groups | false | -| site_url | string | The URL for the site. | Concatenates app_name with hosted_zone_name. | -| allow_overwrite | bool | Allow creation of Route53 records in Terraform to overwrite an existing record, if any. | false | -| hosted_zone | [object](#hosted_zone) | Hosted Zone object to redirect to ALB. (Can pass in the aws_hosted_zone object). A and AAAA records created in this hosted zone | | -| https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain | | -| autoscaling_config | [object](#autoscaling_config) | Configuration for default autoscaling policies and alarms. Set to `null` if you want to set up your own autoscaling policies and alarms. | | -| up_scaling_policy_config | [object](#autoscaling_config) | Advanced configuration for the scaling up policy if 'autoscaling_config' is in use. | todo | | -| up_metric_alarm_config | [object](#autoscaling_config) | Advanced configuration for the scaling up metric alarm if 'autoscaling_config' is in use. | todo | | -| down_scaling_policy_config | [object](#autoscaling_config) | Advanced configuration for the scaling down policy if 'autoscaling_config' is in use. | todo | | -| down_metric_alarm_config | [object](#autoscaling_config) | Advanced configuration for scaling the down metric alarm if 'autoscaling_config' is in use." | todo | -| log_group_name | string | CloudWatch log group name. | | -| log_retention_in_days | number | CloudWatch log group retention in days | 120 | -| tags | map(string) | A map of AWS Tags to attach to each resource created | {} | -| lb_logging_enabled | bool | Option to enable logging of load balancer requests. | false | -| lb_logging_bucket_name | string | Required if `lb_logging_enabled` is true. A bucket to store the logs in with an a [load balancer access policy](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html#attach-bucket-policy) attached. | | -| fargate_platform_version | string | Version of the Fargate platform to run. | 1.4.0 | -| xray_enabled | bool | Whether or not the X-Ray daemon should be created with the Fargate API. | false | +| Name | Type | Description | Default | +|-----------------------------------|---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------| +| app_name | string | Application name to name your Fargate API and other resources (Must be <= 24 alphanumeric characters) | | +| ecs_cluster_name | string | Existing ECS Cluster name to host the fargate server. Defaults to creating its own cluster. | | +| primary_container_definition | [object](#container_definition) | The primary container definition for your application. This one will be the only container that receives traffic from the ALB, so make sure the `ports` field contains the same port as the `image_port` | | +| extra_container_definitions | list([object](#container_definition)) | A list of extra container definitions (side car containers) | [] | +| container_port | number | The port the primary docker container is listening on | | +| health_check_path | string | Health check path for the image | "/" | +| health_check_matcher | string | Expected status code for health check. [See docs for syntax](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html) | 200 | +| health_check_interval | number | Amount of time, in seconds, between health checks of an individual target | 30 | +| health_check_timeout | number | Amount of time, in seconds, during which no response means a failed health check | 5 | +| health_check_healthy_threshold | number | Number of consecutive health checks required before considering target as healthy | 3 | +| health_check_unhealthy_threshold | number | Number of consecutive failed health checks required before considering target as unhealthy | 3 | +| health_check_grace_period | number | Health check grace period in seconds | 0 | +| task_policies | list(string) | List of IAM Policy ARNs to attach to the task execution IAM Policy | [] | +| task_cpu | number | CPU for the task definition | 256 | +| task_memory | number | Memory for the task definition | 512 | +| security_groups | list(string) | List of extra security group IDs to attach to the fargate task | [] | +| vpc_id | string | VPC ID to deploy the ECS fargate service and ALB | | +| public_subnet_ids | list(string) | List of subnet IDs for the ALB | | +| alb_internal_flag | bool | Marks an ALB as Internal (Inaccessible to public internet) | false | +| alb_sg_ingress_cidrs | list(string) | List of cidrs to allow alb ingress for | ["0.0.0.0/0"] | +| alb_sg_ingress_sg_ids | llist(string) | List of security groups to allow ingress | [] | +| private_subnet_ids | list(string) | List of subnet IDs for the fargate service | | +| codedeploy_service_role_arn | string | ARN of the IAM Role for the CodeDeploy to use to initiate new deployments. (usually the PowerBuilder Role) | | +| codedeploy_termination_wait_time | number | the number of minutes to wait after a successful blue/green deployment before terminating instances from the original environment | 15 | +| codedeploy_test_listener_port | number | The port for a codedeploy test listener. If provided CodeDeploy will use this port for test traffic on the new replacement set during the blue-green deployment process before shifting production traffic to the replacement set | null | +| codedeploy_lifecycle_hooks | [object](#codedeploy_lifecycle_hooks) | Define Lambda Functions for each CodeDeploy [lifecycle event hooks](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html). Use the Lambda function names as the values. Use null if you don't want to invoke a lambda function at that specific hook. Or set this variable to null to not have any lifecycle hooks invoked | `null` | +| appspec_filename | string | Filename (including path) to use when outputing appspec json. | `appspec.json` in the current working directory (i.e. where you ran `terraform apply`) | +| role_permissions_boundary_arn | string | ARN of the IAM Role permissions boundary to place on each IAM role created | | +| target_group_deregistration_delay | number | Deregistration delay in seconds for ALB target groups | 60 | +| target_group_sticky_sessions | boolean | Enables sticky sessions on the ALB target groups | false | +| site_url | string | The URL for the site. | Concatenates app_name with hosted_zone_name. | +| allow_overwrite | bool | Allow creation of Route53 records in Terraform to overwrite an existing record, if any. | false | +| hosted_zone | [object](#hosted_zone) | Hosted Zone object to redirect to ALB. (Can pass in the aws_hosted_zone object). A and AAAA records created in this hosted zone | | +| https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain | | +| autoscaling_config | [object](#autoscaling_config) | Configuration for default autoscaling policies and alarms. Set to `null` if you want to set up your own autoscaling policies and alarms. | | +| scaling_up_policy_config | [object](#scaling_up_policy_config) | Advanced configuration for the scaling up policy if 'autoscaling_config' is in use. | todo | | +| scaling_up_metric_alarm_config | [object](#scaling_up_metric_alarm_config) | Advanced configuration for the scaling up metric alarm if 'autoscaling_config' is in use. | todo | | +| scaling_down_policy_config | [object](#scaling_down_policy_config) | Advanced configuration for the scaling down policy if 'autoscaling_config' is in use. | todo | | +| scaling_down_metric_alarm_config | [object](#scaling_down_metric_alarm_config) | Advanced configuration for scaling the down metric alarm if 'autoscaling_config' is in use." | todo | +| log_group_name | string | CloudWatch log group name. | | +| log_retention_in_days | number | CloudWatch log group retention in days | 120 | +| tags | map(string) | A map of AWS Tags to attach to each resource created | {} | +| lb_logging_enabled | bool | Option to enable logging of load balancer requests. | false | +| lb_logging_bucket_name | string | Required if `lb_logging_enabled` is true. A bucket to store the logs in with an a [load balancer access policy](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html#attach-bucket-policy) attached. | | +| fargate_platform_version | string | Version of the Fargate platform to run. | 1.4.0 | +| xray_enabled | bool | Whether or not the X-Ray daemon should be created with the Fargate API. | false | #### container_definition @@ -205,6 +205,90 @@ point this module will not create any policies/alarms. **Note:** the desired count of the ECS Fargate Service will be set the first time terraform runs but changes to desired count will be ignored after the first time. +#### scaling_up_policy_config + +This will allow the scaling up policy to be configured if necessary. + +* **`adjustment_type`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial +* **`metric_aggregation_type`** - (Required) Maximum task count for autoscaling +* **`cooldown`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial +* **`scaling_adjustment`** - (Required) Maximum task count for autoscaling +* **`metric_interval_lower_bound`** - (Required) Maximum task count for autoscaling +* Default: + ``` + { + adjustment_type = "ChangeInCapacity" + metric_aggregation_type = "Average" + cooldown = 300 + scaling_adjustment = 1 + metric_interval_lower_bound = 0 + } + ``` + +#### scaling_down_policy_config + +This will allow the scaling down policy to be configured if necessary. + +* **`adjustment_type`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial +* **`metric_aggregation_type`** - (Required) Maximum task count for autoscaling +* **`cooldown`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial +* **`scaling_adjustment`** - (Required) Maximum task count for autoscaling +* **`metric_interval_upper_bound`** - (Required) Maximum task count for autoscaling +* Default: + ``` + { + adjustment_type = "ChangeInCapacity" + metric_aggregation_type = "Average" + cooldown = 300 + scaling_adjustment = -1 + metric_interval_upper_bound = 0 + } + ``` + +#### scaling_up_metric_alarm_config + +This will allow the scaling up alarm to be configured if necessary. + +* **`statistic`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial +* **`metric_name`** - (Required) Maximum task count for autoscaling +* **`comparison_operator`** - (Required) Minimum task count for autoscaling (this will also be used to define the +* **`threshold`** - (Required) Maximum task count for autoscaling +* **`period`** - (Required) Maximum task count for autoscaling +* **`evaluation_periods`** - (Required) Maximum task count for autoscaling +* Default: + ``` + { + statistic = "Average" + metric_name = "CPUUtilization" + comparison_operator = "GreaterThanThreshold" + threshold = 75 + period = 300 + evaluation_periods = 5 + } + ``` + +#### scaling_down_metric_alarm_config + +This will allow the scaling down alarm to be configured if necessary. + +* **`statistic`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial +* **`metric_name`** - (Required) Maximum task count for autoscaling +* **`comparison_operator`** - (Required) Minimum task count for autoscaling (this will also be used to define the +* **`threshold`** - (Required) Maximum task count for autoscaling +* **`period`** - (Required) Maximum task count for autoscaling +* **`evaluation_periods`** - (Required) Maximum task count for autoscaling +* Default: + ``` + { + statistic = "Average" + metric_name = "CPUUtilization" + comparison_operator = "LessThanThreshold" + threshold = 25 + period = 300 + evaluation_periods = 5 + } + ``` + #### CloudWatch logs This module will create a CloudWatch log group named `fargate/` with log streams @@ -215,23 +299,23 @@ with the container logs in `example-api/example/12d344fd34b556ae4326...` ## Outputs -| Name | Type | Description | -| --- | --- | --- | -| fargate_service | [object](https://www.terraform.io/docs/providers/aws/r/ecs_service.html#attributes-reference) | Fargate ECS Service object | -| ecs_cluster | [object](https://www.terraform.io/docs/providers/aws/r/ecs_cluster.html#attributes-reference) | ECS Cluster (created or pre-existing) the service is deployed on | -| fargate_service_security_group | [object](https://www.terraform.io/docs/providers/aws/r/security_group.html#attributes-reference) | Security Group object assigned to the Fargate service | -| task_definition | [object](https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html#attributes-reference) | The task definition object of the fargate service | -| codedeploy_deployment_group | [object](https://www.terraform.io/docs/providers/aws/r/codedeploy_deployment_group.html#attributes-reference) | The CodeDeploy deployment group object. | -| codedeploy_appspec_json_file | string | Filename of the generated appspec.json file | -| alb | [object](https://www.terraform.io/docs/providers/aws/r/lb.html#attributes-reference) | The Application Load Balancer (ALB) object | -| alb_target_group_blue | [object](https://www.terraform.io/docs/providers/aws/r/lb_target_group.html#attributes-reference) | The Application Load Balancer Target Group (ALB Target Group) object for the blue deployment | -| alb_target_group_green | [object](https://www.terraform.io/docs/providers/aws/r/lb_target_group.html#attributes-reference) | The Application Load Balancer Target Group (ALB Target Group) object for the green deployment | -| alb_security_group | [object](https://www.terraform.io/docs/providers/aws/r/security_group.html#attributes-reference) | The ALB's security group object | -| dns_record | [object](https://www.terraform.io/docs/providers/aws/r/route53_record.html#attributes-reference) | The DNS A-record mapped to the ALB | -| autoscaling_step_up_policy | [object](https://www.terraform.io/docs/providers/aws/r/autoscaling_policy.html#attributes-reference) | Autoscaling policy to step up | -| autoscaling_step_down_policy | [object](https://www.terraform.io/docs/providers/aws/r/autoscaling_policy.html#attributes-reference) | Autoscaling policy to step down | -| task_role | [object](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role#attributes-reference) | IAM role created for the tasks. | -| task_execution_role | [object](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role#attributes-reference) | IAM role created for the execution of tasks. | +| Name | Type | Description | +|--------------------------------|---------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------| +| fargate_service | [object](https://www.terraform.io/docs/providers/aws/r/ecs_service.html#attributes-reference) | Fargate ECS Service object | +| ecs_cluster | [object](https://www.terraform.io/docs/providers/aws/r/ecs_cluster.html#attributes-reference) | ECS Cluster (created or pre-existing) the service is deployed on | +| fargate_service_security_group | [object](https://www.terraform.io/docs/providers/aws/r/security_group.html#attributes-reference) | Security Group object assigned to the Fargate service | +| task_definition | [object](https://www.terraform.io/docs/providers/aws/r/ecs_task_definition.html#attributes-reference) | The task definition object of the fargate service | +| codedeploy_deployment_group | [object](https://www.terraform.io/docs/providers/aws/r/codedeploy_deployment_group.html#attributes-reference) | The CodeDeploy deployment group object. | +| codedeploy_appspec_json_file | string | Filename of the generated appspec.json file | +| alb | [object](https://www.terraform.io/docs/providers/aws/r/lb.html#attributes-reference) | The Application Load Balancer (ALB) object | +| alb_target_group_blue | [object](https://www.terraform.io/docs/providers/aws/r/lb_target_group.html#attributes-reference) | The Application Load Balancer Target Group (ALB Target Group) object for the blue deployment | +| alb_target_group_green | [object](https://www.terraform.io/docs/providers/aws/r/lb_target_group.html#attributes-reference) | The Application Load Balancer Target Group (ALB Target Group) object for the green deployment | +| alb_security_group | [object](https://www.terraform.io/docs/providers/aws/r/security_group.html#attributes-reference) | The ALB's security group object | +| dns_record | [object](https://www.terraform.io/docs/providers/aws/r/route53_record.html#attributes-reference) | The DNS A-record mapped to the ALB | +| autoscaling_step_up_policy | [object](https://www.terraform.io/docs/providers/aws/r/autoscaling_policy.html#attributes-reference) | Autoscaling policy to step up | +| autoscaling_step_down_policy | [object](https://www.terraform.io/docs/providers/aws/r/autoscaling_policy.html#attributes-reference) | Autoscaling policy to step down | +| task_role | [object](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role#attributes-reference) | IAM role created for the tasks. | +| task_execution_role | [object](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role#attributes-reference) | IAM role created for the execution of tasks. | #### appspec diff --git a/main.tf b/main.tf index 3fcf787..1a159da 100644 --- a/main.tf +++ b/main.tf @@ -558,13 +558,13 @@ resource "aws_appautoscaling_policy" "up" { service_namespace = aws_appautoscaling_target.default[0].service_namespace step_scaling_policy_configuration { - adjustment_type = var.up_scaling_policy_config.adjustment_type - metric_aggregation_type = var.up_scaling_policy_config.metric_aggregation_type - cooldown = var.up_scaling_policy_config.cooldown + adjustment_type = var.scaling_up_policy_config.adjustment_type + metric_aggregation_type = var.scaling_up_policy_config.metric_aggregation_type + cooldown = var.scaling_up_policy_config.cooldown step_adjustment { - scaling_adjustment = var.up_scaling_policy_config.scaling_adjustment - metric_interval_lower_bound = var.up_scaling_policy_config.metric_interval_lower_bound + scaling_adjustment = var.scaling_up_policy_config.scaling_adjustment + metric_interval_lower_bound = var.scaling_up_policy_config.metric_interval_lower_bound } } } @@ -576,12 +576,12 @@ resource "aws_cloudwatch_metric_alarm" "up" { ClusterName = local.cluster_name ServiceName = aws_ecs_service.service.name } - statistic = var.up_metric_alarm_config.statistic - metric_name = var.up_metric_alarm_config.metric_name - comparison_operator = var.up_metric_alarm_config.comparison_operator - threshold = var.up_metric_alarm_config.threshold - period = var.up_metric_alarm_config.period - evaluation_periods = var.up_metric_alarm_config.evaluation_periods + statistic = var.scaling_up_metric_alarm_config.statistic + metric_name = var.scaling_up_metric_alarm_config.metric_name + comparison_operator = var.scaling_up_metric_alarm_config.comparison_operator + threshold = var.scaling_up_metric_alarm_config.threshold + period = var.scaling_up_metric_alarm_config.period + evaluation_periods = var.scaling_up_metric_alarm_config.evaluation_periods alarm_actions = [aws_appautoscaling_policy.up[0].arn] tags = var.tags } @@ -593,13 +593,13 @@ resource "aws_appautoscaling_policy" "down" { service_namespace = aws_appautoscaling_target.default[0].service_namespace step_scaling_policy_configuration { - adjustment_type = var.down_scaling_policy_config.adjustment_type - metric_aggregation_type = var.down_scaling_policy_config.metric_aggregation_type - cooldown = var.down_scaling_policy_config.cooldown + adjustment_type = var.scaling_down_policy_config.adjustment_type + metric_aggregation_type = var.scaling_down_policy_config.metric_aggregation_type + cooldown = var.scaling_down_policy_config.cooldown step_adjustment { - scaling_adjustment = var.down_scaling_policy_config.adjustment_type - metric_interval_upper_bound = var.down_scaling_policy_config.metric_interval_upper_bound + scaling_adjustment = var.scaling_down_policy_config.adjustment_type + metric_interval_upper_bound = var.scaling_down_policy_config.metric_interval_upper_bound } } } @@ -611,12 +611,12 @@ resource "aws_cloudwatch_metric_alarm" "down" { ClusterName = local.cluster_name ServiceName = aws_ecs_service.service.name } - statistic = var.down_metric_alarm_config.statistic - metric_name = var.down_metric_alarm_config.metric_name - comparison_operator = var.down_metric_alarm_config.comparison_operator - threshold = var.down_metric_alarm_config.threshold - period = var.down_metric_alarm_config.period - evaluation_periods = var.down_metric_alarm_config.evaluation_periods + statistic = var.scaling_down_metric_alarm_config.statistic + metric_name = var.scaling_down_metric_alarm_config.metric_name + comparison_operator = var.scaling_down_metric_alarm_config.comparison_operator + threshold = var.scaling_down_metric_alarm_config.threshold + period = var.scaling_down_metric_alarm_config.period + evaluation_periods = var.scaling_down_metric_alarm_config.evaluation_periods alarm_actions = [aws_appautoscaling_policy.down[0].arn] tags = var.tags } diff --git a/variables.tf b/variables.tf index 120242c..9788656 100644 --- a/variables.tf +++ b/variables.tf @@ -202,7 +202,7 @@ variable "autoscaling_config" { }) description = "Configuration for default autoscaling policies and alarms. Set to null if you want to set up your own autoscaling policies and alarms." } -variable "up_scaling_policy_config" { +variable "scaling_up_policy_config" { type = object({ adjustment_type = string metric_aggregation_type = string @@ -219,7 +219,7 @@ variable "up_scaling_policy_config" { metric_interval_lower_bound = 0 } } -variable "up_metric_alarm_config" { +variable "scaling_up_metric_alarm_config" { type = object({ statistic = string metric_name = string @@ -238,7 +238,7 @@ variable "up_metric_alarm_config" { evaluation_periods = 5 } } -variable "down_scaling_policy_config" { +variable "scaling_down_policy_config" { type = object({ adjustment_type = string metric_aggregation_type = string @@ -255,7 +255,7 @@ variable "down_scaling_policy_config" { metric_interval_upper_bound = 0 } } -variable "down_metric_alarm_config" { +variable "scaling_down_metric_alarm_config" { type = object({ statistic = string metric_name = string From 7b4db60889e79f976b00359e5e88453cc4109909 Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Fri, 3 Jun 2022 09:07:09 -0600 Subject: [PATCH 7/9] finish readme --- README.md | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 6baec82..3f21b4e 100644 --- a/README.md +++ b/README.md @@ -209,11 +209,11 @@ count will be ignored after the first time. This will allow the scaling up policy to be configured if necessary. -* **`adjustment_type`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial -* **`metric_aggregation_type`** - (Required) Maximum task count for autoscaling -* **`cooldown`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial -* **`scaling_adjustment`** - (Required) Maximum task count for autoscaling -* **`metric_interval_lower_bound`** - (Required) Maximum task count for autoscaling +* **`adjustment_type`** - (Required) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. +* **`metric_aggregation_type`** - (Required) The aggregation type for the policy's metrics. +* **`cooldown`** - (Required) The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. +* **`scaling_adjustment`** - (Required) The number of members by which to scale, when the adjustment bounds are breached. A positive value scales up. A negative value scales down. +* **`metric_interval_lower_bound`** - (Required) The lower bound for the difference between the alarm threshold and the CloudWatch metric. * Default: ``` { @@ -229,11 +229,11 @@ This will allow the scaling up policy to be configured if necessary. This will allow the scaling down policy to be configured if necessary. -* **`adjustment_type`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial -* **`metric_aggregation_type`** - (Required) Maximum task count for autoscaling -* **`cooldown`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial -* **`scaling_adjustment`** - (Required) Maximum task count for autoscaling -* **`metric_interval_upper_bound`** - (Required) Maximum task count for autoscaling +* **`adjustment_type`** - (Required) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. +* **`metric_aggregation_type`** - (Required) The aggregation type for the policy's metrics. +* **`cooldown`** - (Required) The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. +* **`scaling_adjustment`** - (Required) The number of members by which to scale, when the adjustment bounds are breached. A positive value scales up. A negative value scales down. +* **`metric_interval_upper_bound`** - The upper bound for the difference between the alarm threshold and the CloudWatch metric. * Default: ``` { @@ -249,12 +249,12 @@ This will allow the scaling down policy to be configured if necessary. This will allow the scaling up alarm to be configured if necessary. -* **`statistic`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial -* **`metric_name`** - (Required) Maximum task count for autoscaling -* **`comparison_operator`** - (Required) Minimum task count for autoscaling (this will also be used to define the -* **`threshold`** - (Required) Maximum task count for autoscaling -* **`period`** - (Required) Maximum task count for autoscaling -* **`evaluation_periods`** - (Required) Maximum task count for autoscaling +* **`statistic`** - (Required) The statistic to apply to the alarm's associated metric. +* **`metric_name`** - (Required) The name for the alarm's associated metric. +* **`comparison_operator`** - (Required) The arithmetic operation to use when comparing the specified Statistic and Threshold. +* **`threshold`** - (Required) The value against which the specified statistic is compared. +* **`period`** - (Required) The period in seconds over which the specified statistic is applied. +* **`evaluation_periods`** - (Required) The number of periods over which data is compared to the specified threshold. * Default: ``` { @@ -271,12 +271,12 @@ This will allow the scaling up alarm to be configured if necessary. This will allow the scaling down alarm to be configured if necessary. -* **`statistic`** - (Required) Minimum task count for autoscaling (this will also be used to define the initial -* **`metric_name`** - (Required) Maximum task count for autoscaling -* **`comparison_operator`** - (Required) Minimum task count for autoscaling (this will also be used to define the -* **`threshold`** - (Required) Maximum task count for autoscaling -* **`period`** - (Required) Maximum task count for autoscaling -* **`evaluation_periods`** - (Required) Maximum task count for autoscaling +* **`statistic`** - (Required) The statistic to apply to the alarm's associated metric. +* **`metric_name`** - (Required) The name for the alarm's associated metric. +* **`comparison_operator`** - (Required) The arithmetic operation to use when comparing the specified Statistic and Threshold. +* **`threshold`** - (Required) The value against which the specified statistic is compared. +* **`period`** - (Required) The period in seconds over which the specified statistic is applied. +* **`evaluation_periods`** - (Required) The number of periods over which data is compared to the specified threshold. * Default: ``` { From 8611e67244427bb927669c885bbabf3d92e945bc Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Fri, 3 Jun 2022 10:18:19 -0600 Subject: [PATCH 8/9] fixes --- README.md | 42 +++++++++++++++++++++++-------------- examples/logging/logging.tf | 2 +- examples/simple/simple.tf | 2 +- main.tf | 2 +- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3f21b4e..cf4d6b8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ customized solution you may need to use this code more as a pattern or guideline ```hcl module "my_app" { - source = "github.com/byu-oit/terraform-aws-fargate-api?ref=v3.4.0" + source = "github.com/byu-oit/terraform-aws-fargate-api?ref=v3.5.0" app_name = "example-api" container_port = 8000 primary_container_definition = { @@ -113,10 +113,10 @@ module "my_app" { | hosted_zone | [object](#hosted_zone) | Hosted Zone object to redirect to ALB. (Can pass in the aws_hosted_zone object). A and AAAA records created in this hosted zone | | | https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain | | | autoscaling_config | [object](#autoscaling_config) | Configuration for default autoscaling policies and alarms. Set to `null` if you want to set up your own autoscaling policies and alarms. | | -| scaling_up_policy_config | [object](#scaling_up_policy_config) | Advanced configuration for the scaling up policy if 'autoscaling_config' is in use. | todo | | -| scaling_up_metric_alarm_config | [object](#scaling_up_metric_alarm_config) | Advanced configuration for the scaling up metric alarm if 'autoscaling_config' is in use. | todo | | -| scaling_down_policy_config | [object](#scaling_down_policy_config) | Advanced configuration for the scaling down policy if 'autoscaling_config' is in use. | todo | | -| scaling_down_metric_alarm_config | [object](#scaling_down_metric_alarm_config) | Advanced configuration for scaling the down metric alarm if 'autoscaling_config' is in use." | todo | +| scaling_up_policy_config | [object](#scaling_up_policy_config) | Optional advanced configuration for the scaling up policy if 'autoscaling_config' is in use. | See object definition [object](#scaling_up_policy_config) | +| scaling_up_metric_alarm_config | [object](#scaling_up_metric_alarm_config) | Optional advanced configuration for the scaling up metric alarm if 'autoscaling_config' is in use. | See object definition [object](#scaling_up_metric_alarm_config) | +| scaling_down_policy_config | [object](#scaling_down_policy_config) | Optional advanced configuration for the scaling down policy if 'autoscaling_config' is in use. | See object definition [object](#scaling_down_policy_config) | +| scaling_down_metric_alarm_config | [object](#scaling_down_metric_alarm_config) | Optional advanced configuration for scaling the down metric alarm if 'autoscaling_config' is in use." | See object definition [object](#scaling_down_metric_alarm_config) | | log_group_name | string | CloudWatch log group name. | | | log_retention_in_days | number | CloudWatch log group retention in days | 120 | | tags | map(string) | A map of AWS Tags to attach to each resource created | {} | @@ -209,12 +209,16 @@ count will be ignored after the first time. This will allow the scaling up policy to be configured if necessary. -* **`adjustment_type`** - (Required) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. +* **`adjustment_type`** - (Required) Specifies whether the adjustment is an absolute number or a percentage of the + current capacity. * **`metric_aggregation_type`** - (Required) The aggregation type for the policy's metrics. -* **`cooldown`** - (Required) The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. -* **`scaling_adjustment`** - (Required) The number of members by which to scale, when the adjustment bounds are breached. A positive value scales up. A negative value scales down. -* **`metric_interval_lower_bound`** - (Required) The lower bound for the difference between the alarm threshold and the CloudWatch metric. -* Default: +* **`cooldown`** - (Required) The amount of time, in seconds, after a scaling activity completes and before the next + scaling activity can start. +* **`scaling_adjustment`** - (Required) The number of members by which to scale, when the adjustment bounds are + breached. A positive value scales up. A negative value scales down. +* **`metric_interval_lower_bound`** - (Required) The lower bound for the difference between the alarm threshold and the + CloudWatch metric. +* Default: ``` { adjustment_type = "ChangeInCapacity" @@ -229,11 +233,15 @@ This will allow the scaling up policy to be configured if necessary. This will allow the scaling down policy to be configured if necessary. -* **`adjustment_type`** - (Required) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. +* **`adjustment_type`** - (Required) Specifies whether the adjustment is an absolute number or a percentage of the + current capacity. * **`metric_aggregation_type`** - (Required) The aggregation type for the policy's metrics. -* **`cooldown`** - (Required) The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. -* **`scaling_adjustment`** - (Required) The number of members by which to scale, when the adjustment bounds are breached. A positive value scales up. A negative value scales down. -* **`metric_interval_upper_bound`** - The upper bound for the difference between the alarm threshold and the CloudWatch metric. +* **`cooldown`** - (Required) The amount of time, in seconds, after a scaling activity completes and before the next + scaling activity can start. +* **`scaling_adjustment`** - (Required) The number of members by which to scale, when the adjustment bounds are + breached. A positive value scales up. A negative value scales down. +* **`metric_interval_upper_bound`** - The upper bound for the difference between the alarm threshold and the CloudWatch + metric. * Default: ``` { @@ -251,7 +259,8 @@ This will allow the scaling up alarm to be configured if necessary. * **`statistic`** - (Required) The statistic to apply to the alarm's associated metric. * **`metric_name`** - (Required) The name for the alarm's associated metric. -* **`comparison_operator`** - (Required) The arithmetic operation to use when comparing the specified Statistic and Threshold. +* **`comparison_operator`** - (Required) The arithmetic operation to use when comparing the specified Statistic and + Threshold. * **`threshold`** - (Required) The value against which the specified statistic is compared. * **`period`** - (Required) The period in seconds over which the specified statistic is applied. * **`evaluation_periods`** - (Required) The number of periods over which data is compared to the specified threshold. @@ -273,7 +282,8 @@ This will allow the scaling down alarm to be configured if necessary. * **`statistic`** - (Required) The statistic to apply to the alarm's associated metric. * **`metric_name`** - (Required) The name for the alarm's associated metric. -* **`comparison_operator`** - (Required) The arithmetic operation to use when comparing the specified Statistic and Threshold. +* **`comparison_operator`** - (Required) The arithmetic operation to use when comparing the specified Statistic and + Threshold. * **`threshold`** - (Required) The value against which the specified statistic is compared. * **`period`** - (Required) The period in seconds over which the specified statistic is applied. * **`evaluation_periods`** - (Required) The number of periods over which data is compared to the specified threshold. diff --git a/examples/logging/logging.tf b/examples/logging/logging.tf index 53444cd..b351fad 100644 --- a/examples/logging/logging.tf +++ b/examples/logging/logging.tf @@ -14,7 +14,7 @@ data "aws_elb_service_account" "main" {} // name = "fake-example-cluster" //} module "fargate_api" { - source = "github.com/byu-oit/terraform-aws-fargate-api?ref=v3.4.0" + source = "github.com/byu-oit/terraform-aws-fargate-api?ref=v3.5.0" // source = "../../" // for local testing app_name = "example-api" // ecs_cluster_name = aws_ecs_cluster.existing.name diff --git a/examples/simple/simple.tf b/examples/simple/simple.tf index 737c469..2ecc3ba 100644 --- a/examples/simple/simple.tf +++ b/examples/simple/simple.tf @@ -11,7 +11,7 @@ module "acs" { // name = "fake-example-cluster" //} module "fargate_api" { - source = "github.com/byu-oit/terraform-aws-fargate-api?ref=v3.4.0" + source = "github.com/byu-oit/terraform-aws-fargate-api?ref=v3.5.0" // source = "../../" // for local testing app_name = "example-api" // ecs_cluster_name = aws_ecs_cluster.existing.name diff --git a/main.tf b/main.tf index 1a159da..aa1a6f0 100644 --- a/main.tf +++ b/main.tf @@ -598,7 +598,7 @@ resource "aws_appautoscaling_policy" "down" { cooldown = var.scaling_down_policy_config.cooldown step_adjustment { - scaling_adjustment = var.scaling_down_policy_config.adjustment_type + scaling_adjustment = var.scaling_down_policy_config.scaling_adjustment metric_interval_upper_bound = var.scaling_down_policy_config.metric_interval_upper_bound } } From c6bb65746c2a9e6be9dd48a35edf7f00ce8e2eac Mon Sep 17 00:00:00 2001 From: Jamie Visker Date: Fri, 3 Jun 2022 11:32:12 -0600 Subject: [PATCH 9/9] clarification --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf4d6b8..c88b59b 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ module "my_app" { | allow_overwrite | bool | Allow creation of Route53 records in Terraform to overwrite an existing record, if any. | false | | hosted_zone | [object](#hosted_zone) | Hosted Zone object to redirect to ALB. (Can pass in the aws_hosted_zone object). A and AAAA records created in this hosted zone | | | https_certificate_arn | string | ARN of the HTTPS certificate of the hosted zone/domain | | -| autoscaling_config | [object](#autoscaling_config) | Configuration for default autoscaling policies and alarms. Set to `null` if you want to set up your own autoscaling policies and alarms. | | +| autoscaling_config | [object](#autoscaling_config) | Configuration for default autoscaling policies and alarms. Additional advanced scaling options, which are optional, can be made with the "scaling_up_policy_config", "scaling_up_metric_alarm_config", "scaling_down_policy_config", and "scaling_down_metric_alarm_config" variables. Set to `null` if you want to set up your own autoscaling policies and alarms. | | | scaling_up_policy_config | [object](#scaling_up_policy_config) | Optional advanced configuration for the scaling up policy if 'autoscaling_config' is in use. | See object definition [object](#scaling_up_policy_config) | | scaling_up_metric_alarm_config | [object](#scaling_up_metric_alarm_config) | Optional advanced configuration for the scaling up metric alarm if 'autoscaling_config' is in use. | See object definition [object](#scaling_up_metric_alarm_config) | | scaling_down_policy_config | [object](#scaling_down_policy_config) | Optional advanced configuration for the scaling down policy if 'autoscaling_config' is in use. | See object definition [object](#scaling_down_policy_config) |