packer-plugin-vmware icon indicating copy to clipboard operation
packer-plugin-vmware copied to clipboard

`vmware-iso`: Using the `snapshot_name` option with ESXi, the VMX file does not refer the correct snapshot

Open julien-lang opened this issue 3 years ago • 1 comments

I use packer to generate virtual machines on ESXi.

I set a snapshot_name combined with "keep_registered": true and "skip_export": true.

Packer succeed to create the Virtual Machine and the snapshot is created indeed but the VMX file does refer the snapshot:

  • Actual result:

    scsi0:0.filename = "disk.vmdk"
    
  • Expected result:

    scsi0:0.filename = "disk-000001.vmdk"
    

Related to #20

julien-lang avatar Mar 04 '22 00:03 julien-lang

I think the error might come from the list of steps in the builder/vmware/iso/builder.go file.

The StepCreateSnapshot is defined before the StepUploadVMX step. So if I understand the code correclty, This will override the VMDK filename in the VMX.

So the fixup could simply be:

diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go
index 951aaab..4074d62 100644
--- a/builder/vmware/iso/builder.go
+++ b/builder/vmware/iso/builder.go
@@ -179,12 +179,12 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
                        RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
                        VNCEnabled:               !b.config.DisableVNC,
                },
-               &vmwcommon.StepCreateSnapshot{
-                       SnapshotName: &b.config.SnapshotName,
-               },
                &vmwcommon.StepUploadVMX{
                        RemoteType: b.config.RemoteType,
                },
+               &vmwcommon.StepCreateSnapshot{
+                       SnapshotName: &b.config.SnapshotName,
+               },
                &vmwcommon.StepExport{
                        Format:         b.config.Format,
                        SkipExport:     b.config.SkipExport,

But I have not tested it yet.

julien-lang avatar Jul 25 '22 23:07 julien-lang

This was, in fact, the issue. I've opened a PR to address this in both builders and address some minor tech debt for this option.

tenthirtyam avatar Jul 16 '24 02:07 tenthirtyam