mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-02 03:22:59 +00:00
feat: add support for "ssd" disk flag for VM (#181)
* feat: add support for ssd flag * update docs, add `ssd` to examples * restore original .md formatting Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
0df14f9d6a
commit
290734655c
@ -183,6 +183,7 @@ output "ubuntu_vm_public_key" {
|
|||||||
* `description` - (Optional) The description.
|
* `description` - (Optional) The description.
|
||||||
* `disk` - (Optional) A disk (multiple blocks supported).
|
* `disk` - (Optional) A disk (multiple blocks supported).
|
||||||
* `datastore_id` - (Optional) The identifier for the datastore to create the disk in (defaults to `local-lvm`).
|
* `datastore_id` - (Optional) The identifier for the datastore to create the disk in (defaults to `local-lvm`).
|
||||||
|
* `discard` - (Optional) Whether to pass discard/trim requests to the underlying storage. Supported values are `on`/`ignore` (defaults to `ignore`)
|
||||||
* `file_format` - (Optional) The file format (defaults to `qcow2`).
|
* `file_format` - (Optional) The file format (defaults to `qcow2`).
|
||||||
* `qcow2` - QEMU Disk Image v2.
|
* `qcow2` - QEMU Disk Image v2.
|
||||||
* `raw` - Raw Disk Image.
|
* `raw` - Raw Disk Image.
|
||||||
@ -190,14 +191,14 @@ output "ubuntu_vm_public_key" {
|
|||||||
* `file_id` - (Optional) The file ID for a disk image (experimental - might cause high CPU utilization during
|
* `file_id` - (Optional) The file ID for a disk image (experimental - might cause high CPU utilization during
|
||||||
import, especially with large disk images).
|
import, especially with large disk images).
|
||||||
* `interface` - (Required) The disk interface for Proxmox, currently scsi, sata and virtio are supported.
|
* `interface` - (Required) The disk interface for Proxmox, currently scsi, sata and virtio are supported.
|
||||||
|
* `iothread` - (Optional) Whether to use iothreads for this disk (defaults to `false`).
|
||||||
* `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.
|
||||||
* `read` - (Optional) The maximum read speed in megabytes per second.
|
* `read` - (Optional) The maximum read speed in megabytes per second.
|
||||||
* `read_burstable` - (Optional) The maximum burstable read speed in megabytes per second.
|
* `read_burstable` - (Optional) The maximum burstable read speed in megabytes per second.
|
||||||
* `write` - (Optional) The maximum write speed in megabytes per second.
|
* `write` - (Optional) The maximum write speed in megabytes per second.
|
||||||
* `write_burstable` - (Optional) The maximum burstable write speed in megabytes per second.
|
* `write_burstable` - (Optional) The maximum burstable write speed in megabytes per second.
|
||||||
* `iothread` - (Optional) Whether to use iothreads for this disk (defaults to `false`).
|
* ssd - (Optional) Whether to use an SSD emulation option for this disk (defaults to `false`). Note that SSD emulation is not supported on VirtIO Block drives.
|
||||||
* `discard` - (Optional) Whether to pass discard/trim requests to the underlying storage. Supported values are `on`/`ignore` (defaults to `ignore`)
|
|
||||||
* `initialization` - (Optional) The cloud-init configuration.
|
* `initialization` - (Optional) The cloud-init configuration.
|
||||||
* `datastore_id` - (Optional) The identifier for the datastore to create the cloud-init disk in (defaults
|
* `datastore_id` - (Optional) The identifier for the datastore to create the cloud-init disk in (defaults
|
||||||
to `local-lvm`).
|
to `local-lvm`).
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
locals {
|
||||||
|
datastore_id = element(data.proxmox_virtual_environment_datastores.example.datastore_ids, index(data.proxmox_virtual_environment_datastores.example.datastore_ids, "local-lvm"))
|
||||||
|
}
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_vm" "example_template" {
|
resource "proxmox_virtual_environment_vm" "example_template" {
|
||||||
agent {
|
agent {
|
||||||
enabled = true
|
enabled = true
|
||||||
@ -5,14 +9,21 @@ resource "proxmox_virtual_environment_vm" "example_template" {
|
|||||||
|
|
||||||
description = "Managed by Terraform"
|
description = "Managed by Terraform"
|
||||||
|
|
||||||
disk {
|
# disk {
|
||||||
datastore_id = element(data.proxmox_virtual_environment_datastores.example.datastore_ids, index(data.proxmox_virtual_environment_datastores.example.datastore_ids, "local-lvm"))
|
# datastore_id = local.datastore_id
|
||||||
file_id = proxmox_virtual_environment_file.ubuntu_cloud_image.id
|
# file_id = proxmox_virtual_environment_file.ubuntu_cloud_image.id
|
||||||
interface = "virtio0"
|
# interface = "virtio0"
|
||||||
discard = "on"
|
# iothread = true
|
||||||
iothread = true
|
# }
|
||||||
}
|
|
||||||
|
|
||||||
|
disk {
|
||||||
|
datastore_id = local.datastore_id
|
||||||
|
file_id = proxmox_virtual_environment_file.ubuntu_cloud_image.id
|
||||||
|
interface = "scsi0"
|
||||||
|
discard = "on"
|
||||||
|
ssd = true
|
||||||
|
}
|
||||||
|
#
|
||||||
# disk {
|
# disk {
|
||||||
# datastore_id = "nfs"
|
# datastore_id = "nfs"
|
||||||
# interface = "scsi1"
|
# interface = "scsi1"
|
||||||
@ -21,7 +32,7 @@ resource "proxmox_virtual_environment_vm" "example_template" {
|
|||||||
# }
|
# }
|
||||||
|
|
||||||
initialization {
|
initialization {
|
||||||
datastore_id = element(data.proxmox_virtual_environment_datastores.example.datastore_ids, index(data.proxmox_virtual_environment_datastores.example.datastore_ids, "local-lvm"))
|
datastore_id = local.datastore_id
|
||||||
|
|
||||||
dns {
|
dns {
|
||||||
server = "1.1.1.1"
|
server = "1.1.1.1"
|
||||||
|
@ -163,6 +163,7 @@ type CustomStorageDevice struct {
|
|||||||
FileVolume string `json:"file" url:"file"`
|
FileVolume string `json:"file" url:"file"`
|
||||||
Format *string `json:"format,omitempty" url:"format,omitempty"`
|
Format *string `json:"format,omitempty" url:"format,omitempty"`
|
||||||
IOThread *CustomBool `json:"iothread,omitempty" url:"iothread,omitempty,int"`
|
IOThread *CustomBool `json:"iothread,omitempty" url:"iothread,omitempty,int"`
|
||||||
|
SSD *CustomBool `json:"ssd,omitempty" url:"ssd,omitempty,int"`
|
||||||
MaxReadSpeedMbps *int `json:"mbps_rd,omitempty" url:"mbps_rd,omitempty"`
|
MaxReadSpeedMbps *int `json:"mbps_rd,omitempty" url:"mbps_rd,omitempty"`
|
||||||
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"`
|
||||||
@ -1088,6 +1089,14 @@ func (r CustomStorageDevice) EncodeValues(key string, v *url.Values) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.SSD != nil {
|
||||||
|
if *r.SSD {
|
||||||
|
values = append(values, "ssd=1")
|
||||||
|
} else {
|
||||||
|
values = append(values, "ssd=0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if r.Discard != nil && *r.Discard != "" {
|
if r.Discard != nil && *r.Discard != "" {
|
||||||
values = append(values, fmt.Sprintf("discard=%s", *r.Discard))
|
values = append(values, fmt.Sprintf("discard=%s", *r.Discard))
|
||||||
}
|
}
|
||||||
@ -1451,8 +1460,8 @@ func (r *CustomNetworkDevice) UnmarshalJSON(b []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r.RateLimit = &fv
|
r.RateLimit = &fv
|
||||||
|
|
||||||
case "tag":
|
case "tag":
|
||||||
iv, err := strconv.Atoi(v[1])
|
iv, err := strconv.Atoi(v[1])
|
||||||
|
|
||||||
@ -1631,6 +1640,9 @@ func (r *CustomStorageDevice) UnmarshalJSON(b []byte) error {
|
|||||||
case "iothread":
|
case "iothread":
|
||||||
bv := CustomBool(v[1] == "1")
|
bv := CustomBool(v[1] == "1")
|
||||||
r.IOThread = &bv
|
r.IOThread = &bv
|
||||||
|
case "ssd":
|
||||||
|
bv := CustomBool(v[1] == "1")
|
||||||
|
r.SSD = &bv
|
||||||
case "discard":
|
case "discard":
|
||||||
r.Discard = &v[1]
|
r.Discard = &v[1]
|
||||||
}
|
}
|
||||||
|
@ -14,18 +14,19 @@ func TestCustomStorageDevice_UnmarshalJSON(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "simple volume",
|
name: "simple volume",
|
||||||
line: `"local-lvm:vm-2041-disk-0,discard=on,iothread=1,size=8G"`,
|
line: `"local-lvm:vm-2041-disk-0,discard=on,ssd=1,iothread=1,size=8G"`,
|
||||||
want: &CustomStorageDevice{
|
want: &CustomStorageDevice{
|
||||||
Discard: strPtr("on"),
|
Discard: strPtr("on"),
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
FileVolume: "local-lvm:vm-2041-disk-0",
|
FileVolume: "local-lvm:vm-2041-disk-0",
|
||||||
IOThread: boolPtr(true),
|
IOThread: boolPtr(true),
|
||||||
Size: strPtr("8G"),
|
Size: strPtr("8G"),
|
||||||
|
SSD: boolPtr(true),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "raw volume type",
|
name: "raw volume type",
|
||||||
line: `"nfs:2041/vm-2041-disk-0.raw,discard=ignore,iothread=1,size=8G"`,
|
line: `"nfs:2041/vm-2041-disk-0.raw,discard=ignore,ssd=1,iothread=1,size=8G"`,
|
||||||
want: &CustomStorageDevice{
|
want: &CustomStorageDevice{
|
||||||
Discard: strPtr("ignore"),
|
Discard: strPtr("ignore"),
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
@ -33,6 +34,7 @@ func TestCustomStorageDevice_UnmarshalJSON(t *testing.T) {
|
|||||||
Format: strPtr("raw"),
|
Format: strPtr("raw"),
|
||||||
IOThread: boolPtr(true),
|
IOThread: boolPtr(true),
|
||||||
Size: strPtr("8G"),
|
Size: strPtr("8G"),
|
||||||
|
SSD: boolPtr(true),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ const (
|
|||||||
dvResourceVirtualEnvironmentVMDiskFileID = ""
|
dvResourceVirtualEnvironmentVMDiskFileID = ""
|
||||||
dvResourceVirtualEnvironmentVMDiskSize = 8
|
dvResourceVirtualEnvironmentVMDiskSize = 8
|
||||||
dvResourceVirtualEnvironmentVMDiskIOThread = false
|
dvResourceVirtualEnvironmentVMDiskIOThread = false
|
||||||
|
dvResourceVirtualEnvironmentVMDiskSSD = false
|
||||||
dvResourceVirtualEnvironmentVMDiskDiscard = ""
|
dvResourceVirtualEnvironmentVMDiskDiscard = ""
|
||||||
dvResourceVirtualEnvironmentVMDiskSpeedRead = 0
|
dvResourceVirtualEnvironmentVMDiskSpeedRead = 0
|
||||||
dvResourceVirtualEnvironmentVMDiskSpeedReadBurstable = 0
|
dvResourceVirtualEnvironmentVMDiskSpeedReadBurstable = 0
|
||||||
@ -138,6 +139,7 @@ const (
|
|||||||
mkResourceVirtualEnvironmentVMDiskFileID = "file_id"
|
mkResourceVirtualEnvironmentVMDiskFileID = "file_id"
|
||||||
mkResourceVirtualEnvironmentVMDiskSize = "size"
|
mkResourceVirtualEnvironmentVMDiskSize = "size"
|
||||||
mkResourceVirtualEnvironmentVMDiskIOThread = "iothread"
|
mkResourceVirtualEnvironmentVMDiskIOThread = "iothread"
|
||||||
|
mkResourceVirtualEnvironmentVMDiskSSD = "ssd"
|
||||||
mkResourceVirtualEnvironmentVMDiskDiscard = "discard"
|
mkResourceVirtualEnvironmentVMDiskDiscard = "discard"
|
||||||
mkResourceVirtualEnvironmentVMDiskSpeed = "speed"
|
mkResourceVirtualEnvironmentVMDiskSpeed = "speed"
|
||||||
mkResourceVirtualEnvironmentVMDiskSpeedRead = "read"
|
mkResourceVirtualEnvironmentVMDiskSpeedRead = "read"
|
||||||
@ -488,6 +490,7 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
|
|||||||
mkResourceVirtualEnvironmentVMDiskInterface: dvResourceVirtualEnvironmentVMDiskInterface,
|
mkResourceVirtualEnvironmentVMDiskInterface: dvResourceVirtualEnvironmentVMDiskInterface,
|
||||||
mkResourceVirtualEnvironmentVMDiskSize: dvResourceVirtualEnvironmentVMDiskSize,
|
mkResourceVirtualEnvironmentVMDiskSize: dvResourceVirtualEnvironmentVMDiskSize,
|
||||||
mkResourceVirtualEnvironmentVMDiskIOThread: dvResourceVirtualEnvironmentVMDiskIOThread,
|
mkResourceVirtualEnvironmentVMDiskIOThread: dvResourceVirtualEnvironmentVMDiskIOThread,
|
||||||
|
mkResourceVirtualEnvironmentVMDiskSSD: dvResourceVirtualEnvironmentVMDiskSSD,
|
||||||
mkResourceVirtualEnvironmentVMDiskDiscard: dvResourceVirtualEnvironmentVMDiskDiscard,
|
mkResourceVirtualEnvironmentVMDiskDiscard: dvResourceVirtualEnvironmentVMDiskDiscard,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
@ -534,6 +537,12 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
|
|||||||
Optional: true,
|
Optional: true,
|
||||||
Default: dvResourceVirtualEnvironmentVMDiskIOThread,
|
Default: dvResourceVirtualEnvironmentVMDiskIOThread,
|
||||||
},
|
},
|
||||||
|
mkResourceVirtualEnvironmentVMDiskSSD: {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Description: "Whether to use ssd for this disk drive",
|
||||||
|
Optional: true,
|
||||||
|
Default: dvResourceVirtualEnvironmentVMDiskSSD,
|
||||||
|
},
|
||||||
mkResourceVirtualEnvironmentVMDiskDiscard: {
|
mkResourceVirtualEnvironmentVMDiskDiscard: {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "Whether to pass discard/trim requests to the underlying storage.",
|
Description: "Whether to pass discard/trim requests to the underlying storage.",
|
||||||
@ -1913,6 +1922,7 @@ func resourceVirtualEnvironmentVMCreateCustomDisks(ctx context.Context, d *schem
|
|||||||
speed := block[mkResourceVirtualEnvironmentVMDiskSpeed].([]interface{})
|
speed := block[mkResourceVirtualEnvironmentVMDiskSpeed].([]interface{})
|
||||||
diskInterface, _ := block[mkResourceVirtualEnvironmentVMDiskInterface].(string)
|
diskInterface, _ := block[mkResourceVirtualEnvironmentVMDiskInterface].(string)
|
||||||
ioThread := proxmox.CustomBool(block[mkResourceVirtualEnvironmentVMDiskIOThread].(bool))
|
ioThread := proxmox.CustomBool(block[mkResourceVirtualEnvironmentVMDiskIOThread].(bool))
|
||||||
|
ssd := proxmox.CustomBool(block[mkResourceVirtualEnvironmentVMDiskSSD].(bool))
|
||||||
discard, _ := block[mkResourceVirtualEnvironmentVMDiskDiscard].(string)
|
discard, _ := block[mkResourceVirtualEnvironmentVMDiskDiscard].(string)
|
||||||
|
|
||||||
if len(speed) == 0 {
|
if len(speed) == 0 {
|
||||||
@ -1935,6 +1945,10 @@ func resourceVirtualEnvironmentVMCreateCustomDisks(ctx context.Context, d *schem
|
|||||||
diskOptions += ",iothread=1"
|
diskOptions += ",iothread=1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ssd {
|
||||||
|
diskOptions += ",ssd=1"
|
||||||
|
}
|
||||||
|
|
||||||
if discard != "" {
|
if discard != "" {
|
||||||
diskOptions += fmt.Sprintf(",discard=%s", discard)
|
diskOptions += fmt.Sprintf(",discard=%s", discard)
|
||||||
}
|
}
|
||||||
@ -2232,6 +2246,7 @@ func resourceVirtualEnvironmentVMGetDiskDeviceObjects(d *schema.ResourceData, di
|
|||||||
size, _ := block[mkResourceVirtualEnvironmentVMDiskSize].(int)
|
size, _ := block[mkResourceVirtualEnvironmentVMDiskSize].(int)
|
||||||
diskInterface, _ := block[mkResourceVirtualEnvironmentVMDiskInterface].(string)
|
diskInterface, _ := block[mkResourceVirtualEnvironmentVMDiskInterface].(string)
|
||||||
ioThread := proxmox.CustomBool(block[mkResourceVirtualEnvironmentVMDiskIOThread].(bool))
|
ioThread := proxmox.CustomBool(block[mkResourceVirtualEnvironmentVMDiskIOThread].(bool))
|
||||||
|
ssd := proxmox.CustomBool(block[mkResourceVirtualEnvironmentVMDiskSSD].(bool))
|
||||||
discard := block[mkResourceVirtualEnvironmentVMDiskDiscard].(string)
|
discard := block[mkResourceVirtualEnvironmentVMDiskDiscard].(string)
|
||||||
|
|
||||||
speedBlock, err := getSchemaBlock(resource, d, []string{mkResourceVirtualEnvironmentVMDisk, mkResourceVirtualEnvironmentVMDiskSpeed}, 0, false)
|
speedBlock, err := getSchemaBlock(resource, d, []string{mkResourceVirtualEnvironmentVMDisk, mkResourceVirtualEnvironmentVMDiskSpeed}, 0, false)
|
||||||
@ -2253,6 +2268,7 @@ func resourceVirtualEnvironmentVMGetDiskDeviceObjects(d *schema.ResourceData, di
|
|||||||
diskDevice.Size = &sizeString
|
diskDevice.Size = &sizeString
|
||||||
diskDevice.SizeInt = &size
|
diskDevice.SizeInt = &size
|
||||||
diskDevice.IOThread = &ioThread
|
diskDevice.IOThread = &ioThread
|
||||||
|
diskDevice.SSD = &ssd
|
||||||
diskDevice.Discard = &discard
|
diskDevice.Discard = &discard
|
||||||
|
|
||||||
if len(speedBlock) > 0 {
|
if len(speedBlock) > 0 {
|
||||||
@ -2774,6 +2790,12 @@ func resourceVirtualEnvironmentVMReadCustom(ctx context.Context, d *schema.Resou
|
|||||||
disk[mkResourceVirtualEnvironmentVMDiskIOThread] = false
|
disk[mkResourceVirtualEnvironmentVMDiskIOThread] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dd.SSD != nil {
|
||||||
|
disk[mkResourceVirtualEnvironmentVMDiskSSD] = *dd.SSD
|
||||||
|
} else {
|
||||||
|
disk[mkResourceVirtualEnvironmentVMDiskSSD] = false
|
||||||
|
}
|
||||||
|
|
||||||
if dd.Discard != nil {
|
if dd.Discard != nil {
|
||||||
disk[mkResourceVirtualEnvironmentVMDiskDiscard] = *dd.Discard
|
disk[mkResourceVirtualEnvironmentVMDiskDiscard] = *dd.Discard
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user