Skip to content

Commit

Permalink
Merge pull request #490 from Neonox31/feat-qemu-add-usb-devices-support
Browse files Browse the repository at this point in the history
feat(qemu): add usb devices support
  • Loading branch information
mleone87 committed Jan 29, 2022
2 parents 72c6277 + 6d264d1 commit a44e076
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
16 changes: 16 additions & 0 deletions docs/resources/vm_qemu.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ details.
| `type` | `str` | | ** |
| Required** The type of serial device to create. Options: `socket`, or the path to a serial device like `/dev/ttyS0`. | | | |

### USB Block

The `usb` block is used to configure USB devices. It may be specified multiple times. The order in which the
blocks are specified determines the ID for each net device. i.e. The first `usb` block will become `usb0`, the
second will be `usb1` etc...

See the [docs about USB passthrough](https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_usb_passthrough) for more
details.

| Argument | Type | Default Value | Description |
|-------------------------------------------------------------------------------------------------------------------|--------|---------------|------------------------------------------------------------------|
| `host` | `str` | | ** |
| Required** USB device host. This can either be done via the vendor- and product-id, or via the host bus and port. | | | |
| `usb3` | `bool` | `false` | Specifies whether if given host option is a USB3 device or port. |


## Attribute Reference

In addition to the arguments above, the following attributes can be referenced from this resource.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Telmate/terraform-provider-proxmox
go 1.16

require (
github.com/Telmate/proxmox-api-go v0.0.0-20211123192920-062fd1a6ab10
github.com/Telmate/proxmox-api-go v0.0.0-20220129131641-6909b62b8cf0
github.com/agext/levenshtein v1.2.3 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C6
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/Telmate/proxmox-api-go v0.0.0-20211123192920-062fd1a6ab10 h1:lJNkRZEptfaQsmo4pWBIsWRo9cOGw0somkXecKapedU=
github.com/Telmate/proxmox-api-go v0.0.0-20211123192920-062fd1a6ab10/go.mod h1:keBhXWLa+UBajvf79xvKcfiqeIc7vZL9wOqxuy1CBGw=
github.com/Telmate/proxmox-api-go v0.0.0-20220129131641-6909b62b8cf0 h1:tq3jryt750KRU0oxEQCQHKxh2QQ+Y8nFMtyZtO7yv8I=
github.com/Telmate/proxmox-api-go v0.0.0-20220129131641-6909b62b8cf0/go.mod h1:keBhXWLa+UBajvf79xvKcfiqeIc7vZL9wOqxuy1CBGw=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down
26 changes: 26 additions & 0 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,22 @@ func resourceVmQemu() *schema.Resource {
},
},
},
"usb": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"host": {
Type: schema.TypeString,
Required: true,
},
"usb3": {
Type: schema.TypeBool,
Optional: true,
},
},
},
},
"os_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -706,6 +722,8 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
serials := d.Get("serial").(*schema.Set)
qemuSerials, _ := DevicesSetToMap(serials)

qemuUsbs, _ := ExpandDevicesList(d.Get("usb").([]interface{}))

config := pxapi.ConfigQemu{
Name: vmName,
Description: d.Get("desc").(string),
Expand Down Expand Up @@ -734,6 +752,7 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
QemuNetworks: qemuNetworks,
QemuDisks: qemuDisks,
QemuSerials: qemuSerials,
QemuUsbs: qemuUsbs,
// Cloud-init.
CIuser: d.Get("ciuser").(string),
CIpassword: d.Get("cipassword").(string),
Expand Down Expand Up @@ -972,6 +991,11 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
serials := d.Get("serial").(*schema.Set)
qemuSerials, _ := DevicesSetToMap(serials)

qemuUsbs, err := ExpandDevicesList(d.Get("usb").([]interface{}))
if err != nil {
return diag.FromErr(fmt.Errorf("error while processing Usb configuration: %v", err))
}

d.Partial(true)
if d.HasChange("target_node") {
_, err := client.MigrateNode(vmr, d.Get("target_node").(string), true)
Expand Down Expand Up @@ -1010,6 +1034,7 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
QemuNetworks: qemuNetworks,
QemuDisks: qemuDisks,
QemuSerials: qemuSerials,
QemuUsbs: qemuUsbs,
// Cloud-init.
CIuser: d.Get("ciuser").(string),
CIpassword: d.Get("cipassword").(string),
Expand Down Expand Up @@ -1099,6 +1124,7 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
"kvm",
"vga",
"serial",
"usb",
) {
d.Set("reboot_required", true)
}
Expand Down

0 comments on commit a44e076

Please sign in to comment.