Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow selectively enabling CPU and Memory based autoscaling #16

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ This repository contains Terraform infrastructure code which creates AWS resourc
| <a name="input_ecs_ulimits"></a> [ecs\_ulimits](#input\_ecs\_ulimits) | Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit" | <pre>list(object({<br> name = string<br> hardLimit = number<br> softLimit = number<br> }))</pre> | `null` | no |
| <a name="input_enable_alb"></a> [enable\_alb](#input\_enable\_alb) | IF an application load balancer should be created | `bool` | `true` | no |
| <a name="input_enable_asg"></a> [enable\_asg](#input\_enable\_asg) | If autoscaling should be enabled | `bool` | `false` | no |
| <a name="input_enable_cpu_scaling"></a> [enable\_cpu\_scaling](#input\_enable\_cpu\_scaling) | If autoscaling should be enabled based on CPU | `bool` | `true` | no |
| <a name="input_enable_datadog_log_forwarder"></a> [enable\_datadog\_log\_forwarder](#input\_enable\_datadog\_log\_forwarder) | Whether we create the lambda to forward logs to datadog | `bool` | `false` | no |
| <a name="input_enable_datadog_sidecar"></a> [enable\_datadog\_sidecar](#input\_enable\_datadog\_sidecar) | Whether the datadog sidecar should be added to the task definition | `bool` | `false` | no |
| <a name="input_enable_mem_scaling"></a> [enable\_mem\_scaling](#input\_enable\_mem\_scaling) | If autoscaling should be enabled based on Memory | `bool` | `true` | no |
| <a name="input_enable_nlb"></a> [enable\_nlb](#input\_enable\_nlb) | IF an network load balancer should be created | `bool` | `true` | no |
| <a name="input_enable_service_discovery"></a> [enable\_service\_discovery](#input\_enable\_service\_discovery) | Whether the service should be registered with Service Discovery. In order to use Service Disovery, an existing DNS Namespace must exist and be passed in. | `bool` | `false` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the environment | `string` | n/a | yes |
Expand Down
4 changes: 2 additions & 2 deletions autoscaling.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "aws_appautoscaling_target" "target" {

resource "aws_appautoscaling_policy" "auto_scaling_cpu" {

count = var.enable_asg ? 1 : 0
count = (var.enable_asg && var.enable_cpu_scaling) ? 1 : 0
name = "${var.environment}-${var.name}-cpu-scale"
policy_type = "TargetTrackingScaling"
resource_id = aws_appautoscaling_target.target[0].resource_id
Expand All @@ -40,7 +40,7 @@ resource "aws_appautoscaling_policy" "auto_scaling_cpu" {

resource "aws_appautoscaling_policy" "auto_scaling_mem" {

count = var.enable_asg ? 1 : 0
count = (var.enable_asg && var.enable_mem_scaling) ? 1 : 0
name = "${var.environment}-${var.name}-mem-scale"
policy_type = "TargetTrackingScaling"
resource_id = aws_appautoscaling_target.target[0].resource_id
Expand Down
13 changes: 13 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ variable "enable_asg" {
default = false
}

variable "enable_cpu_scaling" {
description = "If autoscaling should be enabled based on CPU"
type = bool
default = true
}

variable "enable_mem_scaling" {
description = "If autoscaling should be enabled based on Memory"
type = bool
default = true

}

variable "asg_max_tasks" {
description = "The amount of maximum tasks"
type = number
Expand Down
Loading