Packer parallel builds interfering with each other

I’m running a Packer build based on vsphere-iso where I specify multiple sources, with the only difference being their name and vm_name field. The respective provisioners used during the build are then provided ${source.name} as a parameter, which causes them to execute differently.

This part works fine.

However, about half of the time, at the end of the build when one of the VM’s is being shut down, it actually shuts down the wrong VM, and then downloads the wrong disk (even though Packer’s output shows the right disk) and continues running a postprocessor (running ovftool with some added logic, again with ${source.name} as a parameter to determine respective configuration). This results in .ova’s that have the wrong content.

The shutdown command:

  shutdown_command        = "echo '${var.ssh_password}' | sudo -S shutdown -P now"
  shutdown_timeout        = "5m"

An example of this happening:

2023-01-26T16:31:12Z:     vsphere-iso.upgrade:
2023-01-26T16:31:12Z:     vsphere-iso.upgrade: PLAY RECAP *********************************************************************
2023-01-26T16:31:12Z:     vsphere-iso.upgrade: default                    : ok=66   changed=57   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
2023-01-26T16:31:12Z:     vsphere-iso.upgrade:
2023-01-26T16:31:12Z: ==> vsphere-iso.upgrade: Executing shutdown command...
2023-01-26T16:31:34Z:     vsphere-iso.bootstrap: changed: [default]
2023-01-26T16:31:34Z:     vsphere-iso.bootstrap:
2023-01-26T16:31:34Z:     vsphere-iso.bootstrap: PLAY RECAP *********************************************************************
2023-01-26T16:31:34Z:     vsphere-iso.bootstrap: default                    : ok=66   changed=57   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
2023-01-26T16:31:34Z:     vsphere-iso.bootstrap:
2023-01-26T16:31:35Z: ==> vsphere-iso.bootstrap: VM is already powered off
2023-01-26T16:31:35Z: ==> vsphere-iso.bootstrap: Deleting Floppy drives...
2023-01-26T16:31:35Z: ==> vsphere-iso.bootstrap: Eject CD-ROM drives...
2023-01-26T16:31:35Z: ==> vsphere-iso.bootstrap: Deleting CD-ROM drives...
2023-01-26T16:31:35Z:     vsphere-iso.bootstrap: Starting export...
2023-01-26T16:31:35Z:     vsphere-iso.bootstrap: Downloading: ova.bootstrap-847-79b794dba2-disk-0.vmdk
2023-01-26T16:36:13Z: ==> vsphere-iso.upgrade: Provisioning step had errors: Running the cleanup provisioner, if present...
2023-01-26T16:36:13Z: ==> vsphere-iso.upgrade: Power off VM...
2023-01-26T16:36:13Z: ==> vsphere-iso.upgrade: Destroying VM...
2023-01-26T16:36:14Z: ==> vsphere-iso.upgrade: Deleting cd_files image from remote datastore ...
2023-01-26T16:36:14Z: Build 'vsphere-iso.upgrade' errored after 36 minutes 42 seconds: Timeout while waiting for machine to shut down.
2023-01-26T16:38:29Z:     vsphere-iso.bootstrap: Exporting file: ova.bootstrap-847-79b794dba2-disk-0.vmdk
[...]

How can I avoid this from happening?

I tried using ${build.PackerRunUUID} in the vm_name, but even with Packer 1.8.5 I get an error stating that that property does not exist.
I also tried using different export.output_directory values, but that also makes no difference.

I am running this on vCenter 7.0.3 (build 19234570).

I’ve created a Github issue (Packer parallel `vsphere-iso` builds interfering with each other · Issue #250 · hashicorp/packer-plugin-vsphere · GitHub), this forum thread, but I’m not getting anywhere at all.

Looking at the amount of replies to threads here and in the Github repo, I’m seriously doubting if Packer is still being maintained.