Skip to content

Commit

Permalink
Spot capacity (#14)
Browse files Browse the repository at this point in the history
* added spot capacity

* improved weight calculation

* fix devide by 0

* fix 100% issue

* fix calculation

* fix logic in calc

* moved locals

* fix calculation

* fix calc

* fix cal

* add graviton to capacity providers
  • Loading branch information
marciogoda authored May 20, 2024
1 parent 9f473c2 commit f9dcf64
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 17 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,30 @@ module "ecs_update_monitor" {
}

locals {
p = var.spot_capacity_percentage <= 50 ? var.spot_capacity_percentage : 100 - var.spot_capacity_percentage
lower_weight = ceil(local.p / 100)
higher_weight = local.lower_weight == 0 ? 1 : (floor(local.lower_weight / (local.p / 100)) - local.lower_weight)
spot_weight = var.spot_capacity_percentage <= 50 ? local.lower_weight : local.higher_weight
ondemand_weight = var.spot_capacity_percentage <= 50 ? local.higher_weight : local.lower_weight

capacity_providers = var.image_build_details["buildx"] == "true" && can(regexall("^arm64", var.image_build_details["platforms"])) ? [
{
capacity_provider = "${var.ecs_cluster}-native-scaling-graviton"
weight = 1
weight = local.ondemand_weight
},
{
capacity_provider = "${var.ecs_cluster}-native-scaling-graviton-spot"
weight = local.spot_weight
}
] : [
{
capacity_provider = "${var.ecs_cluster}-native-scaling"
weight = 1
},
weight = local.ondemand_weight
},
{
capacity_provider = "${var.ecs_cluster}-native-scaling-spot"
weight = local.spot_weight
}
]
}

Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,10 @@ variable "image_build_details" {
"buildx" = "false",
"platforms" = ""
}
}

variable "spot_capacity_percentage" {
default = 33
type = number
description = "Percentage of tasks to run on spot instances"
}

0 comments on commit f9dcf64

Please sign in to comment.