Skip to content

Commit

Permalink
Merge pull request #16 from lagerfeuer/master
Browse files Browse the repository at this point in the history
Allow selectively enabling CPU and Memory based autoscaling
  • Loading branch information
robertomoutinho authored Jan 8, 2024
2 parents c7c693f + bc6e98e commit 81aae56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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

0 comments on commit 81aae56

Please sign in to comment.