Skip to content

Commit f5402f4

Browse files
committed
EKS: Determine ami_type for node pool based on instance_type
1 parent 191f4a5 commit f5402f4

File tree

7 files changed

+26
-0
lines changed

7 files changed

+26
-0
lines changed

aws/_modules/eks/node_pool.tf

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module "node_pool" {
2020

2121
taints = var.taints
2222

23+
ami_type = null
24+
2325
# force node_pool to depend on aws-auth configmap
2426
depends-on-aws-auth = {
2527
name = kubernetes_config_map.current.metadata[0].name

aws/_modules/eks/node_pool/main.tf

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
data "aws_ec2_instance_type" "current" {
2+
# ami_type is always determined by the first instance_type in the list
3+
instance_type = element(tolist(var.instance_types), 0)
4+
}
5+
6+
locals {
7+
cpu_ami_type = data.aws_ec2_instance_type.current.supported_architectures[0] == "arm64" ? "AL2_ARM_64" : "AL2_x86_64"
8+
ami_type = length(data.aws_ec2_instance_type.current.gpus) > 0 ? "AL2_x86_64_GPU" : local.cpu_ami_type
9+
}
10+
111
resource "aws_eks_node_group" "nodes" {
212
cluster_name = var.cluster_name
313
node_group_name = var.node_group_name
@@ -10,6 +20,7 @@ resource "aws_eks_node_group" "nodes" {
1020
min_size = var.min_size
1121
}
1222

23+
ami_type = var.ami_type == null ? local.ami_type : var.ami_type
1324
instance_types = var.instance_types
1425
disk_size = var.disk_size
1526

aws/_modules/eks/node_pool/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ variable "labels" {
7979
description = "Kubernetes labels to set on the nodes created by the node pool. Merged with Kubestack default labels."
8080
default = {}
8181
}
82+
83+
variable "ami_type" {
84+
type = string
85+
description = "AMI type to use for nodes of the node pool."
86+
}

aws/cluster/node-pool/configuration.tf

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ locals {
1616
max_size = lookup(local.cfg, "max_size")
1717
disk_size = lookup(local.cfg, "disk_size", null)
1818

19+
ami_type = lookup(local.cfg, "ami_type")
20+
1921
availability_zones_lookup = local.cfg["availability_zones"] == null ? "" : local.cfg["availability_zones"]
2022
availability_zones = compact(split(",", local.availability_zones_lookup))
2123

aws/cluster/node-pool/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module "node_pool" {
1515
max_size = local.max_size
1616
min_size = local.min_size
1717

18+
ami_type = local.ami_type
19+
1820
disk_size = local.disk_size
1921

2022
taints = local.taints

aws/cluster/node-pool/variables.tf

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ variable "configuration" {
99
max_size = optional(string)
1010
disk_size = optional(string)
1111

12+
ami_type = optional(string)
13+
1214
availability_zones = optional(string)
1315

1416
vpc_subnet_ids = optional(string)

tests/eks_zero_node_pools.tf

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ module "eks_zero_node_pool_existing_subnets_one_az_only" {
5454
desired_capacity = 1
5555
min_size = 1
5656
max_size = 3
57+
58+
ami_type = "AL2_x86_64_GPU"
5759
}
5860

5961
# Settings for Ops-cluster

0 commit comments

Comments
 (0)