Skip to content

Commit

Permalink
improved weight calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
marciogoda committed May 2, 2024
1 parent f448447 commit f4d43e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
locals {
service_name = "${var.env}-${var.release["component"]}"
full_service_name = "${local.service_name}${var.name_suffix}"
lower_weight = ceil((var.spot_capacity_percentage / 100))
high_weight = floor(local.lower_weight / (var.spot_capacity_percentage / 100))
spot_weight = var.spot_capacity_percentage <= 50 ? local.lower_weight : local.high_weight
ondemand_weight = var.spot_capacity_percentage <= 50 ? local.high_weight : local.lower_weight
}

module "ecs_update_monitor" {
Expand All @@ -18,20 +22,20 @@ locals {
capacity_providers = var.image_build_details["buildx"] == "true" && can(regexall("^arm64", var.image_build_details["platforms"])) ? [
{
capacity_provider = "${var.ecs_cluster}-native-scaling"
weight = 2
weight = local.ondemand_weight
},
{
capacity_provider = "${var.ecs_cluster}-native-spot-scaling"
weight = var.capacity_provider_spot_tasks_weight
capacity_provider = "${var.ecs_cluster}-native-scaling-spot"
weight = local.spot_weight
}
] : [
{
capacity_provider = "${var.ecs_cluster}-native-scaling"
weight = 2
weight = local.ondemand_weight
},
{
capacity_provider = "${var.ecs_cluster}-native-spot-scaling"
weight = var.capacity_provider_spot_tasks_weight
capacity_provider = "${var.ecs_cluster}-native-scaling-spot"
weight = local.spot_weight
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ variable "image_build_details" {
}
}

variable "capacity_provider_spot_tasks_weight" {
default = 1
variable "spot_capacity_percentage" {
default = 20
type = number
description = "Weight "
description = "Percentage of tasks to run on spot instances"
}

0 comments on commit f4d43e1

Please sign in to comment.