From bd8a1e55c4f6dd6a57d721915b07cd46725e9005 Mon Sep 17 00:00:00 2001 From: Joe Ferris Date: Wed, 6 Dec 2023 16:12:32 -0500 Subject: [PATCH] Allow Spot capacity type for AWS node groups The underlying Terraform resource accepts a capacity type to determine on-demand or spot compute, but we don't currently pass it. This uses the default of on-demand but allows overriding it for creation of Spot node groups. --- aws/cluster/README.md | 2 +- aws/cluster/main.tf | 1 + aws/cluster/modules/eks-node-group/README.md | 1 + aws/cluster/modules/eks-node-group/main.tf | 1 + aws/cluster/modules/eks-node-group/variables.tf | 6 ++++++ aws/cluster/variables.tf | 1 + 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aws/cluster/README.md b/aws/cluster/README.md index c4b7fe50..70ac0d68 100644 --- a/aws/cluster/README.md +++ b/aws/cluster/README.md @@ -100,7 +100,7 @@ module "cluster" { | [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | How many days until control plane logs are purged | `number` | `7` | no | | [name](#input\_name) | Name for this EKS cluster | `string` | n/a | yes | | [namespace](#input\_namespace) | Prefix to be applied to created resources | `list(string)` | `[]` | no | -| [node\_groups](#input\_node\_groups) | Node groups to create in this cluster |
map(object({
instance_types = list(string),
max_size = number
min_size = number
}))
| n/a | yes | +| [node\_groups](#input\_node\_groups) | Node groups to create in this cluster |
map(object({
capacity_type = optional(string, "ON_DEMAND")
instance_types = list(string),
max_size = number
min_size = number
}))
| n/a | yes | | [tags](#input\_tags) | Tags to be applied to all created resources | `map(string)` | `{}` | no | ## Outputs diff --git a/aws/cluster/main.tf b/aws/cluster/main.tf index 8aa92be6..caceb270 100644 --- a/aws/cluster/main.tf +++ b/aws/cluster/main.tf @@ -39,6 +39,7 @@ module "node_groups" { for_each = var.node_groups source = "./modules/eks-node-group" + capacity_type = each.value.capacity_type cluster = module.eks_cluster.instance instance_types = each.value.instance_types max_size = each.value.max_size diff --git a/aws/cluster/modules/eks-node-group/README.md b/aws/cluster/modules/eks-node-group/README.md index db52d317..6ffcdc0a 100644 --- a/aws/cluster/modules/eks-node-group/README.md +++ b/aws/cluster/modules/eks-node-group/README.md @@ -22,6 +22,7 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [capacity\_type](#input\_capacity\_type) | Allow values: ON\_DEMAND (default), SPOT | `string` | `"ON_DEMAND"` | no | | [cluster](#input\_cluster) | Cluster which this node group should join | `object({ name = string })` | n/a | yes | | [instance\_types](#input\_instance\_types) | EC2 instance types allowed in this node group | `list(string)` |
[
"t3.medium"
]
| no | | [max\_size](#input\_max\_size) | Maximum number of nodes in this group | `number` | n/a | yes | diff --git a/aws/cluster/modules/eks-node-group/main.tf b/aws/cluster/modules/eks-node-group/main.tf index 79fa53f9..ecc2920b 100644 --- a/aws/cluster/modules/eks-node-group/main.tf +++ b/aws/cluster/modules/eks-node-group/main.tf @@ -1,6 +1,7 @@ resource "aws_eks_node_group" "this" { for_each = local.subnets + capacity_type = var.capacity_type cluster_name = var.cluster.name instance_types = var.instance_types node_group_name = join("-", concat(var.namespace, [var.name, each.key])) diff --git a/aws/cluster/modules/eks-node-group/variables.tf b/aws/cluster/modules/eks-node-group/variables.tf index 4e75c6ac..8f678fc8 100644 --- a/aws/cluster/modules/eks-node-group/variables.tf +++ b/aws/cluster/modules/eks-node-group/variables.tf @@ -1,3 +1,9 @@ +variable "capacity_type" { + type = string + default = "ON_DEMAND" + description = "Allow values: ON_DEMAND (default), SPOT" +} + variable "cluster" { type = object({ name = string }) description = "Cluster which this node group should join" diff --git a/aws/cluster/variables.tf b/aws/cluster/variables.tf index f868f4a8..c9353dd9 100644 --- a/aws/cluster/variables.tf +++ b/aws/cluster/variables.tf @@ -30,6 +30,7 @@ variable "node_groups" { description = "Node groups to create in this cluster" type = map(object({ + capacity_type = optional(string, "ON_DEMAND") instance_types = list(string), max_size = number min_size = number