From 52cd604a9be40f51aab5b3c113a878a6ad446aad Mon Sep 17 00:00:00 2001 From: Dom Del Nano Date: Mon, 27 Feb 2023 21:37:07 -0800 Subject: [PATCH] Refactor template name to use a map lookup on Ubuntu version --- examples/ubuntu/ubuntu-2004.pkr.hcl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/ubuntu/ubuntu-2004.pkr.hcl b/examples/ubuntu/ubuntu-2004.pkr.hcl index 3106e6a..8b0fb0d 100644 --- a/examples/ubuntu/ubuntu-2004.pkr.hcl +++ b/examples/ubuntu/ubuntu-2004.pkr.hcl @@ -16,6 +16,12 @@ data "null" "ubuntu_version" { locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") ubuntu_version = data.null.ubuntu_version.output + + # Update this map to support future releases. At this time, the Ubuntu + # jammy template is not available yet. + ubuntu_template_name = { + 20.04 = "Ubuntu Focal Fossa 20.04" + } } # TODO(ddelnano): Update this to use a local once https://github.com/hashicorp/packer/issues/11011 @@ -81,8 +87,8 @@ source "xenserver-iso" "ubuntu-2004" { remote_username = var.remote_username # Change this to match the ISO of ubuntu you are using in the iso_url variable - clone_template = "Ubuntu Focal Fossa 20.04" - vm_name = "packer-ubuntu-2004-${local.timestamp}" + clone_template = local.ubuntu_template_name[data.null.ubuntu_version.output] + vm_name = "packer-ubuntu-${data.null.ubuntu_version.output}-${local.timestamp}" vm_description = "Build started: ${local.timestamp}" vm_memory = 4096 disk_size = 20000