From ab4148af63fee076fa1e472cee8cb849bd82c30e Mon Sep 17 00:00:00 2001 From: Dennis Hoppe Date: Tue, 29 Nov 2022 10:15:50 +0100 Subject: [PATCH 1/3] refactor: Use Git branch / tag instead of current year / month --- README.md | 49 ++++++++++++++++--- .../linux/almalinux/8/linux-almalinux.pkr.hcl | 15 ++++-- .../linux/almalinux/9/linux-almalinux.pkr.hcl | 15 ++++-- builds/linux/centos/7/linux-centos.pkr.hcl | 15 ++++-- .../8-stream/linux-centos-stream.pkr.hcl | 15 ++++-- .../9-stream/linux-centos-stream.pkr.hcl | 15 ++++-- builds/linux/debian/11/linux-debian.pkr.hcl | 15 ++++-- builds/linux/photon/4/linux-photon.pkr.hcl | 15 ++++-- builds/linux/rhel/7/linux-rhel.pkr.hcl | 15 ++++-- builds/linux/rhel/8/linux-rhel.pkr.hcl | 15 ++++-- builds/linux/rhel/9/linux-rhel.pkr.hcl | 15 ++++-- builds/linux/rocky/8/linux-rocky.pkr.hcl | 15 ++++-- builds/linux/rocky/9/linux-rocky.pkr.hcl | 15 ++++-- builds/linux/sles/15/linux-sles.pkr.hcl | 15 ++++-- .../ubuntu/18-04-lts/linux-ubuntu.pkr.hcl | 15 ++++-- .../ubuntu/20-04-lts/linux-ubuntu.pkr.hcl | 15 ++++-- .../ubuntu/22-04-lts/linux-ubuntu.pkr.hcl | 15 ++++-- builds/windows/desktop/10/windows.pkr.hcl | 17 +++++-- builds/windows/desktop/11/windows.pkr.hcl | 17 +++++-- .../server/2019/windows-server.pkr.hcl | 23 ++++++--- .../server/2022/windows-server.pkr.hcl | 23 ++++++--- 21 files changed, 287 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index 297bc709c..b9fe6550d 100644 --- a/README.md +++ b/README.md @@ -175,10 +175,12 @@ The following additional software packages must be installed on the operating sy - [Ansible][ansible-docs] 2.9 or higher. + - [jq][jq] A command-line JSON processor. + - xorriso - A command-line .iso creator. ```shell - tdnf -y install git ansible xorriso + tdnf -y install git ansible jq xorriso ``` - HashiCorp [Terraform][terraform-install] 1.3.5 or higher. @@ -209,6 +211,8 @@ The following additional software packages must be installed on the operating sy - [Ansible][ansible-docs] 2.9 or higher. + - [jq][jq] A command-line JSON processor. + - xorriso - A command-line .iso creator. - mkpasswd - Password generating utility @@ -216,7 +220,7 @@ The following additional software packages must be installed on the operating sy - HashiCorp [Terraform][terraform-install] 1.3.5 or higher. ```shell - sudo apt -y install git ansible xorriso whois terraform + sudo apt -y install git ansible jq xorriso whois terraform ``` - [Gomplate][gomplate-install] 3.11.3 or higher. @@ -238,6 +242,8 @@ The following additional software packages must be installed on the operating sy - [Ansible][ansible-docs] 2.9 or higher. + - [jq][jq] A command-line JSON processor. + - Coreutils - HashiCorp [Terraform][terraform-install] 1.3.5 or higher. @@ -245,7 +251,7 @@ The following additional software packages must be installed on the operating sy - [Gomplate][gomplate-install] 3.11.3 or higher. ```shell - brew install git ansible coreutils hashicorp/tap/terraform gomplate + brew install git ansible jq coreutils hashicorp/tap/terraform gomplate ``` - mkpasswd - Password generating utility @@ -263,16 +269,42 @@ The following additional software packages must be installed on the operating sy ## Configuration -### Step 1 - Download the Release +### Step 1 - Download the Source + +You can choose between two options to get the source code. Either via the checkout of a Git repository or the download of a release archive. -Download the [**latest**](https://github.com/vmware-samples/packer-examples-for-vsphere/releases/latest) release. -You may also clone `main` for the latest prerelease updates. +> **Warning** +> +> A branch is mandatory because it is used for the build version and the virtual machine name. It does not matter if it is based on the HEAD or a release tag. -**Example**: +#### Clone the Repository + +```shell +TAG_NAME=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tag_name') -```console git clone https://github.com/vmware-samples/packer-examples-for-vsphere.git +cd packer-examples-for-vsphere +git switch -c $TAG_NAME $TAG_NAME +``` + +> **Note** +> +> You may also clone `main` for the latest prerelease updates. + +#### Download the latest release + +```shell +TAG_NAME=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tag_name') +TARBALL_URL=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tarball_url') + +mkdir packer-examples-for-vsphere +cd packer-examples-for-vsphere +curl -sL $TARBALL_URL | tar xvfz - --strip-components 1 +git init -b main +git add . +git commit -m "Initial commit" +git switch -c $TAG_NAME HEAD ``` The directory structure of the repository. @@ -1011,6 +1043,7 @@ Happy building!!! [hcp-packer-intro]: https://www.youtube.com/watch?v=r0I4TTO957w [hcp-security]: https://www.hashicorp.com/security [iso]: https://en.wikipedia.org/wiki/ISO_image +[jq]: https://stedolan.github.io/jq/ [microsoft-kms]: https://docs.microsoft.com/en-us/windows-server/get-started/kmsclientkeys [microsoft-windows-afg]: https://www.windowsafg.com [microsoft-windows-unattend]: https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/ diff --git a/builds/linux/almalinux/8/linux-almalinux.pkr.hcl b/builds/linux/almalinux/8/linux-almalinux.pkr.hcl index c0e97e594..13cc440a1 100644 --- a/builds/linux/almalinux/8/linux-almalinux.pkr.hcl +++ b/builds/linux/almalinux/8/linux-almalinux.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/almalinux/9/linux-almalinux.pkr.hcl b/builds/linux/almalinux/9/linux-almalinux.pkr.hcl index 32f529389..7960400e2 100644 --- a/builds/linux/almalinux/9/linux-almalinux.pkr.hcl +++ b/builds/linux/almalinux/9/linux-almalinux.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/centos/7/linux-centos.pkr.hcl b/builds/linux/centos/7/linux-centos.pkr.hcl index 77343ca02..38441f60d 100644 --- a/builds/linux/centos/7/linux-centos.pkr.hcl +++ b/builds/linux/centos/7/linux-centos.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/centos/8-stream/linux-centos-stream.pkr.hcl b/builds/linux/centos/8-stream/linux-centos-stream.pkr.hcl index 53b195289..b67342e9c 100644 --- a/builds/linux/centos/8-stream/linux-centos-stream.pkr.hcl +++ b/builds/linux/centos/8-stream/linux-centos-stream.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/centos/9-stream/linux-centos-stream.pkr.hcl b/builds/linux/centos/9-stream/linux-centos-stream.pkr.hcl index 29a1669f8..5a3f26cd2 100644 --- a/builds/linux/centos/9-stream/linux-centos-stream.pkr.hcl +++ b/builds/linux/centos/9-stream/linux-centos-stream.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/debian/11/linux-debian.pkr.hcl b/builds/linux/debian/11/linux-debian.pkr.hcl index f2722e6f2..1396c6b20 100644 --- a/builds/linux/debian/11/linux-debian.pkr.hcl +++ b/builds/linux/debian/11/linux-debian.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "file=/media/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/photon/4/linux-photon.pkr.hcl b/builds/linux/photon/4/linux-photon.pkr.hcl index 376e05840..1a6ebda04 100644 --- a/builds/linux/photon/4/linux-photon.pkr.hcl +++ b/builds/linux/photon/4/linux-photon.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -38,7 +47,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.json" : "ks=/dev/sr1:/ks.json" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/rhel/7/linux-rhel.pkr.hcl b/builds/linux/rhel/7/linux-rhel.pkr.hcl index 1ce2fab5e..f04e66db5 100644 --- a/builds/linux/rhel/7/linux-rhel.pkr.hcl +++ b/builds/linux/rhel/7/linux-rhel.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -43,7 +52,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/rhel/8/linux-rhel.pkr.hcl b/builds/linux/rhel/8/linux-rhel.pkr.hcl index 83051caa5..4469a5819 100644 --- a/builds/linux/rhel/8/linux-rhel.pkr.hcl +++ b/builds/linux/rhel/8/linux-rhel.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -43,7 +52,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/rhel/9/linux-rhel.pkr.hcl b/builds/linux/rhel/9/linux-rhel.pkr.hcl index 29bba60e8..0fcb5ed92 100644 --- a/builds/linux/rhel/9/linux-rhel.pkr.hcl +++ b/builds/linux/rhel/9/linux-rhel.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -43,7 +52,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/rocky/8/linux-rocky.pkr.hcl b/builds/linux/rocky/8/linux-rocky.pkr.hcl index 821b0ffa8..2045a3fb5 100644 --- a/builds/linux/rocky/8/linux-rocky.pkr.hcl +++ b/builds/linux/rocky/8/linux-rocky.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/rocky/9/linux-rocky.pkr.hcl b/builds/linux/rocky/9/linux-rocky.pkr.hcl index d96f76a53..8ff8b1c27 100644 --- a/builds/linux/rocky/9/linux-rocky.pkr.hcl +++ b/builds/linux/rocky/9/linux-rocky.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "inst.ks=cdrom:/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/sles/15/linux-sles.pkr.hcl b/builds/linux/sles/15/linux-sles.pkr.hcl index 7a796113e..db37a7dbc 100644 --- a/builds/linux/sles/15/linux-sles.pkr.hcl +++ b/builds/linux/sles/15/linux-sles.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -43,7 +52,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? " autoyast=http://{{ .HTTPIP }}:{{ .HTTPPort }}/autoinst.xml" : " netsetup=dhcp autoyast=device://sr1/autoinst.xml" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/ubuntu/18-04-lts/linux-ubuntu.pkr.hcl b/builds/linux/ubuntu/18-04-lts/linux-ubuntu.pkr.hcl index 19b036cf1..fa8f13e25 100644 --- a/builds/linux/ubuntu/18-04-lts/linux-ubuntu.pkr.hcl +++ b/builds/linux/ubuntu/18-04-lts/linux-ubuntu.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -41,7 +50,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" : "file=/media/ks.cfg" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/ubuntu/20-04-lts/linux-ubuntu.pkr.hcl b/builds/linux/ubuntu/20-04-lts/linux-ubuntu.pkr.hcl index 06cbbd661..80c1934e4 100644 --- a/builds/linux/ubuntu/20-04-lts/linux-ubuntu.pkr.hcl +++ b/builds/linux/ubuntu/20-04-lts/linux-ubuntu.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -42,7 +51,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "ds=\"nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/\"" : "ds=\"nocloud\"" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl b/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl index 30a94fe08..b32804fd8 100644 --- a/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl +++ b/builds/linux/ubuntu/22-04-lts/linux-ubuntu.pkr.hcl @@ -9,6 +9,10 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" @@ -16,14 +20,19 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) @@ -42,7 +51,7 @@ locals { }) } data_source_command = var.common_data_source == "http" ? "ds=\"nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/\"" : "ds=\"nocloud\"" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/windows/desktop/10/windows.pkr.hcl b/builds/windows/desktop/10/windows.pkr.hcl index bd12a6c36..c93399f42 100644 --- a/builds/windows/desktop/10/windows.pkr.hcl +++ b/builds/windows/desktop/10/windows.pkr.hcl @@ -9,12 +9,14 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" } - } - required_plugins { windows-update = { version = ">= 0.14.1" source = "github.com/rgl/windows-update" @@ -22,21 +24,26 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}", "[] /vmimages/tools-isoimages/${var.vm_guest_os_family}.iso"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) manifest_path = "${path.cwd}/manifests/" manifest_output = "${local.manifest_path}${local.manifest_date}.json" ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version} ${var.vm_guest_os_edition}" } diff --git a/builds/windows/desktop/11/windows.pkr.hcl b/builds/windows/desktop/11/windows.pkr.hcl index 99c4daec5..694e9cc89 100644 --- a/builds/windows/desktop/11/windows.pkr.hcl +++ b/builds/windows/desktop/11/windows.pkr.hcl @@ -9,12 +9,14 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" } - } - required_plugins { windows-update = { version = ">= 0.14.1" source = "github.com/rgl/windows-update" @@ -22,21 +24,26 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}", "[] /vmimages/tools-isoimages/${var.vm_guest_os_family}.iso"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) manifest_path = "${path.cwd}/manifests/" manifest_output = "${local.manifest_path}${local.manifest_date}.json" ovf_export_path = "${path.cwd}/artifacts/${local.vm_name}" - vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition}-v${local.build_version}" + vm_name = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version} ${var.vm_guest_os_edition}" } diff --git a/builds/windows/server/2019/windows-server.pkr.hcl b/builds/windows/server/2019/windows-server.pkr.hcl index 45dd483b3..ce901c88d 100644 --- a/builds/windows/server/2019/windows-server.pkr.hcl +++ b/builds/windows/server/2019/windows-server.pkr.hcl @@ -9,12 +9,14 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" } - } - required_plugins { windows-update = { version = ">= 0.14.1" source = "github.com/rgl/windows-update" @@ -22,24 +24,29 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}", "[] /vmimages/tools-isoimages/${var.vm_guest_os_family}.iso"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) manifest_path = "${path.cwd}/manifests/" manifest_output = "${local.manifest_path}${local.manifest_date}.json" ovf_export_path = "${path.cwd}/artifacts/" - vm_name_datacenter_core = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_datacenter}-${var.vm_guest_os_experience_core}-v${local.build_version}" - vm_name_datacenter_desktop = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_datacenter}-${var.vm_guest_os_experience_desktop}-v${local.build_version}" - vm_name_standard_core = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_standard}-${var.vm_guest_os_experience_core}-v${local.build_version}" - vm_name_standard_desktop = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_standard}-${var.vm_guest_os_experience_desktop}-v${local.build_version}" + vm_name_datacenter_core = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_datacenter}-${var.vm_guest_os_experience_core}-${local.build_version}" + vm_name_datacenter_desktop = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_datacenter}-${var.vm_guest_os_experience_desktop}-${local.build_version}" + vm_name_standard_core = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_standard}-${var.vm_guest_os_experience_core}-${local.build_version}" + vm_name_standard_desktop = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_standard}-${var.vm_guest_os_experience_desktop}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } diff --git a/builds/windows/server/2022/windows-server.pkr.hcl b/builds/windows/server/2022/windows-server.pkr.hcl index a97ed2eaf..180d0da6a 100644 --- a/builds/windows/server/2022/windows-server.pkr.hcl +++ b/builds/windows/server/2022/windows-server.pkr.hcl @@ -9,12 +9,14 @@ packer { required_version = ">= 1.8.4" required_plugins { + git = { + version = ">= 0.3.2" + source = "github.com/ethanmdavidson/git" + } vsphere = { version = ">= v1.1.0" source = "github.com/hashicorp/vsphere" } - } - required_plugins { windows-update = { version = ">= 0.14.1" source = "github.com/rgl/windows-update" @@ -22,24 +24,29 @@ packer { } } +// BLOCK: data +// Defines the data sources. + +data "git-repository" "cwd" {} + // BLOCK: locals // Defines the local variables. locals { build_by = "Built by: HashiCorp Packer ${packer.version}" build_date = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp()) - build_version = formatdate("YY.MM", timestamp()) - build_description = "Version: v${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" + build_version = data.git-repository.cwd.head + build_description = "Version: ${local.build_version}\nBuilt on: ${local.build_date}\n${local.build_by}" iso_paths = ["[${var.common_iso_datastore}] ${var.iso_path}/${var.iso_file}", "[] /vmimages/tools-isoimages/${var.vm_guest_os_family}.iso"] iso_checksum = "${var.iso_checksum_type}:${var.iso_checksum_value}" manifest_date = formatdate("YYYY-MM-DD hh:mm:ss", timestamp()) manifest_path = "${path.cwd}/manifests/" manifest_output = "${local.manifest_path}${local.manifest_date}.json" ovf_export_path = "${path.cwd}/artifacts/" - vm_name_datacenter_core = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_datacenter}-${var.vm_guest_os_experience_core}-v${local.build_version}" - vm_name_datacenter_desktop = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_datacenter}-${var.vm_guest_os_experience_desktop}-v${local.build_version}" - vm_name_standard_core = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_standard}-${var.vm_guest_os_experience_core}-v${local.build_version}" - vm_name_standard_desktop = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_standard}-${var.vm_guest_os_experience_desktop}-v${local.build_version}" + vm_name_datacenter_core = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_datacenter}-${var.vm_guest_os_experience_core}-${local.build_version}" + vm_name_datacenter_desktop = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_datacenter}-${var.vm_guest_os_experience_desktop}-${local.build_version}" + vm_name_standard_core = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_standard}-${var.vm_guest_os_experience_core}-${local.build_version}" + vm_name_standard_desktop = "${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}-${var.vm_guest_os_edition_standard}-${var.vm_guest_os_experience_desktop}-${local.build_version}" bucket_name = replace("${var.vm_guest_os_family}-${var.vm_guest_os_name}-${var.vm_guest_os_version}", ".", "") bucket_description = "${var.vm_guest_os_family} ${var.vm_guest_os_name} ${var.vm_guest_os_version}" } From 0aa16c158717586af392dee7de59a391cea37897 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Tue, 29 Nov 2022 20:03:55 -0500 Subject: [PATCH 2/3] docs: update `README.md` Updates `README.md`: - Adds link to `packer-plugin-git` as well as version used. - Updates the order for the Configuration section. Signed-off-by: Ryan Johnson --- README.md | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b9fe6550d..7989f9737 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,7 @@ Operating systems and versions tested with the project: > Required plugins are automatically downloaded and initialized when using `./build.sh`. For dark sites, you may download the plugins and place these same directory as your Packer executable `/usr/local/bin` or `$HOME/.packer.d/plugins`. - HashiCorp [Packer Plugin for VMware vSphere][packer-plugin-vsphere] (`vsphere-iso`) 1.1.0 or higher. + - [Packer Plugin for Git][packer-plugin-git] 0.3.2 or higher - a community plugin for HashiCorp Packer. - [Packer Plugin for Windows Updates][packer-plugin-windows-update] 0.14.1 or higher - a community plugin for HashiCorp Packer. **Additional Software Packages**: @@ -271,42 +272,49 @@ The following additional software packages must be installed on the operating sy ### Step 1 - Download the Source -You can choose between two options to get the source code. Either via the checkout of a Git repository or the download of a release archive. +You can choose between two options to get the source code: +1. [Download the Release Archive](#download-the-latest-release) +1. [Clone the Repository](#clone-the-repository) -> **Warning** -> -> A branch is mandatory because it is used for the build version and the virtual machine name. It does not matter if it is based on the HEAD or a release tag. + > **Warning** + > + > A branch is mandatory because it is used for the build version and the virtual machine name. It does not matter if it is based on the HEAD or a release tag. -#### Clone the Repository -```shell +#### Download the Latest Release + +```console TAG_NAME=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tag_name') +TARBALL_URL=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tarball_url') -git clone https://github.com/vmware-samples/packer-examples-for-vsphere.git +mkdir packer-examples-for-vsphere cd packer-examples-for-vsphere -git switch -c $TAG_NAME $TAG_NAME +curl -sL $TARBALL_URL | tar xvfz - --strip-components 1 +git init -b main +git add . +git commit -m "Initial commit" +git switch -c $TAG_NAME HEAD ``` +#### Clone the Repository + > **Note** > > You may also clone `main` for the latest prerelease updates. -#### Download the latest release - -```shell +```console TAG_NAME=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tag_name') -TARBALL_URL=$(curl -s https://api.github.com/repos/vmware-samples/packer-examples-for-vsphere/releases | jq -r '.[0].tarball_url') -mkdir packer-examples-for-vsphere +git clone https://github.com/vmware-samples/packer-examples-for-vsphere.git cd packer-examples-for-vsphere -curl -sL $TARBALL_URL | tar xvfz - --strip-components 1 -git init -b main -git add . -git commit -m "Initial commit" -git switch -c $TAG_NAME HEAD +git switch -c $TAG_NAME $TAG_NAME ``` +> **Warning** +> +> A branch is mandatory because it is used for the build version and the virtual machine name. It does not matter if it is based on the HEAD or a release tag. + The directory structure of the repository. ```console @@ -1050,6 +1058,7 @@ Happy building!!! [packer]: https://www.packer.io [packer-debug]: https://developer.hashicorp.com/packer/docs/debugging [packer-install]: https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli +[packer-plugin-git]: https://github.com/ethanmdavidson/packer-plugin-git [packer-plugin-vsphere]: https://developer.hashicorp.com/packer/plugins/builders/vsphere/vsphere-iso [packer-plugin-windows-update]: https://github.com/rgl/packer-plugin-windows-update [packer-variables]: https://developer.hashicorp.com/packer/docs/templates/hcl_templates/variables From 44c58b7c01e33c9b35990952bc9e37183f81898b Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Wed, 30 Nov 2022 07:04:05 -0500 Subject: [PATCH 3/3] docs: update `README.md` Updates `README.md` to remove duplicate warning in the configuration section. Signed-off-by: Ryan Johnson --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 7989f9737..1c2698b97 100644 --- a/README.md +++ b/README.md @@ -277,11 +277,6 @@ You can choose between two options to get the source code: 1. [Download the Release Archive](#download-the-latest-release) 1. [Clone the Repository](#clone-the-repository) - > **Warning** - > - > A branch is mandatory because it is used for the build version and the virtual machine name. It does not matter if it is based on the HEAD or a release tag. - - #### Download the Latest Release ```console