From e0367905f0debf9d7a8cb9b0c51b65732ea88994 Mon Sep 17 00:00:00 2001 From: pjoyce Date: Wed, 18 Mar 2026 18:00:01 -0400 Subject: [PATCH] add variables for custom source AMI owner, ssh interface, IAM profile, and subnet Change log update rm changelog entry packer fmt update variable descriptions simplify logic --- al2023.pkr.hcl | 18 ++++++++++-------- al2023arm.pkr.hcl | 18 ++++++++++-------- al2023gpu.pkr.hcl | 18 ++++++++++-------- al2023neu.pkr.hcl | 18 ++++++++++-------- variables.pkr.hcl | 24 ++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 32 deletions(-) diff --git a/al2023.pkr.hcl b/al2023.pkr.hcl index a293ab86..d048c3a0 100644 --- a/al2023.pkr.hcl +++ b/al2023.pkr.hcl @@ -32,17 +32,19 @@ source "amazon-ebs" "al2023" { filters = { name = "${var.source_ami_al2023}" } - owners = ["amazon"] + owners = var.source_ami_owners most_recent = true include_deprecated = true } - ami_ou_arns = "${var.ami_ou_arns}" - ami_org_arns = "${var.ami_org_arns}" - ami_users = "${var.ami_users}" - ssh_interface = "public_ip" - ssh_username = "ec2-user" - tags = "${local.merged_tags}" - run_tags = "${var.run_tags}" + ami_ou_arns = "${var.ami_ou_arns}" + ami_org_arns = "${var.ami_org_arns}" + ami_users = "${var.ami_users}" + ssh_interface = "${var.ssh_interface}" + ssh_username = "ec2-user" + iam_instance_profile = "${var.iam_instance_profile}" + subnet_id = "${var.subnet_id}" + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } build { diff --git a/al2023arm.pkr.hcl b/al2023arm.pkr.hcl index f2cd6402..7cf044e9 100644 --- a/al2023arm.pkr.hcl +++ b/al2023arm.pkr.hcl @@ -32,15 +32,17 @@ source "amazon-ebs" "al2023arm" { filters = { name = "${var.source_ami_al2023arm}" } - owners = ["amazon"] + owners = var.source_ami_owners most_recent = true include_deprecated = true } - ami_ou_arns = "${var.ami_ou_arns}" - ami_org_arns = "${var.ami_org_arns}" - ami_users = "${var.ami_users}" - ssh_interface = "public_ip" - ssh_username = "ec2-user" - tags = "${local.merged_tags_al2023arm}" - run_tags = "${var.run_tags}" + ami_ou_arns = "${var.ami_ou_arns}" + ami_org_arns = "${var.ami_org_arns}" + ami_users = "${var.ami_users}" + ssh_interface = "${var.ssh_interface}" + ssh_username = "ec2-user" + iam_instance_profile = "${var.iam_instance_profile}" + subnet_id = "${var.subnet_id}" + tags = "${local.merged_tags_al2023arm}" + run_tags = "${var.run_tags}" } diff --git a/al2023gpu.pkr.hcl b/al2023gpu.pkr.hcl index 9b8e549e..b58d276f 100644 --- a/al2023gpu.pkr.hcl +++ b/al2023gpu.pkr.hcl @@ -32,15 +32,17 @@ source "amazon-ebs" "al2023gpu" { filters = { name = "${var.source_ami_al2023}" } - owners = ["amazon"] + owners = var.source_ami_owners most_recent = true include_deprecated = true } - ami_ou_arns = "${var.ami_ou_arns}" - ami_org_arns = "${var.ami_org_arns}" - ami_users = "${var.ami_users}" - ssh_interface = "public_ip" - ssh_username = "ec2-user" - tags = "${local.merged_tags_al2023gpu}" - run_tags = "${var.run_tags}" + ami_ou_arns = "${var.ami_ou_arns}" + ami_org_arns = "${var.ami_org_arns}" + ami_users = "${var.ami_users}" + ssh_interface = "${var.ssh_interface}" + ssh_username = "ec2-user" + iam_instance_profile = "${var.iam_instance_profile}" + subnet_id = "${var.subnet_id}" + tags = "${local.merged_tags_al2023gpu}" + run_tags = "${var.run_tags}" } diff --git a/al2023neu.pkr.hcl b/al2023neu.pkr.hcl index 9ae01427..3c6caa49 100644 --- a/al2023neu.pkr.hcl +++ b/al2023neu.pkr.hcl @@ -32,15 +32,17 @@ source "amazon-ebs" "al2023neu" { filters = { name = "${var.source_ami_al2023}" } - owners = ["amazon"] + owners = var.source_ami_owners most_recent = true include_deprecated = true } - ami_ou_arns = "${var.ami_ou_arns}" - ami_org_arns = "${var.ami_org_arns}" - ami_users = "${var.ami_users}" - ssh_interface = "public_ip" - ssh_username = "ec2-user" - tags = "${local.merged_tags_al2023neu}" - run_tags = "${var.run_tags}" + ami_ou_arns = "${var.ami_ou_arns}" + ami_org_arns = "${var.ami_org_arns}" + ami_users = "${var.ami_users}" + ssh_interface = "${var.ssh_interface}" + ssh_username = "ec2-user" + iam_instance_profile = "${var.iam_instance_profile}" + subnet_id = "${var.subnet_id}" + tags = "${local.merged_tags_al2023neu}" + run_tags = "${var.run_tags}" } diff --git a/variables.pkr.hcl b/variables.pkr.hcl index c845d161..79b80f1e 100644 --- a/variables.pkr.hcl +++ b/variables.pkr.hcl @@ -129,6 +129,30 @@ variable "source_ami_al2023arm" { description = "Amazon Linux 2023 ARM source AMI to build from." } +variable "source_ami_owners" { + type = list(string) + description = "Accounts to search when filtering source AMIs. Defaults to Amazon-owned AMIs." + default = ["amazon"] +} + +variable "ssh_interface" { + type = string + description = "SSH interface for the build instance." + default = "public_ip" +} + +variable "iam_instance_profile" { + type = string + description = "IAM instance profile to attach to the build instance. Required when ssh_interface is 'session_manager'." + default = null +} + +variable "subnet_id" { + type = string + description = "VPC subnet ID for the build instance. Must support the connectivity method specified by 'ssh_interface'." + default = null +} + variable "kernel_version_al2023" { type = string description = "Amazon Linux 2023 kernel version."