Skip to content

Commit

Permalink
Merge pull request #73 from V-Paranoiaque/feature/serial
Browse files Browse the repository at this point in the history
Add support for serial devices
  • Loading branch information
ggongaware committed Aug 13, 2019
2 parents 17f3cea + 7e6b78d commit 68c41fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ resource "proxmox_vm_qemu" "prepprovision-test" {
size = 4G
backup = true
}
# Serial interface of type socket is used by xterm.js
# You will need to configure your guest system before being able to use it
serial {
id = 0
type = "socket"
}
preprovision = true
ssh_forward_ip = "10.0.0.1"
ssh_user = "terraform"
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 @@ -274,6 +274,22 @@ func resourceVmQemu() *schema.Resource {
return strings.TrimSpace(old) == strings.TrimSpace(new)
},
},
"serial": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": &schema.Schema{
Type: schema.TypeInt,
Required: true,
},
"type": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
},
},
},
"os_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -375,6 +391,8 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
qemuNetworks := DevicesSetToMap(networks)
disks := d.Get("disk").(*schema.Set)
qemuDisks := DevicesSetToMap(disks)
serials := d.Get("serial").(*schema.Set)
qemuSerials := DevicesSetToMap(serials)

config := pxapi.ConfigQemu{
Name: vmName,
Expand All @@ -390,6 +408,7 @@ func resourceVmQemuCreate(d *schema.ResourceData, meta interface{}) error {
QemuOs: d.Get("qemu_os").(string),
QemuNetworks: qemuNetworks,
QemuDisks: qemuDisks,
QemuSerials: qemuSerials,
// Cloud-init.
CIuser: d.Get("ciuser").(string),
CIpassword: d.Get("cipassword").(string),
Expand Down Expand Up @@ -534,6 +553,8 @@ func resourceVmQemuUpdate(d *schema.ResourceData, meta interface{}) error {
qemuDisks := DevicesSetToMap(configDisksSet)
configNetworksSet := d.Get("network").(*schema.Set)
qemuNetworks := DevicesSetToMap(configNetworksSet)
serials := d.Get("serial").(*schema.Set)
qemuSerials := DevicesSetToMap(serials)

config := pxapi.ConfigQemu{
Name: d.Get("name").(string),
Expand All @@ -549,6 +570,7 @@ func resourceVmQemuUpdate(d *schema.ResourceData, meta interface{}) error {
QemuOs: d.Get("qemu_os").(string),
QemuNetworks: qemuNetworks,
QemuDisks: qemuDisks,
QemuSerials: qemuSerials,
// Cloud-init.
CIuser: d.Get("ciuser").(string),
CIpassword: d.Get("cipassword").(string),
Expand Down Expand Up @@ -664,6 +686,10 @@ func resourceVmQemuRead(d *schema.ResourceData, meta interface{}) error {
d.Set("vlan", config.QemuVlanTag)
d.Set("mac", config.QemuMacAddr)
d.Set("pool", vmr.Pool())
//Serials
configSerialsSet := d.Get("serial").(*schema.Set)
activeSerialSet := UpdateDevicesSet(configSerialsSet, config.QemuSerials)
d.Set("serial", activeSerialSet)

pmParallelEnd(pconf)
return nil
Expand Down

0 comments on commit 68c41fc

Please sign in to comment.