mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 19:12:59 +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
|
- `iothread` - (Optional) Whether to use iothreads for this disk (defaults
|
||||||
to `false`).
|
to `false`).
|
||||||
- `replicate` - (Optional) Whether the drive should be considered for replication jobs (defaults to `true`).
|
- `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`).
|
- `size` - (Optional) The disk size in gigabytes (defaults to `8`).
|
||||||
- `speed` - (Optional) The speed limits.
|
- `speed` - (Optional) The speed limits.
|
||||||
- `iops_read` - (Optional) The maximum read I/O in operations per second.
|
- `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"
|
interface = "scsi0"
|
||||||
discard = "on"
|
discard = "on"
|
||||||
cache = "writeback"
|
cache = "writeback"
|
||||||
|
serial = "dead_beef"
|
||||||
ssd = true
|
ssd = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ func TestAccResourceVMDisks(t *testing.T) {
|
|||||||
file_format = "raw"
|
file_format = "raw"
|
||||||
datastore_id = "local-lvm"
|
datastore_id = "local-lvm"
|
||||||
interface = "virtio0"
|
interface = "virtio0"
|
||||||
|
serial = "-dead_beef-"
|
||||||
size = 8
|
size = 8
|
||||||
replicate = false
|
replicate = false
|
||||||
aio = "native"
|
aio = "native"
|
||||||
@ -93,6 +94,7 @@ func TestAccResourceVMDisks(t *testing.T) {
|
|||||||
"disk.0.iothread": "false",
|
"disk.0.iothread": "false",
|
||||||
"disk.0.path_in_datastore": `vm-\d+-disk-\d+`,
|
"disk.0.path_in_datastore": `vm-\d+-disk-\d+`,
|
||||||
"disk.0.replicate": "false",
|
"disk.0.replicate": "false",
|
||||||
|
"disk.0.serial": "-dead_beef-",
|
||||||
"disk.0.size": "8",
|
"disk.0.size": "8",
|
||||||
"disk.0.ssd": "false",
|
"disk.0.ssd": "false",
|
||||||
"disk.0.speed.0.iops_read": "100",
|
"disk.0.speed.0.iops_read": "100",
|
||||||
@ -122,6 +124,7 @@ func TestAccResourceVMDisks(t *testing.T) {
|
|||||||
interface = "virtio0"
|
interface = "virtio0"
|
||||||
iothread = true
|
iothread = true
|
||||||
discard = "on"
|
discard = "on"
|
||||||
|
serial = "dead_beef"
|
||||||
size = 20
|
size = 20
|
||||||
}
|
}
|
||||||
}`),
|
}`),
|
||||||
@ -134,6 +137,7 @@ func TestAccResourceVMDisks(t *testing.T) {
|
|||||||
"disk.0.interface": "virtio0",
|
"disk.0.interface": "virtio0",
|
||||||
"disk.0.iothread": "true",
|
"disk.0.iothread": "true",
|
||||||
"disk.0.path_in_datastore": `vm-\d+-disk-\d+`,
|
"disk.0.path_in_datastore": `vm-\d+-disk-\d+`,
|
||||||
|
"disk.0.serial": "dead_beef",
|
||||||
"disk.0.size": "20",
|
"disk.0.size": "20",
|
||||||
"disk.0.ssd": "false",
|
"disk.0.ssd": "false",
|
||||||
}),
|
}),
|
||||||
|
@ -38,6 +38,7 @@ type CustomStorageDevice struct {
|
|||||||
MaxWriteSpeedMbps *int `json:"mbps_wr,omitempty" url:"mbps_wr,omitempty"`
|
MaxWriteSpeedMbps *int `json:"mbps_wr,omitempty" url:"mbps_wr,omitempty"`
|
||||||
Media *string `json:"media,omitempty" url:"media,omitempty"`
|
Media *string `json:"media,omitempty" url:"media,omitempty"`
|
||||||
Replicate *types.CustomBool `json:"replicate,omitempty" url:"replicate,omitempty,int"`
|
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"`
|
Size *types.DiskSize `json:"size,omitempty" url:"size,omitempty"`
|
||||||
SSD *types.CustomBool `json:"ssd,omitempty" url:"ssd,omitempty,int"`
|
SSD *types.CustomBool `json:"ssd,omitempty" url:"ssd,omitempty,int"`
|
||||||
DatastoreID *string `json:"-" url:"-"`
|
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 != nil {
|
||||||
if *d.SSD {
|
if *d.SSD {
|
||||||
values = append(values, "ssd=1")
|
values = append(values, "ssd=1")
|
||||||
@ -346,6 +351,9 @@ func (d *CustomStorageDevice) UnmarshalJSON(b []byte) error {
|
|||||||
bv := types.CustomBool(v[1] == "1")
|
bv := types.CustomBool(v[1] == "1")
|
||||||
d.Replicate = &bv
|
d.Replicate = &bv
|
||||||
|
|
||||||
|
case "serial":
|
||||||
|
d.Serial = &v[1]
|
||||||
|
|
||||||
case "size":
|
case "size":
|
||||||
d.Size = new(types.DiskSize)
|
d.Size = new(types.DiskSize)
|
||||||
|
|
||||||
|
@ -258,6 +258,7 @@ func GetDiskDeviceObjects(
|
|||||||
fileID, _ := block[mkDiskFileID].(string)
|
fileID, _ := block[mkDiskFileID].(string)
|
||||||
ioThread := types.CustomBool(block[mkDiskIOThread].(bool))
|
ioThread := types.CustomBool(block[mkDiskIOThread].(bool))
|
||||||
replicate := types.CustomBool(block[mkDiskReplicate].(bool))
|
replicate := types.CustomBool(block[mkDiskReplicate].(bool))
|
||||||
|
serial := block[mkDiskSerial].(string)
|
||||||
size, _ := block[mkDiskSize].(int)
|
size, _ := block[mkDiskSize].(int)
|
||||||
ssd := types.CustomBool(block[mkDiskSSD].(bool))
|
ssd := types.CustomBool(block[mkDiskSSD].(bool))
|
||||||
|
|
||||||
@ -301,6 +302,7 @@ func GetDiskDeviceObjects(
|
|||||||
diskDevice.Format = &fileFormat
|
diskDevice.Format = &fileFormat
|
||||||
diskDevice.Interface = &diskInterface
|
diskDevice.Interface = &diskInterface
|
||||||
diskDevice.Replicate = &replicate
|
diskDevice.Replicate = &replicate
|
||||||
|
diskDevice.Serial = &serial
|
||||||
diskDevice.Size = types.DiskSizeFromGigabytes(int64(size))
|
diskDevice.Size = types.DiskSizeFromGigabytes(int64(size))
|
||||||
|
|
||||||
if !strings.HasPrefix(diskInterface, "virtio") {
|
if !strings.HasPrefix(diskInterface, "virtio") {
|
||||||
@ -535,6 +537,12 @@ func Read(
|
|||||||
disk[mkDiskReplicate] = true
|
disk[mkDiskReplicate] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dd.Serial != nil {
|
||||||
|
disk[mkDiskSerial] = *dd.Serial
|
||||||
|
} else {
|
||||||
|
disk[mkDiskSerial] = ""
|
||||||
|
}
|
||||||
|
|
||||||
if dd.SSD != nil {
|
if dd.SSD != nil {
|
||||||
disk[mkDiskSSD] = *dd.SSD
|
disk[mkDiskSSD] = *dd.SSD
|
||||||
} else {
|
} else {
|
||||||
@ -700,6 +708,7 @@ func Update(
|
|||||||
tmp.MaxReadSpeedMbps = disk.MaxReadSpeedMbps
|
tmp.MaxReadSpeedMbps = disk.MaxReadSpeedMbps
|
||||||
tmp.MaxWriteSpeedMbps = disk.MaxWriteSpeedMbps
|
tmp.MaxWriteSpeedMbps = disk.MaxWriteSpeedMbps
|
||||||
tmp.Replicate = disk.Replicate
|
tmp.Replicate = disk.Replicate
|
||||||
|
tmp.Serial = disk.Serial
|
||||||
tmp.SSD = disk.SSD
|
tmp.SSD = disk.SSD
|
||||||
|
|
||||||
switch prefix {
|
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
|
package disk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -34,6 +40,7 @@ const (
|
|||||||
mkDiskIOThread = "iothread"
|
mkDiskIOThread = "iothread"
|
||||||
mkDiskPathInDatastore = "path_in_datastore"
|
mkDiskPathInDatastore = "path_in_datastore"
|
||||||
mkDiskReplicate = "replicate"
|
mkDiskReplicate = "replicate"
|
||||||
|
mkDiskSerial = "serial"
|
||||||
mkDiskSize = "size"
|
mkDiskSize = "size"
|
||||||
mkDiskSpeed = "speed"
|
mkDiskSpeed = "speed"
|
||||||
mkDiskSpeedRead = "read"
|
mkDiskSpeedRead = "read"
|
||||||
@ -63,6 +70,7 @@ func Schema() map[string]*schema.Schema {
|
|||||||
mkDiskIOThread: false,
|
mkDiskIOThread: false,
|
||||||
mkDiskPathInDatastore: nil,
|
mkDiskPathInDatastore: nil,
|
||||||
mkDiskReplicate: true,
|
mkDiskReplicate: true,
|
||||||
|
mkDiskSerial: "",
|
||||||
mkDiskSize: dvDiskSize,
|
mkDiskSize: dvDiskSize,
|
||||||
mkDiskSSD: false,
|
mkDiskSSD: false,
|
||||||
},
|
},
|
||||||
@ -126,6 +134,13 @@ func Schema() map[string]*schema.Schema {
|
|||||||
Default: "",
|
Default: "",
|
||||||
ValidateDiagFunc: validators.FileID(),
|
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: {
|
mkDiskSize: {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Description: "The disk size in gigabytes",
|
Description: "The disk size in gigabytes",
|
||||||
|
Loading…
Reference in New Issue
Block a user