Skip to content

Commit 42d3671

Browse files
authored
Merge pull request #26 from cruxstack/dev
feat: support on-demand instances
2 parents 1c4c984 + 12e2683 commit 42d3671

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ resource "random_string" "teleport_cluster_random_suffix" {
5555
module "auth_servers" {
5656
source = "./modules/teleport-node"
5757

58-
instance_sizes = local.instance_config.auth.sizes
59-
instance_count = local.instance_config.auth.count
58+
instance_sizes = local.instance_config.auth.sizes
59+
instance_count = local.instance_config.auth.count
60+
instance_spot_enabled = local.instance_config.auth.spot
6061

6162
teleport_cluster_name = local.teleport_cluster_name
6263
teleport_image_id = local.teleport_image_id
@@ -90,8 +91,9 @@ module "auth_servers" {
9091
module "proxy_servers" {
9192
source = "./modules/teleport-node"
9293

93-
instance_sizes = local.instance_config.proxy.sizes
94-
instance_count = local.instance_config.proxy.count
94+
instance_sizes = local.instance_config.proxy.sizes
95+
instance_count = local.instance_config.proxy.count
96+
instance_spot_enabled = local.instance_config.proxy.spot
9597

9698
teleport_cluster_name = local.teleport_cluster_name
9799
teleport_image_id = local.teleport_image_id
@@ -126,8 +128,9 @@ module "proxy_servers" {
126128
module "node_servers" {
127129
source = "./modules/teleport-node"
128130

129-
instance_sizes = local.instance_config.node.sizes
130-
instance_count = local.instance_config.node.count
131+
instance_sizes = local.instance_config.node.sizes
132+
instance_count = local.instance_config.node.count
133+
instance_spot_enabled = local.instance_config.node.spot
131134

132135
teleport_cluster_name = local.teleport_cluster_name
133136
teleport_image_id = local.teleport_image_id

modules/teleport-node/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ locals {
1919
logs_bucket_name = var.logs_bucket_name
2020
experimental = var.experimental
2121

22-
desired_capacity = local.teleport_setup_enabled ? (local.teleport_node_type == "auth" ? 1 : 0) : var.instance_count
23-
min_capacity = local.teleport_setup_enabled ? (local.teleport_node_type == "auth" ? 1 : 0) : var.instance_count
24-
max_capacity = local.teleport_setup_enabled ? (local.teleport_node_type == "auth" ? 1 : 0) : var.instance_count
25-
instance_sizes = var.instance_sizes
22+
desired_capacity = local.teleport_setup_enabled ? (local.teleport_node_type == "auth" ? 1 : 0) : var.instance_count
23+
min_capacity = local.teleport_setup_enabled ? (local.teleport_node_type == "auth" ? 1 : 0) : var.instance_count
24+
max_capacity = local.teleport_setup_enabled ? (local.teleport_node_type == "auth" ? 1 : 0) : var.instance_count
25+
instance_sizes = var.instance_sizes
26+
instance_spot_enabled = var.instance_spot_enabled
2627

2728
dns_name = "${module.dns_label.id}.${var.dns_parent_zone_name}"
2829
dns_parent_zone_id = var.dns_parent_zone_id
@@ -338,7 +339,7 @@ resource "aws_autoscaling_group" "this" {
338339
mixed_instances_policy {
339340
instances_distribution {
340341
on_demand_base_capacity = 0
341-
on_demand_percentage_above_base_capacity = 0
342+
on_demand_percentage_above_base_capacity = local.instance_spot_enabled ? 0 : 100
342343
spot_allocation_strategy = "capacity-optimized"
343344
spot_instance_pools = 0
344345
}

modules/teleport-node/variables.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ variable "experimental" {
5252

5353
# ----------------------------------------------------------------- instance ---
5454

55-
5655
variable "instance_count" {
5756
type = number
5857
default = 1
@@ -63,6 +62,11 @@ variable "instance_sizes" {
6362
default = ["t3.medium", "t3a.medium"]
6463
}
6564

65+
variable "instance_spot_enabled" {
66+
type = bool
67+
default = true
68+
}
69+
6670
# ----------------------------------------------------------- infrastructure ---
6771

6872
variable "artifacts_bucket_name" {

variables.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ variable "instance_config" {
2929
auth = optional(object({
3030
count = optional(number, 1)
3131
sizes = optional(list(string), ["t3.micro", "t3a.micro"])
32+
spot = optional(bool, true)
3233
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
3334
}), {})
3435
node = optional(object({
3536
count = optional(number, 1)
3637
sizes = optional(list(string), ["t3.micro", "t3a.micro"])
38+
spot = optional(bool, true)
3739
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
3840
}), {})
3941
proxy = optional(object({
4042
count = optional(number, 1)
4143
sizes = optional(list(string), ["t3.micro", "t3a.micro"])
44+
spot = optional(bool, true)
4245
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
4346
}), {})
4447
})

0 commit comments

Comments
 (0)