Skip to content

Commit c0c8d85

Browse files
authored
Merge pull request #323 from mark5cinco/eks-support-node-release-version-config
Eks support node release version config
2 parents c0b6789 + ad749c8 commit c0c8d85

File tree

10 files changed

+41
-16
lines changed

10 files changed

+41
-16
lines changed

aws/_modules/eks/node_pool.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module "node_pool" {
2222

2323
taints = var.taints
2424

25-
ami_type = null
25+
ami_type = null
26+
ami_release_version = var.worker_ami_release_version
2627

2728
tags = var.additional_node_tags
2829

aws/_modules/eks/node_pool/launch_template.tf

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ locals {
55
launch_template_name_hash = sha256(local.launch_template_name_parts)
66
launch_template_name = "${substr(local.launch_template_name_parts, 0, 120)}-${substr(local.launch_template_name_hash, 0, 7)}"
77

8-
cpu_ami_name = data.aws_ec2_instance_type.current.supported_architectures[0] == "arm64" ? "amazon-linux-2-arm64" : "amazon-linux-2"
9-
ami_name = length(data.aws_ec2_instance_type.current.gpus) > 0 ? "amazon-linux-2-gpu" : local.cpu_ami_name
8+
cpu_ami_name = data.aws_ec2_instance_type.current.supported_architectures[0] == "arm64" ? "amazon-linux-2-arm64" : "amazon-linux-2"
9+
is_gpu = length(data.aws_ec2_instance_type.current.gpus) > 0
10+
ami_name = local.is_gpu ? "amazon-linux-2-gpu" : local.cpu_ami_name
11+
ami_release_prefix = local.is_gpu ? "amazon-eks-gpu-node" : "amazon-eks-node"
12+
ami_release_date = split("-", var.ami_release_version)[1]
13+
ami_release_name = var.ami_release_version == null ? "recommended" : "${local.ami_release_prefix}-${var.kubernetes_version}-v${local.ami_release_date}"
1014
}
1115

1216
data "aws_ssm_parameter" "eks_ami_release_version" {
1317
count = var.disk_size != null ? 1 : 0
1418

15-
name = "/aws/service/eks/optimized-ami/${var.kubernetes_version}/${local.ami_name}/recommended/image_id"
19+
name = "/aws/service/eks/optimized-ami/${var.kubernetes_version}/${local.ami_name}/${local.ami_release_name}/image_id"
1620
}
1721

1822
data "aws_ami" "eks_optimized" {

aws/_modules/eks/node_pool/main.tf

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ resource "aws_eks_node_group" "nodes" {
2020
min_size = var.min_size
2121
}
2222

23-
version = var.kubernetes_version
24-
ami_type = var.ami_type == null ? local.ami_type : var.ami_type
25-
instance_types = var.instance_types
23+
version = var.kubernetes_version
24+
ami_type = var.ami_type == null ? local.ami_type : var.ami_type
25+
release_version = var.ami_release_version
26+
instance_types = var.instance_types
2627

2728
disk_size = local.create_launch_template ? null : var.disk_size
2829

aws/_modules/eks/node_pool/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ variable "ami_type" {
8585
description = "AMI type to use for nodes of the node pool."
8686
}
8787

88+
variable "ami_release_version" {
89+
type = string
90+
description = "AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version"
91+
default = null
92+
}
93+
8894
variable "kubernetes_version" {
8995
type = string
9096
description = "Kubernetes version to use for node pool."

aws/_modules/eks/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ variable "cluster_encryption_key_arn" {
172172
description = "Arn of an AWS KMS symmetric key to be used for encryption of kubernetes resources."
173173
}
174174

175+
variable "worker_ami_release_version" {
176+
type = string
177+
default = null
178+
description = "AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version. A list of release versions can be found in https://github.com/awslabs/amazon-eks-ami/blob/master/CHANGELOG.md"
179+
}
180+
175181
variable "metadata_options" {
176182
description = "EC2 metadata service options."
177183
type = object({

aws/cluster/configuration.tf

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ locals {
6767
worker_root_device_volume_size = lookup(local.cfg, "worker_root_device_volume_size", null)
6868
worker_root_device_encrypted = lookup(local.cfg, "worker_root_device_encrypted", null)
6969

70+
worker_ami_release_version = lookup(local.cfg, "worker_ami_release_version", null)
71+
7072
cluster_aws_auth_map_roles = lookup(local.cfg, "cluster_aws_auth_map_roles", "")
7173
cluster_aws_auth_map_users = lookup(local.cfg, "cluster_aws_auth_map_users", "")
7274
cluster_aws_auth_map_accounts = lookup(local.cfg, "cluster_aws_auth_map_accounts", "")

aws/cluster/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ module "cluster" {
5959

6060
cluster_encryption_key_arn = local.cluster_encryption_key_arn
6161

62+
worker_ami_release_version = local.worker_ami_release_version
63+
6264
# cluster module configuration is still map(string)
6365
# once module_variable_optional_attrs isn't experimental anymore
6466
# we can migrate cluster module configuration to map(object(...))

aws/cluster/node-pool/configuration.tf

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ locals {
1111

1212
instance_types_lookup = local.cfg["instance_types"] == null ? "" : local.cfg["instance_types"]
1313
instance_types = toset(split(",", local.instance_types_lookup))
14+
ami_release_version = lookup(local.cfg, "ami_release_version")
1415
desired_capacity = lookup(local.cfg, "desired_capacity")
1516
min_size = lookup(local.cfg, "min_size")
1617
max_size = lookup(local.cfg, "max_size")

aws/cluster/node-pool/main.tf

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ module "node_pool" {
2020

2121
subnet_ids = local.vpc_subnet_newbits == null ? local.vpc_subnet_ids : aws_subnet.current.*.id
2222

23-
instance_types = local.instance_types
24-
desired_size = local.desired_capacity
25-
max_size = local.max_size
26-
min_size = local.min_size
23+
instance_types = local.instance_types
24+
ami_release_version = local.ami_release_version
25+
desired_size = local.desired_capacity
26+
max_size = local.max_size
27+
min_size = local.min_size
2728

2829
ami_type = local.ami_type
2930

aws/cluster/node-pool/variables.tf

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ variable "configuration" {
33

44
name = optional(string)
55

6-
instance_types = optional(string)
7-
desired_capacity = optional(string)
8-
min_size = optional(string)
9-
max_size = optional(string)
10-
disk_size = optional(string)
6+
instance_types = optional(string)
7+
ami_release_version = optional(string)
8+
desired_capacity = optional(string)
9+
min_size = optional(string)
10+
max_size = optional(string)
11+
disk_size = optional(string)
1112

1213
ami_type = optional(string)
1314

0 commit comments

Comments
 (0)