mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-08 14:55:02 +00:00
Add serial_device argument to VM resource
This commit is contained in:
parent
844ef98ae6
commit
23466ab289
@ -1,3 +1,9 @@
|
|||||||
|
## 0.3.0 (UNRELEASED)
|
||||||
|
|
||||||
|
ENHANCEMENTS:
|
||||||
|
|
||||||
|
* resource/virtual_environment_vm: Add `serial_device` argument
|
||||||
|
|
||||||
## 0.2.0
|
## 0.2.0
|
||||||
|
|
||||||
BREAKING CHANGES:
|
BREAKING CHANGES:
|
||||||
|
@ -621,6 +621,10 @@ This resource doesn't expose any additional attributes.
|
|||||||
* `wvista` - Windows Vista
|
* `wvista` - Windows Vista
|
||||||
* `wxp` - Windows XP
|
* `wxp` - Windows XP
|
||||||
* `pool_id` - (Optional) The ID of a pool to assign the virtual machine to
|
* `pool_id` - (Optional) The ID of a pool to assign the virtual machine to
|
||||||
|
* `serial_device` - (Optional) A serial device (multiple blocks supported)
|
||||||
|
* `device` - (Optional) The device (defaults to `socket`)
|
||||||
|
* `/dev/*` - A host serial device
|
||||||
|
* `socket` - A unix socket
|
||||||
* `started` - (Optional) Whether to start the virtual machine (defaults to `true`)
|
* `started` - (Optional) Whether to start the virtual machine (defaults to `true`)
|
||||||
* `tablet_device` - (Optional) Whether to enable the USB tablet device (defaults to `true`)
|
* `tablet_device` - (Optional) Whether to enable the USB tablet device (defaults to `true`)
|
||||||
* `vga` - (Optional) The VGA configuration
|
* `vga` - (Optional) The VGA configuration
|
||||||
|
@ -41,7 +41,10 @@ resource "proxmox_virtual_environment_vm" "example" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pool_id = "${proxmox_virtual_environment_pool.example.id}"
|
pool_id = "${proxmox_virtual_environment_pool.example.id}"
|
||||||
vm_id = 2038
|
|
||||||
|
serial_device {}
|
||||||
|
|
||||||
|
vm_id = 2038
|
||||||
|
|
||||||
connection {
|
connection {
|
||||||
type = "ssh"
|
type = "ssh"
|
||||||
|
@ -59,6 +59,7 @@ const (
|
|||||||
dvResourceVirtualEnvironmentVMNetworkDeviceVLANID = 0
|
dvResourceVirtualEnvironmentVMNetworkDeviceVLANID = 0
|
||||||
dvResourceVirtualEnvironmentVMOperatingSystemType = "other"
|
dvResourceVirtualEnvironmentVMOperatingSystemType = "other"
|
||||||
dvResourceVirtualEnvironmentVMPoolID = ""
|
dvResourceVirtualEnvironmentVMPoolID = ""
|
||||||
|
dvResourceVirtualEnvironmentVMSerialDeviceDevice = "socket"
|
||||||
dvResourceVirtualEnvironmentVMStarted = true
|
dvResourceVirtualEnvironmentVMStarted = true
|
||||||
dvResourceVirtualEnvironmentVMTabletDevice = true
|
dvResourceVirtualEnvironmentVMTabletDevice = true
|
||||||
dvResourceVirtualEnvironmentVMVGAEnabled = true
|
dvResourceVirtualEnvironmentVMVGAEnabled = true
|
||||||
@ -131,6 +132,8 @@ const (
|
|||||||
mkResourceVirtualEnvironmentVMOperatingSystem = "operating_system"
|
mkResourceVirtualEnvironmentVMOperatingSystem = "operating_system"
|
||||||
mkResourceVirtualEnvironmentVMOperatingSystemType = "type"
|
mkResourceVirtualEnvironmentVMOperatingSystemType = "type"
|
||||||
mkResourceVirtualEnvironmentVMPoolID = "pool_id"
|
mkResourceVirtualEnvironmentVMPoolID = "pool_id"
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDevice = "serial_device"
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDeviceDevice = "device"
|
||||||
mkResourceVirtualEnvironmentVMStarted = "started"
|
mkResourceVirtualEnvironmentVMStarted = "started"
|
||||||
mkResourceVirtualEnvironmentVMTabletDevice = "tablet_device"
|
mkResourceVirtualEnvironmentVMTabletDevice = "tablet_device"
|
||||||
mkResourceVirtualEnvironmentVMVGA = "vga"
|
mkResourceVirtualEnvironmentVMVGA = "vga"
|
||||||
@ -757,6 +760,31 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
|
|||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
Default: dvResourceVirtualEnvironmentVMPoolID,
|
Default: dvResourceVirtualEnvironmentVMPoolID,
|
||||||
},
|
},
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDevice: &schema.Schema{
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Description: "The serial devices",
|
||||||
|
Optional: true,
|
||||||
|
DefaultFunc: func() (interface{}, error) {
|
||||||
|
return []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDeviceDevice: dvResourceVirtualEnvironmentVMSerialDeviceDevice,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDeviceDevice: {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Description: "The device",
|
||||||
|
Optional: true,
|
||||||
|
Default: dvResourceVirtualEnvironmentVMSerialDeviceDevice,
|
||||||
|
ValidateFunc: resourceVirtualEnvironmentVMGetSerialDeviceValidator(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MaxItems: 4,
|
||||||
|
MinItems: 0,
|
||||||
|
},
|
||||||
mkResourceVirtualEnvironmentVMStarted: {
|
mkResourceVirtualEnvironmentVMStarted: {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Description: "Whether to start the virtual machine",
|
Description: "Whether to start the virtual machine",
|
||||||
@ -927,6 +955,13 @@ func resourceVirtualEnvironmentVMCreate(d *schema.ResourceData, m interface{}) e
|
|||||||
operatingSystemType := operatingSystem[mkResourceVirtualEnvironmentVMOperatingSystemType].(string)
|
operatingSystemType := operatingSystem[mkResourceVirtualEnvironmentVMOperatingSystemType].(string)
|
||||||
|
|
||||||
poolID := d.Get(mkResourceVirtualEnvironmentVMPoolID).(string)
|
poolID := d.Get(mkResourceVirtualEnvironmentVMPoolID).(string)
|
||||||
|
|
||||||
|
serialDevices, err := resourceVirtualEnvironmentVMGetSerialDeviceList(d, m)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
started := proxmox.CustomBool(d.Get(mkResourceVirtualEnvironmentVMStarted).(bool))
|
started := proxmox.CustomBool(d.Get(mkResourceVirtualEnvironmentVMStarted).(bool))
|
||||||
tabletDevice := proxmox.CustomBool(d.Get(mkResourceVirtualEnvironmentVMTabletDevice).(bool))
|
tabletDevice := proxmox.CustomBool(d.Get(mkResourceVirtualEnvironmentVMTabletDevice).(bool))
|
||||||
|
|
||||||
@ -1016,7 +1051,7 @@ func resourceVirtualEnvironmentVMCreate(d *schema.ResourceData, m interface{}) e
|
|||||||
PoolID: &poolID,
|
PoolID: &poolID,
|
||||||
SCSIDevices: diskDeviceObjects,
|
SCSIDevices: diskDeviceObjects,
|
||||||
SCSIHardware: &scsiHardware,
|
SCSIHardware: &scsiHardware,
|
||||||
SerialDevices: []string{"socket"},
|
SerialDevices: serialDevices,
|
||||||
SharedMemory: memorySharedObject,
|
SharedMemory: memorySharedObject,
|
||||||
StartOnBoot: &started,
|
StartOnBoot: &started,
|
||||||
TabletDeviceEnabled: &tabletDevice,
|
TabletDeviceEnabled: &tabletDevice,
|
||||||
@ -1433,6 +1468,39 @@ func resourceVirtualEnvironmentVMGetOperatingSystemTypeValidator() schema.Schema
|
|||||||
}, false)
|
}, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourceVirtualEnvironmentVMGetSerialDeviceList(d *schema.ResourceData, m interface{}) (proxmox.CustomSerialDevices, error) {
|
||||||
|
device := d.Get(mkResourceVirtualEnvironmentVMSerialDevice).([]interface{})
|
||||||
|
list := make(proxmox.CustomSerialDevices, len(device))
|
||||||
|
|
||||||
|
for i, v := range device {
|
||||||
|
block := v.(map[string]interface{})
|
||||||
|
|
||||||
|
device, _ := block[mkResourceVirtualEnvironmentVMSerialDeviceDevice].(string)
|
||||||
|
|
||||||
|
list[i] = device
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func resourceVirtualEnvironmentVMGetSerialDeviceValidator() schema.SchemaValidateFunc {
|
||||||
|
return func(i interface{}, k string) (s []string, es []error) {
|
||||||
|
v, ok := i.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
es = append(es, fmt.Errorf("expected type of %s to be string", k))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(v, "/dev/") && v != "socket" {
|
||||||
|
es = append(es, fmt.Errorf("expected %s to be '/dev/*' or 'socket'", k))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentVMGetVGADeviceObject(d *schema.ResourceData, m interface{}) (*proxmox.CustomVGADevice, error) {
|
func resourceVirtualEnvironmentVMGetVGADeviceObject(d *schema.ResourceData, m interface{}) (*proxmox.CustomVGADevice, error) {
|
||||||
resource := resourceVirtualEnvironmentVM()
|
resource := resourceVirtualEnvironmentVM()
|
||||||
|
|
||||||
@ -2027,6 +2095,31 @@ func resourceVirtualEnvironmentVMRead(d *schema.ResourceData, m interface{}) err
|
|||||||
d.Set(mkResourceVirtualEnvironmentVMPoolID, *vmConfig.PoolID)
|
d.Set(mkResourceVirtualEnvironmentVMPoolID, *vmConfig.PoolID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compare the serial devices to those stored in the state.
|
||||||
|
serialDevices := make([]interface{}, 4)
|
||||||
|
serialDevicesArray := []*string{
|
||||||
|
vmConfig.SerialDevice0,
|
||||||
|
vmConfig.SerialDevice1,
|
||||||
|
vmConfig.SerialDevice2,
|
||||||
|
vmConfig.SerialDevice3,
|
||||||
|
}
|
||||||
|
serialDevicesCount := 0
|
||||||
|
|
||||||
|
for sdi, sd := range serialDevicesArray {
|
||||||
|
m := map[string]interface{}{}
|
||||||
|
|
||||||
|
if sd != nil {
|
||||||
|
m[mkResourceVirtualEnvironmentVMSerialDeviceDevice] = *sd
|
||||||
|
serialDevicesCount = sdi + 1
|
||||||
|
} else {
|
||||||
|
m[mkResourceVirtualEnvironmentVMSerialDeviceDevice] = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
serialDevices[sdi] = m
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Set(mkResourceVirtualEnvironmentVMSerialDevice, serialDevices[:serialDevicesCount])
|
||||||
|
|
||||||
// Compare the VGA configuration to the one stored in the state.
|
// Compare the VGA configuration to the one stored in the state.
|
||||||
vga := map[string]interface{}{}
|
vga := map[string]interface{}{}
|
||||||
|
|
||||||
@ -2403,6 +2496,17 @@ func resourceVirtualEnvironmentVMUpdate(d *schema.ResourceData, m interface{}) e
|
|||||||
rebootRequired = true
|
rebootRequired = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepare the new serial devices.
|
||||||
|
if d.HasChange(mkResourceVirtualEnvironmentVMSerialDevice) {
|
||||||
|
body.SerialDevices, err = resourceVirtualEnvironmentVMGetSerialDeviceList(d, m)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rebootRequired = true
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare the new VGA configuration.
|
// Prepare the new VGA configuration.
|
||||||
if d.HasChange(mkResourceVirtualEnvironmentVMVGA) {
|
if d.HasChange(mkResourceVirtualEnvironmentVMVGA) {
|
||||||
body.VGADevice, err = resourceVirtualEnvironmentVMGetVGADeviceObject(d, m)
|
body.VGADevice, err = resourceVirtualEnvironmentVMGetVGADeviceObject(d, m)
|
||||||
|
@ -41,6 +41,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
mkResourceVirtualEnvironmentVMNetworkDevice,
|
mkResourceVirtualEnvironmentVMNetworkDevice,
|
||||||
mkResourceVirtualEnvironmentVMOperatingSystem,
|
mkResourceVirtualEnvironmentVMOperatingSystem,
|
||||||
mkResourceVirtualEnvironmentVMPoolID,
|
mkResourceVirtualEnvironmentVMPoolID,
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDevice,
|
||||||
mkResourceVirtualEnvironmentVMStarted,
|
mkResourceVirtualEnvironmentVMStarted,
|
||||||
mkResourceVirtualEnvironmentVMTabletDevice,
|
mkResourceVirtualEnvironmentVMTabletDevice,
|
||||||
mkResourceVirtualEnvironmentVMVMID,
|
mkResourceVirtualEnvironmentVMVMID,
|
||||||
@ -72,6 +73,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
mkResourceVirtualEnvironmentVMNetworkInterfaceNames,
|
mkResourceVirtualEnvironmentVMNetworkInterfaceNames,
|
||||||
mkResourceVirtualEnvironmentVMOperatingSystem,
|
mkResourceVirtualEnvironmentVMOperatingSystem,
|
||||||
mkResourceVirtualEnvironmentVMPoolID,
|
mkResourceVirtualEnvironmentVMPoolID,
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDevice,
|
||||||
mkResourceVirtualEnvironmentVMStarted,
|
mkResourceVirtualEnvironmentVMStarted,
|
||||||
mkResourceVirtualEnvironmentVMTabletDevice,
|
mkResourceVirtualEnvironmentVMTabletDevice,
|
||||||
mkResourceVirtualEnvironmentVMVMID,
|
mkResourceVirtualEnvironmentVMVMID,
|
||||||
@ -94,6 +96,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
schema.TypeList,
|
schema.TypeList,
|
||||||
schema.TypeList,
|
schema.TypeList,
|
||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
|
schema.TypeList,
|
||||||
schema.TypeBool,
|
schema.TypeBool,
|
||||||
schema.TypeBool,
|
schema.TypeBool,
|
||||||
schema.TypeInt,
|
schema.TypeInt,
|
||||||
@ -357,6 +360,18 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
serialDeviceSchema := testNestedSchemaExistence(t, s, mkResourceVirtualEnvironmentVMSerialDevice)
|
||||||
|
|
||||||
|
testOptionalArguments(t, serialDeviceSchema, []string{
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDeviceDevice,
|
||||||
|
})
|
||||||
|
|
||||||
|
testSchemaValueTypes(t, serialDeviceSchema, []string{
|
||||||
|
mkResourceVirtualEnvironmentVMSerialDeviceDevice,
|
||||||
|
}, []schema.ValueType{
|
||||||
|
schema.TypeString,
|
||||||
|
})
|
||||||
|
|
||||||
vgaSchema := testNestedSchemaExistence(t, s, mkResourceVirtualEnvironmentVMVGA)
|
vgaSchema := testNestedSchemaExistence(t, s, mkResourceVirtualEnvironmentVMVGA)
|
||||||
|
|
||||||
testOptionalArguments(t, vgaSchema, []string{
|
testOptionalArguments(t, vgaSchema, []string{
|
||||||
|
@ -9,5 +9,5 @@ const (
|
|||||||
TerraformProviderName = "terraform-provider-proxmox"
|
TerraformProviderName = "terraform-provider-proxmox"
|
||||||
|
|
||||||
// TerraformProviderVersion specifies the version number.
|
// TerraformProviderVersion specifies the version number.
|
||||||
TerraformProviderVersion = "0.2.0"
|
TerraformProviderVersion = "0.3.0"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user