hashicorp / packer-plugin-vmware

Packer plugin for VMware Builder
https://www.packer.io/docs/builders/vmware
Mozilla Public License 2.0
44 stars 42 forks source link

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

Open julien-lang opened 2 years ago

julien-lang commented 2 years ago

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:

Related to #20

julien-lang commented 1 year ago

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.

tenthirtyam commented 1 week ago

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.