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 Oct 30, 2024
1 parent adf6714 commit 95782f5
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# <!-- markdownlint-disable first-line-h1 no-inline-html -->

## 2.10.0 (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)

## 2.9.3 (October 8, 2024)

BUG FIX:
Expand Down
34 changes: 34 additions & 0 deletions vsphere/data_source_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ func dataSourceVSphereVirtualMachine() *schema.Resource {
Computed: true,
Description: "Instance UUID of this 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 @@ -283,6 +297,26 @@ func dataSourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("error setting guest IP addresses: %s", err)
}
}

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 95782f5

Please sign in to comment.