fix: vsphere-clone
: rearrange build steps to ensure source VM exists before deleting target
#489
+12
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses an issue in the
vsphere-clone
builder where using the-force
flag can lead to unintentional deletion of the target VM, which may result in the loss of critical data if the target VM is the only copy of a virtual machine.Issue description
Currently, when the
-force
flag is specified, thevsphere-clone
builder first deletes the target VM before verifying that the source VM to be cloned exists. If the source VM is missing, this process leaves users without a VM to clone and potentially results in data loss.Use case
In our environment, Packer is used to perform regular updates on legacy virtual machine templates. These templates are unique, lack proper build configurations, and cannot be easily replicated. If, for any reason, human intervention results in running
packer build
with the-force
flag, there is a significant risk of losing irreplaceable data.Testing
Testing was performed to confirm:
-force
flag, the target VM is only deleted if a source VM exists.Related issues
vsphere-clone
: Unwanted behavior using-force
flag when source virtual machine doesn't exist #490