From 76d980683c5349ac2376d4f8523df241c5c05e0b Mon Sep 17 00:00:00 2001 From: Karlie Meads <68717336+karliemeads@users.noreply.github.com> Date: Wed, 29 May 2024 21:03:03 -0400 Subject: [PATCH] fix(vm): host parameter is optional if using mapping for usb (#1338) Signed-off-by: Karlie Meads <68717336+karliemeads@users.noreply.github.com> --- proxmox/nodes/vms/vms_types.go | 5 +++-- proxmoxtf/resource/vm/vm.go | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/proxmox/nodes/vms/vms_types.go b/proxmox/nodes/vms/vms_types.go index 527d43a7..b908c9c1 100644 --- a/proxmox/nodes/vms/vms_types.go +++ b/proxmox/nodes/vms/vms_types.go @@ -1207,8 +1207,9 @@ func (r CustomUSBDevice) EncodeValues(key string, v *url.Values) error { return fmt.Errorf("either device ID or resource mapping must be set") } - values := []string{ - fmt.Sprintf("host=%s", *(r.HostDevice)), + values := []string{} + if r.HostDevice != nil { + values = append(values, fmt.Sprintf("host=%s", *(r.HostDevice))) } if r.Mapping != nil { diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index c41e15c7..473a0468 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -979,7 +979,7 @@ func VM() *schema.Resource { mkHostUSBDevice: { Type: schema.TypeString, Description: "The USB device ID for Proxmox, in form of ':'", - Required: true, + Optional: true, }, mkHostUSBDeviceMapping: { Type: schema.TypeString, @@ -3197,9 +3197,13 @@ func vmGetHostUSBDeviceObjects(d *schema.ResourceData) vms.CustomUSBDevices { mapping, _ := block[mkHostUSBDeviceMapping].(string) device := vms.CustomUSBDevice{ - HostDevice: &host, - USB3: &usb3, + USB3: &usb3, } + + if host != "" { + device.HostDevice = &host + } + if mapping != "" { device.Mapping = &mapping }