Skip to content

Commit

Permalink
feat:r/vsphere_virtual_machine add usb controller
Browse files Browse the repository at this point in the history
Add the ability to add usb controller on build and modification of virtual machine.

Signed-off-by: Jared Burns <[email protected]>
  • Loading branch information
burnsjared0415 committed Nov 8, 2024
1 parent a120bd8 commit 911cae3
Show file tree
Hide file tree
Showing 5 changed files with 715 additions and 290 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

## .Next (Not Released)

FEATURES:

- `resource/vsphere_virtual_machine`: Adds ability to add `usb_controller` to virtual machine on creation or clone.
[#2280](https://github.com/hashicorp/terraform-provider-vsphere/pull/2280)
- `data/vsphere_virtual_machine`: Adds ability read `usb_controller` on virtual machine; will return `true` or `false` based on the configuration.
[#2280](https://github.com/hashicorp/terraform-provider-vsphere/pull/2280)

CHORE:

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


## 2.10.0 (October 16, 2024)

FEATURES:
Expand Down
32 changes: 32 additions & 0 deletions vsphere/data_source_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ func dataSourceVSphereVirtualMachine() *schema.Resource {
Computed: true,
Description: "Indicates whether a virtual Trusted Platform Module (TPM) device is present on the virtual machine.",
},
"usb_controller": {
Type: schema.TypeList,
Computed: true,
Description: "List of virtual USB controllers present on the virtual machine, including their versions.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeString,
Computed: true,
Description: "The version of the USB controller.",
},
},
},
},
}

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

var usbControllers []map[string]interface{}
for _, dev := range props.Config.Hardware.Device {
switch dev.(type) {
case *types.VirtualUSBController:
usbControllers = append(usbControllers, map[string]interface{}{
"version": "2.x",
})
case *types.VirtualUSBXHCIController:
usbControllers = append(usbControllers, map[string]interface{}{
"version": "3.x",
})
}
}

if err := d.Set("usb_controller", usbControllers); err != nil {
return fmt.Errorf("error setting usb_controller: %s", err)
}

log.Printf("[DEBUG] VM search for %q completed successfully (UUID %q)", name, props.Config.Uuid)
return nil
}
Loading

0 comments on commit 911cae3

Please sign in to comment.