Skip to content

Commit 95782f5

Browse files
feat:r/vsphere_virtual_machine add usb controller
Add the ability to add usb controller on build and modification of virtual machine. Signed-off-by: Jared Burns <[email protected]>
1 parent adf6714 commit 95782f5

File tree

5 files changed

+431
-0
lines changed

5 files changed

+431
-0
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# <!-- markdownlint-disable first-line-h1 no-inline-html -->
22

3+
## 2.10.0 (Not Released)
4+
5+
FEATURES:
6+
7+
- `resource/vsphere_virtual_machine`: Adds ability to add `usb_controller` to virtual machine on creation or clone.
8+
[#2280](https://github.com/hashicorp/terraform-provider-vsphere/pull/2280)
9+
- `data/vsphere_virtual_machine`: Adds ability read `usb_controller` on virtual machine; will return `true` or `false` based on the configuration.
10+
[#2280](https://github.com/hashicorp/terraform-provider-vsphere/pull/2280)
11+
312
## 2.9.3 (October 8, 2024)
413

514
BUG FIX:

vsphere/data_source_vsphere_virtual_machine.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ func dataSourceVSphereVirtualMachine() *schema.Resource {
165165
Computed: true,
166166
Description: "Instance UUID of this virtual machine.",
167167
},
168+
"usb_controller": {
169+
Type: schema.TypeList,
170+
Computed: true,
171+
Description: "List of virtual USB controllers present on the virtual machine, including their versions.",
172+
Elem: &schema.Resource{
173+
Schema: map[string]*schema.Schema{
174+
"version": {
175+
Type: schema.TypeString,
176+
Computed: true,
177+
Description: "The version of the USB controller.",
178+
},
179+
},
180+
},
181+
},
168182
}
169183

170184
// Merge the VirtualMachineConfig structure so that we can include the number of
@@ -283,6 +297,26 @@ func dataSourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{
283297
return fmt.Errorf("error setting guest IP addresses: %s", err)
284298
}
285299
}
300+
301+
var usbControllers []map[string]interface{}
302+
303+
for _, dev := range props.Config.Hardware.Device {
304+
switch dev.(type) {
305+
case *types.VirtualUSBController:
306+
usbControllers = append(usbControllers, map[string]interface{}{
307+
"version": "2.x",
308+
})
309+
case *types.VirtualUSBXHCIController:
310+
usbControllers = append(usbControllers, map[string]interface{}{
311+
"version": "3.x",
312+
})
313+
}
314+
}
315+
316+
if err := d.Set("usb_controller", usbControllers); err != nil {
317+
return fmt.Errorf("error setting usb_controller: %s", err)
318+
}
319+
286320
log.Printf("[DEBUG] VM search for %q completed successfully (UUID %q)", name, props.Config.Uuid)
287321
return nil
288322
}

0 commit comments

Comments
 (0)