Skip to content

Commit 2be836d

Browse files
burnsjared0415tenthirtyam
authored andcommitted
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 a120bd8 commit 2be836d

File tree

5 files changed

+716
-290
lines changed

5 files changed

+716
-290
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
## .Next (Not Released)
44

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+
512
CHORE:
613

714
- `provider`: Updated `golang/go` to v1.22.8.
815
([#2289](https://github.com/terraform-providers/terraform-provider-vsphere/pull/2289))
916

10-
1117
## 2.10.0 (October 16, 2024)
1218

1319
FEATURES:

vsphere/data_source_vsphere_virtual_machine.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ func dataSourceVSphereVirtualMachine() *schema.Resource {
170170
Computed: true,
171171
Description: "Indicates whether a virtual Trusted Platform Module (TPM) device is present on the virtual machine.",
172172
},
173+
"usb_controller": {
174+
Type: schema.TypeList,
175+
Computed: true,
176+
Description: "List of virtual USB controllers present on the virtual machine, including their versions.",
177+
Elem: &schema.Resource{
178+
Schema: map[string]*schema.Schema{
179+
"version": {
180+
Type: schema.TypeString,
181+
Computed: true,
182+
Description: "The version of the USB controller.",
183+
},
184+
},
185+
},
186+
},
173187
}
174188

175189
// Merge the VirtualMachineConfig structure so that we can include the number of
@@ -298,6 +312,24 @@ func dataSourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{
298312
}
299313
_ = d.Set("vtpm_present", isVTPMPresent)
300314

315+
var usbControllers []map[string]interface{}
316+
for _, dev := range props.Config.Hardware.Device {
317+
switch dev.(type) {
318+
case *types.VirtualUSBController:
319+
usbControllers = append(usbControllers, map[string]interface{}{
320+
"version": "2.x",
321+
})
322+
case *types.VirtualUSBXHCIController:
323+
usbControllers = append(usbControllers, map[string]interface{}{
324+
"version": "3.x",
325+
})
326+
}
327+
}
328+
329+
if err := d.Set("usb_controller", usbControllers); err != nil {
330+
return fmt.Errorf("error setting usb_controller: %s", err)
331+
}
332+
301333
log.Printf("[DEBUG] VM search for %q completed successfully (UUID %q)", name, props.Config.Uuid)
302334
return nil
303335
}

0 commit comments

Comments
 (0)