diff --git a/CHANGELOG.md b/CHANGELOG.md index fa41c78a2..11bb4aa32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,9 +59,10 @@ * builder/vagrant: Use absolute path for package_include files to prevent them from having to be relative to the output vagrant directory. [GH-9260] * builder/virtualbox: Fix bug using checksum files. [GH-9101] -* builder/vSphere: Add option not to set host during datastore upload. [GH-9100 +* builder/vsphere: Add option not to set host during datastore upload. [GH-9100 * builder/vsphere: Fix iso config prepare being called incorrectly, which caused `iso_url` field to fail. [GH-9197] +* builder/vsphere: Fix crash in the driver for an interface conversion of types.AnyType nil to types.ManagedObjectReference. [GH-9354] * core: Ensure HTTP server information `PackerHTTPIP`, `PackerHTTPPort`, and `PackerHTTPAddr` are available via the `build` template engine for all supported builders [GH-9238] diff --git a/builder/vsphere/driver/vm.go b/builder/vsphere/driver/vm.go index 3b35738e8..0296f57b5 100644 --- a/builder/vsphere/driver/vm.go +++ b/builder/vsphere/driver/vm.go @@ -205,7 +205,10 @@ func (d *Driver) CreateVM(config *CreateConfig) (*VirtualMachine, error) { return nil, err } - vmRef := taskInfo.Result.(types.ManagedObjectReference) + vmRef, ok := taskInfo.Result.(types.ManagedObjectReference) + if !ok { + return nil, fmt.Errorf("something went wrong when creating the VM") + } return d.NewVM(&vmRef), nil } @@ -326,7 +329,11 @@ func (vm *VirtualMachine) Clone(ctx context.Context, config *CloneConfig) (*Virt return nil, err } - vmRef := info.Result.(types.ManagedObjectReference) + vmRef, ok := info.Result.(types.ManagedObjectReference) + if !ok { + return nil, fmt.Errorf("something went wrong when cloning the VM") + } + created := vm.driver.NewVM(&vmRef) return created, nil }