Skip to content

vsphere-clone: Unwanted behavior using -force flag when source virtual machine doesn't exist #490

@YuriyAM

Description

@YuriyAM

Overview of the Issue

Currently, when running packer build -force with the vsphere-clone builder, if the specified source virtual machine is missing, Packer proceeds to delete the target virtual machine before verifying that the source is available. This behavior risks data loss, especially in cases where the target VM is unique and has no backup or proper build configuration.

One of the use cases is when Packer is used to regularly update legacy virtual machine templates that are unique and cannot be recreated. Running packer build -force without verifying the source VM can lead to data loss, especially when human error or misconfiguration occurs.

Reproduction Steps

  1. Have a template set to non-existing virtual machine
  2. Run packer build -force
  3. Observe that the target VM is deleted before confirming that a source VM is available.

Expected Behavior

  1. vsphere-clone builder should first check if the source VM exists before force-deleting the target VM.
  2. If the source VM is missing, the build process should exit without affecting the target VM.

Packer Version

Packer v1.11.2

Plugin Version and Builders

Plugin version 1.4.2

  • vsphere-iso
  • vsphere-clone

VMware vSphere Version

Please provide the VMware vSphere version.

  • 7.0.3

Guest Operating System

Any

Simplified Packer Buildfile

Basicvsphere-clone configuration; template option is set to a non-existing virtual machine.

Operating System and Environment Details

Any

Log Fragments and crash.log Files

2024-11-11T07:39:34Z: ==> vsphere-clone.vm: the vm/template packer-live-folder/packer-test-vm already exists, but deleting it due to -force flag
2024-11-11T07:39:34Z: ==> vsphere-clone.vm: packer-live-folder/packer-test-vm is a template, attempting to convert it to a vm
2024-11-11T07:39:36Z: ==> vsphere-clone.vm: Cloning virtual machine...
2024-11-11T07:39:36Z:     vsphere-clone.vm: Closing sessions ....
2024-11-11T07:39:36Z: Build 'vsphere-clone.vm' errored after 1 second 989 milliseconds: error finding virtual machine to clone: vm 'packer-build-folder/packer-test-vm' not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions