Skip to content

Commit 1caa288

Browse files
committed
make built image name/version smarter
1 parent c7e9eba commit 1caa288

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packer/openstack.pkr.hcl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ data "git-commit" "cwd-head" { }
2323
locals {
2424
git_commit = data.git-commit.cwd-head.hash
2525
timestamp = formatdate("YYMMDD-hhmm", timestamp())
26-
image_version = var.image_version == "" ? "${local.timestamp}-${substr(local.git_commit, 0, 8)}" : var.image_version
26+
image_version = var.image_version == "auto" ? "${local.timestamp}-${substr(local.git_commit, 0, 8)}" : var.image_version
27+
image_name = replace(var.image_name, '/', '-')
2728
}
2829

2930
# Path pointing to root of repository - automatically set by environment variable PKR_VAR_repo_root
@@ -157,14 +158,14 @@ variable "inventory_groups" {
157158

158159
variable "image_name" {
159160
type = string
160-
description = "Built image name"
161+
description = "Built image name. Any '/' are replaced with '-'."
161162
default = "openhpc"
162163
}
163164

164165
variable "image_version" {
165166
type = string
166-
description = "Suffix for built image names. If not supplied a timestamp+git commit is used"
167-
default = ""
167+
description = "Suffix for built image names. Default special value 'auto' uses a timestamp+git commit"
168+
default = "auto"
168169
}
169170

170171
source "openstack" "openhpc" {
@@ -202,7 +203,7 @@ build {
202203

203204
source "source.openstack.openhpc" {
204205
name = "rocky-latest"
205-
image_name = "${var.image_name}-${local.image_version}"
206+
image_name = join("-", [local.image_name, local.image_version])
206207
}
207208

208209
provisioner "ansible" {

0 commit comments

Comments
 (0)