From 4189008c4426455fb22a3d519e58e9272d1d176f Mon Sep 17 00:00:00 2001 From: Samuel Allan Date: Wed, 18 Mar 2026 16:31:35 +1030 Subject: [PATCH] fix: don't retrieve ssm param if custom ami used The ssm param for the recommended ami is not used if a custom ami is used. Also, if one wishes to use a custom ami with the older AL2 ami_type (uses bootstrap.sh for user_data in launch templates), retrieving the ssm param fails with k8s >= 1.33 due to the AL2 images being removed: Error: reading SSM Parameter (/aws/service/eks/optimized-ami/1.34/amazon-linux-2/recommended/image_id): couldn't find resource Private-ref: https://tasks.opencraft.com/browse/BB-10631 --- modules/self-managed-node-group/main.tf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/self-managed-node-group/main.tf b/modules/self-managed-node-group/main.tf index 8a65dc6a66..64eba7c6be 100644 --- a/modules/self-managed-node-group/main.tf +++ b/modules/self-managed-node-group/main.tf @@ -42,7 +42,8 @@ locals { } data "aws_ssm_parameter" "ami" { - count = var.create ? 1 : 0 + # only pull the ami if we're creating the resource AND we're not already using a custom ami + count = var.create && length(var.ami_id) == 0 ? 1 : 0 region = var.region @@ -219,7 +220,7 @@ resource "aws_launch_template" "this" { arn = var.create_iam_instance_profile ? aws_iam_instance_profile.this[0].arn : var.iam_instance_profile_arn } - image_id = coalesce(var.ami_id, nonsensitive(data.aws_ssm_parameter.ami[0].value)) + image_id = coalesce(var.ami_id, nonsensitive(try(data.aws_ssm_parameter.ami[0].value, ""))) instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior dynamic "instance_market_options" {