From cc035619ac1673a5b5ea2f6bfb843eac75ea4a9d Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Sat, 16 Jan 2021 15:11:31 +1000 Subject: [PATCH] Set packer builder type with env variable Using the -only CLI option for packer build does not work as expected. The #CR 90dd675df482a8 (global-jjb) submitted with common-packer v0.7.0 fails to build packer jobs because of a bug in the packer build CLI. The `-only` option packer build CLI does not set the cloud provider name/type as per the documentation. The alternative is to use an environment variable that is passed through the packer job and can be reference in the packer templates. Issue: https://github.com/hashicorp/packer/issues/10495 Change-Id: I1c1e2e7c5545df5a2a374a02714634a0f4086378 Signed-off-by: Anil Belur --- ...acker-builder-type-with-env-var-490b7672b07486bc.yaml | 16 ++++++++++++++++ templates/builder.json | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/set-packer-builder-type-with-env-var-490b7672b07486bc.yaml diff --git a/releasenotes/notes/set-packer-builder-type-with-env-var-490b7672b07486bc.yaml b/releasenotes/notes/set-packer-builder-type-with-env-var-490b7672b07486bc.yaml new file mode 100644 index 0000000..e9bb11b --- /dev/null +++ b/releasenotes/notes/set-packer-builder-type-with-env-var-490b7672b07486bc.yaml @@ -0,0 +1,16 @@ +--- +fixes: + - | + Set packer builder type with environment variable + + Using the -only CLI option for packer build does not work as expected. + The #CR 90dd675df482a8 (global-jjb) submitted with common-packer v0.7.0 + fails to build packer jobs because of a bug in the packer build CLI. + + The `-only` option packer build CLI does not set the cloud provider + name/type as per the documentation. The alternative is to use an environment + variable that is passed through the packer job and can be reference in the + packer templates. + + Ref: + https://github.com/hashicorp/packer/issues/10495 diff --git a/templates/builder.json b/templates/builder.json index f4ca2f9..792f95c 100644 --- a/templates/builder.json +++ b/templates/builder.json @@ -12,15 +12,16 @@ "distro": null, "flavor": "v2-highcpu-1", "ssh_user": null, - "ssh_proxy_host": "" + "ssh_proxy_host": "", + "cloud_type": "{{env `PACKER_BUILDER`}}" }, "builders": [ { - "name": "openstack", + "name": "{{user `cloud_type`}}", "image_name": "ZZCI - {{user `distro`}} - builder - {{user `arch`}} - {{isotime \"20060102-150405.000\"}}", "instance_name": "{{user `distro`}}-builder-{{uuid}}", "source_image_name": "{{user `base_image`}}", - "type": "openstack", + "type": "{{user `cloud_type`}}", "region": "{{user `cloud_region`}}", "networks": ["{{user `cloud_network`}}"], "user_data_file": "{{user `cloud_user_data`}}", -- 2.16.6