diff --git a/README.md b/README.md index b3e3c6f..c88b59b 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 = { @@ -76,50 +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. | | -| 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. 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) | +| 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 | {} | +| 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 @@ -201,6 +205,100 @@ 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) 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: + ``` + { + 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) 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: + ``` + { + 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) 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: + ``` + { + 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) 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: + ``` + { + 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 @@ -211,23 +309,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/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 e5452cb..aa1a6f0 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.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 = 1 - metric_interval_lower_bound = 0 + 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 = "Average" - metric_name = "CPUUtilization" - comparison_operator = "GreaterThanThreshold" - threshold = 75 - period = 300 - evaluation_periods = 5 + 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 = "ChangeInCapacity" - metric_aggregation_type = "Average" - cooldown = 300 + 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 = -1 - metric_interval_upper_bound = 0 + scaling_adjustment = var.scaling_down_policy_config.scaling_adjustment + 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 = "Average" - metric_name = "CPUUtilization" - comparison_operator = "LessThanThreshold" - threshold = 25 - period = 300 - evaluation_periods = 5 + 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 066a4ca..9788656 100644 --- a/variables.tf +++ b/variables.tf @@ -202,6 +202,78 @@ 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 "scaling_up_policy_config" { + type = object({ + adjustment_type = string + metric_aggregation_type = string + cooldown = number + 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" + cooldown = 300 + scaling_adjustment = 1 + metric_interval_lower_bound = 0 + } +} +variable "scaling_up_metric_alarm_config" { + type = object({ + statistic = string + metric_name = string + comparison_operator = string + threshold = number + 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" + comparison_operator = "GreaterThanThreshold" + threshold = 75 + period = 300 + evaluation_periods = 5 + } +} +variable "scaling_down_policy_config" { + type = object({ + adjustment_type = string + metric_aggregation_type = string + cooldown = number + 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" + cooldown = 300 + scaling_adjustment = -1 + metric_interval_upper_bound = 0 + } +} +variable "scaling_down_metric_alarm_config" { + type = object({ + statistic = string + metric_name = string + comparison_operator = string + threshold = number + 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" + comparison_operator = "LessThanThreshold" + threshold = 25 + period = 300 + evaluation_periods = 5 + } +} variable "log_group_name" { type = string description = "CloudWatch log group name."