mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 02:31:10 +00:00
feat(vm): add support for disk.serial
attribute (#1385)
* feat(vm): add support for `disk.serial` attribute Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
cfe1b1cc4b
commit
de349523fe
@ -276,6 +276,7 @@ output "ubuntu_vm_public_key" {
|
||||
- `iothread` - (Optional) Whether to use iothreads for this disk (defaults
|
||||
to `false`).
|
||||
- `replicate` - (Optional) Whether the drive should be considered for replication jobs (defaults to `true`).
|
||||
- `serial` - (Optional) The serial number of the disk, up to 20 bytes long.
|
||||
- `size` - (Optional) The disk size in gigabytes (defaults to `8`).
|
||||
- `speed` - (Optional) The speed limits.
|
||||
- `iops_read` - (Optional) The maximum read I/O in operations per second.
|
||||
|
@ -53,6 +53,7 @@ resource "proxmox_virtual_environment_vm" "example_template" {
|
||||
interface = "scsi0"
|
||||
discard = "on"
|
||||
cache = "writeback"
|
||||
serial = "dead_beef"
|
||||
ssd = true
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,7 @@ func TestAccResourceVMDisks(t *testing.T) {
|
||||
file_format = "raw"
|
||||
datastore_id = "local-lvm"
|
||||
interface = "virtio0"
|
||||
serial = "-dead_beef-"
|
||||
size = 8
|
||||
replicate = false
|
||||
aio = "native"
|
||||
@ -93,6 +94,7 @@ func TestAccResourceVMDisks(t *testing.T) {
|
||||
"disk.0.iothread": "false",
|
||||
"disk.0.path_in_datastore": `vm-\d+-disk-\d+`,
|
||||
"disk.0.replicate": "false",
|
||||
"disk.0.serial": "-dead_beef-",
|
||||
"disk.0.size": "8",
|
||||
"disk.0.ssd": "false",
|
||||
"disk.0.speed.0.iops_read": "100",
|
||||
@ -122,6 +124,7 @@ func TestAccResourceVMDisks(t *testing.T) {
|
||||
interface = "virtio0"
|
||||
iothread = true
|
||||
discard = "on"
|
||||
serial = "dead_beef"
|
||||
size = 20
|
||||
}
|
||||
}`),
|
||||
@ -134,6 +137,7 @@ func TestAccResourceVMDisks(t *testing.T) {
|
||||
"disk.0.interface": "virtio0",
|
||||
"disk.0.iothread": "true",
|
||||
"disk.0.path_in_datastore": `vm-\d+-disk-\d+`,
|
||||
"disk.0.serial": "dead_beef",
|
||||
"disk.0.size": "20",
|
||||
"disk.0.ssd": "false",
|
||||
}),
|
||||
|
@ -38,6 +38,7 @@ type CustomStorageDevice struct {
|
||||
MaxWriteSpeedMbps *int `json:"mbps_wr,omitempty" url:"mbps_wr,omitempty"`
|
||||
Media *string `json:"media,omitempty" url:"media,omitempty"`
|
||||
Replicate *types.CustomBool `json:"replicate,omitempty" url:"replicate,omitempty,int"`
|
||||
Serial *string `json:"serial,omitempty" url:"serial,omitempty"`
|
||||
Size *types.DiskSize `json:"size,omitempty" url:"size,omitempty"`
|
||||
SSD *types.CustomBool `json:"ssd,omitempty" url:"ssd,omitempty,int"`
|
||||
DatastoreID *string `json:"-" url:"-"`
|
||||
@ -160,6 +161,10 @@ func (d *CustomStorageDevice) EncodeOptions() string {
|
||||
}
|
||||
}
|
||||
|
||||
if d.Serial != nil && *d.Serial != "" {
|
||||
values = append(values, fmt.Sprintf("serial=%s", *d.Serial))
|
||||
}
|
||||
|
||||
if d.SSD != nil {
|
||||
if *d.SSD {
|
||||
values = append(values, "ssd=1")
|
||||
@ -346,6 +351,9 @@ func (d *CustomStorageDevice) UnmarshalJSON(b []byte) error {
|
||||
bv := types.CustomBool(v[1] == "1")
|
||||
d.Replicate = &bv
|
||||
|
||||
case "serial":
|
||||
d.Serial = &v[1]
|
||||
|
||||
case "size":
|
||||
d.Size = new(types.DiskSize)
|
||||
|
||||
|
@ -258,6 +258,7 @@ func GetDiskDeviceObjects(
|
||||
fileID, _ := block[mkDiskFileID].(string)
|
||||
ioThread := types.CustomBool(block[mkDiskIOThread].(bool))
|
||||
replicate := types.CustomBool(block[mkDiskReplicate].(bool))
|
||||
serial := block[mkDiskSerial].(string)
|
||||
size, _ := block[mkDiskSize].(int)
|
||||
ssd := types.CustomBool(block[mkDiskSSD].(bool))
|
||||
|
||||
@ -301,6 +302,7 @@ func GetDiskDeviceObjects(
|
||||
diskDevice.Format = &fileFormat
|
||||
diskDevice.Interface = &diskInterface
|
||||
diskDevice.Replicate = &replicate
|
||||
diskDevice.Serial = &serial
|
||||
diskDevice.Size = types.DiskSizeFromGigabytes(int64(size))
|
||||
|
||||
if !strings.HasPrefix(diskInterface, "virtio") {
|
||||
@ -535,6 +537,12 @@ func Read(
|
||||
disk[mkDiskReplicate] = true
|
||||
}
|
||||
|
||||
if dd.Serial != nil {
|
||||
disk[mkDiskSerial] = *dd.Serial
|
||||
} else {
|
||||
disk[mkDiskSerial] = ""
|
||||
}
|
||||
|
||||
if dd.SSD != nil {
|
||||
disk[mkDiskSSD] = *dd.SSD
|
||||
} else {
|
||||
@ -700,6 +708,7 @@ func Update(
|
||||
tmp.MaxReadSpeedMbps = disk.MaxReadSpeedMbps
|
||||
tmp.MaxWriteSpeedMbps = disk.MaxWriteSpeedMbps
|
||||
tmp.Replicate = disk.Replicate
|
||||
tmp.Serial = disk.Serial
|
||||
tmp.SSD = disk.SSD
|
||||
|
||||
switch prefix {
|
||||
|
@ -1,3 +1,9 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
@ -34,6 +40,7 @@ const (
|
||||
mkDiskIOThread = "iothread"
|
||||
mkDiskPathInDatastore = "path_in_datastore"
|
||||
mkDiskReplicate = "replicate"
|
||||
mkDiskSerial = "serial"
|
||||
mkDiskSize = "size"
|
||||
mkDiskSpeed = "speed"
|
||||
mkDiskSpeedRead = "read"
|
||||
@ -63,6 +70,7 @@ func Schema() map[string]*schema.Schema {
|
||||
mkDiskIOThread: false,
|
||||
mkDiskPathInDatastore: nil,
|
||||
mkDiskReplicate: true,
|
||||
mkDiskSerial: "",
|
||||
mkDiskSize: dvDiskSize,
|
||||
mkDiskSSD: false,
|
||||
},
|
||||
@ -126,6 +134,13 @@ func Schema() map[string]*schema.Schema {
|
||||
Default: "",
|
||||
ValidateDiagFunc: validators.FileID(),
|
||||
},
|
||||
mkDiskSerial: {
|
||||
Type: schema.TypeString,
|
||||
Description: "The drive’s reported serial number",
|
||||
Optional: true,
|
||||
Default: "",
|
||||
ValidateDiagFunc: validation.ToDiagFunc(validation.StringLenBetween(0, 20)),
|
||||
},
|
||||
mkDiskSize: {
|
||||
Type: schema.TypeInt,
|
||||
Description: "The disk size in gigabytes",
|
||||
|
Loading…
Reference in New Issue
Block a user