Skip to content

Commit

Permalink
fix: Avoid attempting to retrieve the AMI ID from SSM parameter if a …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Samuel Allan authored and GitHub committed Apr 6, 2026
1 parent 3269c34 commit 26ead74
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/self-managed-node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 26ead74

Please sign in to comment.