From 1caa2882546a3476b6f68d141d9fdf78ca49114e Mon Sep 17 00:00:00 2001 From: Steve Brasier Date: Wed, 6 Nov 2024 08:19:01 +0000 Subject: [PATCH] make built image name/version smarter --- packer/openstack.pkr.hcl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packer/openstack.pkr.hcl b/packer/openstack.pkr.hcl index 6c1f7d12..816dd120 100644 --- a/packer/openstack.pkr.hcl +++ b/packer/openstack.pkr.hcl @@ -23,7 +23,8 @@ data "git-commit" "cwd-head" { } locals { git_commit = data.git-commit.cwd-head.hash timestamp = formatdate("YYMMDD-hhmm", timestamp()) - image_version = var.image_version == "" ? "${local.timestamp}-${substr(local.git_commit, 0, 8)}" : var.image_version + image_version = var.image_version == "auto" ? "${local.timestamp}-${substr(local.git_commit, 0, 8)}" : var.image_version + image_name = replace(var.image_name, '/', '-') } # Path pointing to root of repository - automatically set by environment variable PKR_VAR_repo_root @@ -157,14 +158,14 @@ variable "inventory_groups" { variable "image_name" { type = string - description = "Built image name" + description = "Built image name. Any '/' are replaced with '-'." default = "openhpc" } variable "image_version" { type = string - description = "Suffix for built image names. If not supplied a timestamp+git commit is used" - default = "" + description = "Suffix for built image names. Default special value 'auto' uses a timestamp+git commit" + default = "auto" } source "openstack" "openhpc" { @@ -202,7 +203,7 @@ build { source "source.openstack.openhpc" { name = "rocky-latest" - image_name = "${var.image_name}-${local.image_version}" + image_name = join("-", [local.image_name, local.image_version]) } provisioner "ansible" {