From 26ead74f6a2bf9fe50d30d8f09e9cbfd3a185ba4 Mon Sep 17 00:00:00 2001 From: Samuel Allan Date: Tue, 7 Apr 2026 07:12:04 +0930 Subject: [PATCH] fix: Avoid attempting to retrieve the AMI ID from SSM parameter if a custom AMI ID is provided (#3660) * 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 * fix: tidy checks for ami_id --- 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 52600fa..3958fad 100644 --- a/modules/self-managed-node-group/main.tf +++ b/modules/self-managed-node-group/main.tf @@ -44,7 +44,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 && var.ami_id == "" ? 1 : 0 region = var.region @@ -221,7 +222,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 = var.ami_id == "" ? nonsensitive(data.aws_ssm_parameter.ami[0].value) : var.ami_id instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior dynamic "instance_market_options" {