From 4b0cd071524d45a33f292e93fc499b1220f177fd Mon Sep 17 00:00:00 2001 From: Guillaume Delacour Date: Tue, 3 Dec 2024 19:40:53 +0100 Subject: [PATCH] Overrides for tags and run_tags (#303) Overrides for tags and run_tags --- al1.pkr.hcl | 19 +++++++++++-------- al2.pkr.hcl | 19 +++++++++++-------- al2023.pkr.hcl | 19 +++++++++++-------- al2023arm.pkr.hcl | 19 +++++++++++-------- al2023neu.pkr.hcl | 19 +++++++++++-------- al2arm.pkr.hcl | 19 +++++++++++-------- al2gpu.pkr.hcl | 19 +++++++++++-------- al2inf.pkr.hcl | 19 +++++++++++-------- al2keplergpu.pkr.hcl | 19 +++++++++++-------- al2kernel5dot10.pkr.hcl | 19 +++++++++++-------- al2kernel5dot10arm.pkr.hcl | 19 +++++++++++-------- al2kernel5dot10gpu.pkr.hcl | 19 +++++++++++-------- al2kernel5dot10inf.pkr.hcl | 19 +++++++++++-------- variables.pkr.hcl | 12 ++++++++++++ 14 files changed, 155 insertions(+), 104 deletions(-) diff --git a/al1.pkr.hcl b/al1.pkr.hcl index 0761002..257b3b5 100644 --- a/al1.pkr.hcl +++ b/al1.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al1 = "${var.ami_name_prefix_al1}${var.ami_version_al1}-amazon-ecs-optimized" + default_tags = { + os_version = "Amazon Linux" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version_al1}" + ecs_agent_version = "${var.ecs_version_al1}" + ami_type = "al1" + ami_version = "2018.03.${var.ami_version_al1}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al1" { @@ -33,14 +42,8 @@ source "amazon-ebs" "al1" { user_data_file = "scripts/al1/user_data.sh" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version_al1}" - ecs_agent_version = "${var.ecs_version_al1}" - ami_type = "al1" - ami_version = "2018.03.${var.ami_version_al1}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } build { diff --git a/al2.pkr.hcl b/al2.pkr.hcl index 1e21d6a..d756a4f 100644 --- a/al2.pkr.hcl +++ b/al2.pkr.hcl @@ -6,6 +6,15 @@ locals { "69-available-updates-begin", "71-available-updates-finish" ] + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2" { @@ -32,14 +41,8 @@ source "amazon-ebs" "al2" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } build { diff --git a/al2023.pkr.hcl b/al2023.pkr.hcl index f632bb7..b4041de 100644 --- a/al2023.pkr.hcl +++ b/al2023.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2023 = "${var.ami_name_prefix_al2023}-hvm-2023.0.${var.ami_version_al2023}${var.kernel_version_al2023}-x86_64" + default_tags = { + os_version = "Amazon Linux 2023" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version_al2023}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2023" + ami_version = "2023.0.${var.ami_version_al2023}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2023" { @@ -26,14 +35,8 @@ source "amazon-ebs" "al2023" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2023" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version_al2023}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2023" - ami_version = "2023.0.${var.ami_version_al2023}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } build { diff --git a/al2023arm.pkr.hcl b/al2023arm.pkr.hcl index a35ca35..d50fa36 100644 --- a/al2023arm.pkr.hcl +++ b/al2023arm.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2023arm = "${var.ami_name_prefix_al2023}-hvm-2023.0.${var.ami_version_al2023}${var.kernel_version_al2023arm}-arm64" + default_tags = { + os_version = "Amazon Linux 2023" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version_al2023}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2023arm" + ami_version = "2023.0.${var.ami_version_al2023}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2023arm" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2023arm" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2023" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version_al2023}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2023arm" - ami_version = "2023.0.${var.ami_version_al2023}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2023neu.pkr.hcl b/al2023neu.pkr.hcl index ee68562..40fdaaf 100644 --- a/al2023neu.pkr.hcl +++ b/al2023neu.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2023neu = "${var.ami_name_prefix_al2023}-neuron-hvm-2023.0.${var.ami_version_al2023}${var.kernel_version_al2023}-x86_64" + default_tags = { + os_version = "Amazon Linux 2023" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version_al2023}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2023neu" + ami_version = "2023.0.${var.ami_version_al2023}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2023neu" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2023neu" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2023" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version_al2023}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2023neu" - ami_version = "2023.0.${var.ami_version_al2023}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2arm.pkr.hcl b/al2arm.pkr.hcl index 86fa0c0..273b942 100644 --- a/al2arm.pkr.hcl +++ b/al2arm.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2arm = "${var.ami_name_prefix_al2}-hvm-2.0.${var.ami_version_al2}-arm64-ebs" + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2arm" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2arm" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2arm" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2arm" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2gpu.pkr.hcl b/al2gpu.pkr.hcl index 49261fa..e34615a 100644 --- a/al2gpu.pkr.hcl +++ b/al2gpu.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2gpu = "${var.ami_name_prefix_al2}-gpu-hvm-2.0.${var.ami_version_al2}-x86_64-ebs" + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2gpu" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2gpu" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2gpu" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2gpu" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2inf.pkr.hcl b/al2inf.pkr.hcl index 041b377..88b041f 100644 --- a/al2inf.pkr.hcl +++ b/al2inf.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2inf = "${var.ami_name_prefix_al2}-inf-hvm-2.0.${var.ami_version_al2}-x86_64-ebs" + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2inf" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2inf" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2inf" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2inf" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2keplergpu.pkr.hcl b/al2keplergpu.pkr.hcl index 67fdbc0..73126c7 100644 --- a/al2keplergpu.pkr.hcl +++ b/al2keplergpu.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2keplergpu = "${var.ami_name_prefix_al2}-kepler-gpu-hvm-2.0.${var.ami_version_al2}-x86_64-ebs" + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2keplergpu" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2keplergpu" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2keplergpu" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2keplergpu" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2kernel5dot10.pkr.hcl b/al2kernel5dot10.pkr.hcl index ed13763..fd2174e 100644 --- a/al2kernel5dot10.pkr.hcl +++ b/al2kernel5dot10.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2kernel5dot10 = "${var.ami_name_prefix_al2}-kernel-5.10-hvm-2.0.${var.ami_version_al2}-x86_64-ebs" + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2kernel5dot10" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2kernel5dot10" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2kernel5dot10" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2kernel5dot10" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2kernel5dot10arm.pkr.hcl b/al2kernel5dot10arm.pkr.hcl index 6ce2427..ad9cbdf 100644 --- a/al2kernel5dot10arm.pkr.hcl +++ b/al2kernel5dot10arm.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2kernel5dot10arm = "${var.ami_name_prefix_al2}-kernel-5.10-hvm-2.0.${var.ami_version_al2}-arm64-ebs" + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2kernel5dot10arm" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2kernel5dot10arm" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2kernel5dot10arm" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2kernel5dot10arm" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2kernel5dot10gpu.pkr.hcl b/al2kernel5dot10gpu.pkr.hcl index 9c37f8d..0a43f44 100644 --- a/al2kernel5dot10gpu.pkr.hcl +++ b/al2kernel5dot10gpu.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2kernel5dot10gpu = "${var.ami_name_prefix_al2}-kernel-5.10-gpu-hvm-2.0.${var.ami_version_al2}-x86_64-ebs" + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2kernel5dot10gpu" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2kernel5dot10gpu" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2kernel5dot10gpu" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2kernel5dot10gpu" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/al2kernel5dot10inf.pkr.hcl b/al2kernel5dot10inf.pkr.hcl index 9f099c9..ae7cc48 100644 --- a/al2kernel5dot10inf.pkr.hcl +++ b/al2kernel5dot10inf.pkr.hcl @@ -1,5 +1,14 @@ locals { ami_name_al2kernel5dot10inf = "${var.ami_name_prefix_al2}-kernel-5.10-inf-hvm-2.0.${var.ami_version_al2}-x86_64-ebs" + default_tags = { + os_version = "Amazon Linux 2" + source_image_name = "{{ .SourceAMIName }}" + ecs_runtime_version = "Docker version ${var.docker_version}" + ecs_agent_version = "${var.ecs_agent_version}" + ami_type = "al2kernel5dot10inf" + ami_version = "2.0.${var.ami_version_al2}" + } + merged_tags = merge("${local.default_tags}", "${var.tags}") } source "amazon-ebs" "al2kernel5dot10inf" { @@ -26,12 +35,6 @@ source "amazon-ebs" "al2kernel5dot10inf" { ami_users = "${var.ami_users}" ssh_interface = "public_ip" ssh_username = "ec2-user" - tags = { - os_version = "Amazon Linux 2" - source_image_name = "{{ .SourceAMIName }}" - ecs_runtime_version = "Docker version ${var.docker_version}" - ecs_agent_version = "${var.ecs_agent_version}" - ami_type = "al2kernel5dot10inf" - ami_version = "2.0.${var.ami_version_al2}" - } + tags = "${local.merged_tags}" + run_tags = "${var.run_tags}" } diff --git a/variables.pkr.hcl b/variables.pkr.hcl index 3186ba7..018634a 100644 --- a/variables.pkr.hcl +++ b/variables.pkr.hcl @@ -256,3 +256,15 @@ variable "ami_users" { description = "A list of account IDs that have access to launch the resulting AMI(s)." default = [] } + +variable "tags" { + type = map(string) + description = "Tags to apply to the built AMI." + default = {} +} + +variable "run_tags" { + type = map(string) + description = "Tags to apply to resources (key-pair, SG, IAM, snapshot, interfaces and instance) used when building the AMI." + default = {} +} \ No newline at end of file