Skip to content

Commit

Permalink
fix: downscale (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 authored Feb 27, 2024
1 parent 53c9f1c commit b94e8f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
11 changes: 7 additions & 4 deletions terraform/ecs/cluster.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
locals {
image = "${var.ecr_repository_url}:${var.image_version}"

task_cpu = module.this.stage == "prod" ? var.task_cpu : 256
task_memory = module.this.stage == "prod" ? var.task_memory : 512

otel_port = var.port + 1
otel_cpu = 128
otel_memory = 128
Expand All @@ -12,8 +15,8 @@ locals {
module "ecs_cpu_mem" {
source = "app.terraform.io/wallet-connect/ecs_cpu_mem/aws"
version = "1.0.0"
cpu = var.task_cpu + local.otel_cpu
memory = var.task_memory + local.otel_memory
cpu = local.task_cpu
memory = local.task_memory
}

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -60,8 +63,8 @@ resource "aws_ecs_task_definition" "app_task" {
{
name = module.this.id,
image = local.image,
cpu = var.task_cpu,
memory = var.task_memory,
cpu = local.task_cpu - local.otel_cpu,
memory = local.task_memory - local.otel_memory,
essential = true,

environment = [for each in [
Expand Down
6 changes: 5 additions & 1 deletion terraform/ecs/cluster_autoscaling.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
locals {
autoscaling_min_capacity = module.this.stage == "prod" ? var.autoscaling_min_capacity : 1
}

resource "aws_appautoscaling_target" "ecs_target" {
min_capacity = var.autoscaling_min_capacity
min_capacity = local.autoscaling_min_capacity
max_capacity = var.autoscaling_max_capacity
resource_id = "service/${aws_ecs_cluster.app_cluster.name}/${aws_ecs_service.app_service.name}"
scalable_dimension = "ecs:service:DesiredCount"
Expand Down
2 changes: 1 addition & 1 deletion terraform/postgres/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module "db_cluster" {
cloudwatch_log_group_retention_in_days = var.cloudwatch_retention_in_days

serverlessv2_scaling_configuration = {
min_capacity = var.min_capacity
min_capacity = module.this.stage == "prod" ? var.min_capacity : 0.5
max_capacity = var.max_capacity
}
}
4 changes: 2 additions & 2 deletions terraform/res_application.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module "ecs" {
ecr_repository_url = local.ecr_repository_url
image_version = var.image_version
task_execution_role_name = aws_iam_role.application_role.name
task_cpu = 8064 # 8192 - 128
task_memory = 16256 # 16384-128
task_cpu = 4096
task_memory = 8192
autoscaling_desired_count = var.app_autoscaling_desired_count
autoscaling_min_capacity = var.app_autoscaling_min_capacity
autoscaling_max_capacity = var.app_autoscaling_max_capacity
Expand Down

0 comments on commit b94e8f4

Please sign in to comment.