Skip to content

Commit 0928ff0

Browse files
authored
Merge pull request #27 from cruxstack/dev
feat: change interface for configuring spot or ondemand
2 parents 42d3671 + c78097d commit 0928ff0

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

main.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ locals {
22
enabled = coalesce(var.enabled, module.this.enabled, true)
33
name = coalesce(var.name, module.this.name, "teleport-cluster-${random_string.teleport_cluster_random_suffix.result}")
44

5-
aws_account_id = var.aws_account_id != "" ? var.aws_account_id : try(data.aws_caller_identity.current[0].account_id, "")
6-
aws_region_name = var.aws_region_name != "" ? var.aws_region_name : try(data.aws_region.current[0].name, "")
5+
aws_account_id = var.aws_account_id != "" ? var.aws_account_id : one(data.aws_caller_identity.current.*.account_id)
6+
aws_region_name = var.aws_region_name != "" ? var.aws_region_name : one(data.aws_region.current.*.region)
77
aws_kv_namespace = trim(coalesce(var.aws_kv_namespace, "teleport-cluster/${module.teleport_cluster_label.id}"), "/")
88

99
teleport_cluster_name = join("-", [module.teleport_cluster_label.name, module.teleport_cluster_label.stage, module.teleport_cluster_label.environment])
@@ -55,9 +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
60-
instance_spot_enabled = local.instance_config.auth.spot
58+
instance_sizes = local.instance_config.auth.sizes
59+
instance_count = local.instance_config.auth.count
60+
instance_spot = local.instance_config.auth.spot
6161

6262
teleport_cluster_name = local.teleport_cluster_name
6363
teleport_image_id = local.teleport_image_id
@@ -91,9 +91,9 @@ module "auth_servers" {
9191
module "proxy_servers" {
9292
source = "./modules/teleport-node"
9393

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
94+
instance_sizes = local.instance_config.proxy.sizes
95+
instance_count = local.instance_config.proxy.count
96+
instance_spot = local.instance_config.proxy.spot
9797

9898
teleport_cluster_name = local.teleport_cluster_name
9999
teleport_image_id = local.teleport_image_id
@@ -128,9 +128,9 @@ module "proxy_servers" {
128128
module "node_servers" {
129129
source = "./modules/teleport-node"
130130

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
131+
instance_sizes = local.instance_config.node.sizes
132+
instance_count = local.instance_config.node.count
133+
instance_spot = local.instance_config.node.spot
134134

135135
teleport_cluster_name = local.teleport_cluster_name
136136
teleport_image_id = local.teleport_image_id

modules/teleport-node/main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +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
26-
instance_spot_enabled = var.instance_spot_enabled
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 = var.instance_spot
2727

2828
dns_name = "${module.dns_label.id}.${var.dns_parent_zone_name}"
2929
dns_parent_zone_id = var.dns_parent_zone_id
@@ -339,8 +339,8 @@ resource "aws_autoscaling_group" "this" {
339339
mixed_instances_policy {
340340
instances_distribution {
341341
on_demand_base_capacity = 0
342-
on_demand_percentage_above_base_capacity = local.instance_spot_enabled ? 0 : 100
343-
spot_allocation_strategy = "capacity-optimized"
342+
on_demand_percentage_above_base_capacity = local.instance_spot.enabled ? 0 : 100
343+
spot_allocation_strategy = local.instance_spot.allocation_strategy
344344
spot_instance_pools = 0
345345
}
346346

modules/teleport-node/variables.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ variable "instance_sizes" {
6262
default = ["t3.medium", "t3a.medium"]
6363
}
6464

65-
variable "instance_spot_enabled" {
66-
type = bool
67-
default = true
65+
variable "instance_spot" {
66+
type = object({
67+
enabled = optional(bool, true)
68+
allocation_strategy = optional(string, "capacity-optimized")
69+
})
70+
default = {}
6871
}
6972

7073
# ----------------------------------------------------------- infrastructure ---

variables.tf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,29 @@ 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)
3332
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
33+
spot = optional(object({
34+
enabled = optional(bool, true)
35+
allocation_strategy = optional(string, "capacity-optimized")
36+
}), {})
3437
}), {})
3538
node = optional(object({
3639
count = optional(number, 1)
3740
sizes = optional(list(string), ["t3.micro", "t3a.micro"])
38-
spot = optional(bool, true)
3941
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
42+
spot = optional(object({
43+
enabled = optional(bool, true)
44+
allocation_strategy = optional(string, "capacity-optimized")
45+
}), {})
4046
}), {})
4147
proxy = optional(object({
4248
count = optional(number, 1)
4349
sizes = optional(list(string), ["t3.micro", "t3a.micro"])
44-
spot = optional(bool, true)
4550
allowed_cidrs = optional(list(string), ["0.0.0.0/0"])
51+
spot = optional(object({
52+
enabled = optional(bool, true)
53+
allocation_strategy = optional(string, "capacity-optimized")
54+
}), {})
4655
}), {})
4756
})
4857
description = "Configuration for the instances. Each type (`auth`, `node`, `proxy`) contains an object with `count`, `sizes`, and `allowed_cidrs`."

version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0.0, < 6.0.0"
7+
version = ">= 6.0.0"
88
}
99
random = {
1010
source = "hashicorp/random"

0 commit comments

Comments
 (0)