Skip to content

Commit f993c36

Browse files
authored
fix: Fix AMI filtering when the default platform is provided in var.workers_group_defaults (#1413)
1 parent 1d848b5 commit f993c36

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

local.tf

+22-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ locals {
66
cluster_iam_role_arn = var.manage_cluster_iam_resources ? join("", aws_iam_role.cluster.*.arn) : join("", data.aws_iam_role.custom_cluster_iam_role.*.arn)
77
worker_security_group_id = var.worker_create_security_group ? join("", aws_security_group.workers.*.id) : var.worker_security_group_id
88

9+
default_platform = "linux"
910
default_iam_role_id = concat(aws_iam_role.workers.*.id, [""])[0]
1011
default_ami_id_linux = local.workers_group_defaults.ami_id != "" ? local.workers_group_defaults.ami_id : concat(data.aws_ami.eks_worker.*.id, [""])[0]
1112
default_ami_id_windows = local.workers_group_defaults.ami_id_windows != "" ? local.workers_group_defaults.ami_id_windows : concat(data.aws_ami.eks_worker_windows.*.id, [""])[0]
@@ -15,8 +16,26 @@ locals {
1516
worker_group_count = length(var.worker_groups)
1617
worker_group_launch_template_count = length(var.worker_groups_launch_template)
1718

18-
worker_has_linux_ami = length([for x in concat(var.worker_groups, var.worker_groups_launch_template) : x if lookup(x, "platform", "linux") == "linux"]) > 0
19-
worker_has_windows_ami = length([for x in concat(var.worker_groups, var.worker_groups_launch_template) : x if lookup(x, "platform", "linux") == "windows"]) > 0
19+
worker_has_linux_ami = length([for x in concat(var.worker_groups, var.worker_groups_launch_template) : x if lookup(
20+
x,
21+
"platform",
22+
# Fallback on default `platform` if it's not defined in current worker group
23+
lookup(
24+
merge({ platform = local.default_platform }, var.workers_group_defaults),
25+
"platform",
26+
null
27+
)
28+
) == "linux"]) > 0
29+
worker_has_windows_ami = length([for x in concat(var.worker_groups, var.worker_groups_launch_template) : x if lookup(
30+
x,
31+
"platform",
32+
# Fallback on default `platform` if it's not defined in current worker group
33+
lookup(
34+
merge({ platform = local.default_platform }, var.workers_group_defaults),
35+
"platform",
36+
null
37+
)
38+
) == "windows"]) > 0
2039

2140
worker_ami_name_filter = var.worker_ami_name_filter != "" ? var.worker_ami_name_filter : "amazon-eks-node-${var.cluster_version}-v*"
2241
# Windows nodes are available from k8s 1.14. If cluster version is less than 1.14, fix ami filter to some constant to not fail on 'terraform plan'.
@@ -72,7 +91,7 @@ locals {
7291
placement_group = null # The name of the placement group into which to launch the instances, if any.
7392
service_linked_role_arn = "" # Arn of custom service linked role that Auto Scaling group will use. Useful when you have encrypted EBS
7493
termination_policies = [] # A list of policies to decide how the instances in the auto scale group should be terminated.
75-
platform = "linux" # Platform of workers. either "linux" or "windows"
94+
platform = local.default_platform # Platform of workers. Either "linux" or "windows".
7695
additional_ebs_volumes = [] # A list of additional volumes to be attached to the instances on this Auto Scaling group. Each volume should be an object with the following: block_device_name (required), volume_size, volume_type, iops, encrypted, kms_key_id (only on launch-template), delete_on_termination. Optional values are grabbed from root volume or from defaults
7796
additional_instance_store_volumes = [] # A list of additional instance store (local disk) volumes to be attached to the instances on this Auto Scaling group. Each volume should be an object with the following: block_device_name (required), virtual_name.
7897
warm_pool = null # If this block is configured, add a Warm Pool to the specified Auto Scaling group.

0 commit comments

Comments
 (0)