mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-26 05:15:39 +00:00
fix(lxc): root fs creation for storage-backed mp
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
009db038b4
commit
93f6b3ed0e
@ -111,6 +111,7 @@ func TestAccResourceContainer(t *testing.T) {
|
|||||||
"device_passthrough.0.mode": "0660",
|
"device_passthrough.0.mode": "0660",
|
||||||
"initialization.0.dns.#": "0",
|
"initialization.0.dns.#": "0",
|
||||||
}),
|
}),
|
||||||
|
// TODO: depends on DHCP, which may not work in some environments
|
||||||
// ResourceAttributesSet(accTestContainerName, []string{
|
// ResourceAttributesSet(accTestContainerName, []string{
|
||||||
// "ipv4.vmbr0",
|
// "ipv4.vmbr0",
|
||||||
// }),
|
// }),
|
||||||
|
@ -52,10 +52,10 @@ const (
|
|||||||
dvCPUUnits = 1024
|
dvCPUUnits = 1024
|
||||||
dvDescription = ""
|
dvDescription = ""
|
||||||
dvDevicePassthroughMode = "0660"
|
dvDevicePassthroughMode = "0660"
|
||||||
dvDiskACL = false
|
dvDiskACL = false
|
||||||
dvDiskDatastoreID = "local"
|
dvDiskDatastoreID = "local"
|
||||||
dvDiskQuota = false
|
dvDiskQuota = false
|
||||||
dvDiskReplicate = true
|
dvDiskReplicate = false
|
||||||
dvDiskSize = 4
|
dvDiskSize = 4
|
||||||
dvFeaturesNesting = false
|
dvFeaturesNesting = false
|
||||||
dvFeaturesKeyControl = false
|
dvFeaturesKeyControl = false
|
||||||
@ -110,7 +110,7 @@ const (
|
|||||||
mkCPUUnits = "units"
|
mkCPUUnits = "units"
|
||||||
mkDescription = "description"
|
mkDescription = "description"
|
||||||
mkDisk = "disk"
|
mkDisk = "disk"
|
||||||
mkDiskACL = "acl"
|
mkDiskACL = "acl"
|
||||||
mkDiskDatastoreID = "datastore_id"
|
mkDiskDatastoreID = "datastore_id"
|
||||||
mkDiskMountOptions = "mount_options"
|
mkDiskMountOptions = "mount_options"
|
||||||
mkDiskQuota = "quota"
|
mkDiskQuota = "quota"
|
||||||
@ -1511,6 +1511,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeName := d.Get(mkNodeName).(string)
|
nodeName := d.Get(mkNodeName).(string)
|
||||||
container := Container()
|
container := Container()
|
||||||
|
|
||||||
@ -1762,7 +1763,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
|
|
||||||
var rootFS *containers.CustomRootFS
|
var rootFS *containers.CustomRootFS
|
||||||
|
|
||||||
var diskMountOptions = []string{}
|
diskMountOptions := []string{}
|
||||||
|
|
||||||
if diskBlock[mkDiskMountOptions] != nil {
|
if diskBlock[mkDiskMountOptions] != nil {
|
||||||
for _, opt := range diskBlock[mkDiskMountOptions].([]any) {
|
for _, opt := range diskBlock[mkDiskMountOptions].([]any) {
|
||||||
@ -1774,11 +1775,8 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
if diskDatastoreID != "" && (diskSize != dvDiskSize || len(mountPoints) > 0) {
|
if diskDatastoreID != "" && (diskSize != dvDiskSize || len(mountPoints) > 0) {
|
||||||
// This is a special case where the rootfs size is set to a non-default value at creation time.
|
// This is a special case where the rootfs size is set to a non-default value at creation time.
|
||||||
// see https://pve.proxmox.com/pve-docs/chapter-pct.html#_storage_backed_mount_points
|
// see https://pve.proxmox.com/pve-docs/chapter-pct.html#_storage_backed_mount_points
|
||||||
|
|
||||||
// rootfs ID is always 0
|
|
||||||
diskID := 0
|
|
||||||
rootFS = &containers.CustomRootFS{
|
rootFS = &containers.CustomRootFS{
|
||||||
Volume: fmt.Sprintf("%s:%d", getContainerDiskVolume(diskDatastoreID, vmID, diskID) , diskSize),
|
Volume: fmt.Sprintf("%s:%d", diskDatastoreID, diskSize),
|
||||||
MountOptions: &diskMountOptions,
|
MountOptions: &diskMountOptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2988,13 +2986,13 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootFS := &containers.CustomRootFS{}
|
rootFS := &containers.CustomRootFS{}
|
||||||
// Disk ID for the rootfs is always 0
|
// Disk ID for the rootfs is always 0
|
||||||
diskID := 0
|
diskID := 0
|
||||||
vmID := d.Get(mkVMID).(int)
|
vmID := d.Get(mkVMID).(int)
|
||||||
rootFS.Volume = diskBlock[mkDiskDatastoreID].(string)
|
rootFS.Volume = diskBlock[mkDiskDatastoreID].(string)
|
||||||
rootFS.Volume = getContainerDiskVolume(rootFS.Volume, vmID, diskID)
|
rootFS.Volume = getContainerDiskVolume(rootFS.Volume, vmID, diskID)
|
||||||
|
|
||||||
|
|
||||||
acl := types.CustomBool(diskBlock[mkDiskACL].(bool))
|
acl := types.CustomBool(diskBlock[mkDiskACL].(bool))
|
||||||
mountOptions := diskBlock[mkDiskMountOptions].([]interface{})
|
mountOptions := diskBlock[mkDiskMountOptions].([]interface{})
|
||||||
@ -3002,11 +3000,10 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
replicate := types.CustomBool(diskBlock[mkDiskReplicate].(bool))
|
replicate := types.CustomBool(diskBlock[mkDiskReplicate].(bool))
|
||||||
size := types.DiskSizeFromGigabytes(int64(diskBlock[mkDiskSize].(int)))
|
size := types.DiskSizeFromGigabytes(int64(diskBlock[mkDiskSize].(int)))
|
||||||
|
|
||||||
|
|
||||||
rootFS.ACL = &acl
|
rootFS.ACL = &acl
|
||||||
rootFS.Quota = "a
|
rootFS.Quota = "a
|
||||||
rootFS.Replicate = &replicate
|
rootFS.Replicate = &replicate
|
||||||
rootFS.Size = size
|
rootFS.Size = size
|
||||||
|
|
||||||
if len(mountOptions) > 0 {
|
if len(mountOptions) > 0 {
|
||||||
mountOptionsArray := make([]string, 0, len(mountOptions))
|
mountOptionsArray := make([]string, 0, len(mountOptions))
|
||||||
@ -3014,6 +3011,7 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
for _, option := range mountOptions {
|
for _, option := range mountOptions {
|
||||||
mountOptionsArray = append(mountOptionsArray, option.(string))
|
mountOptionsArray = append(mountOptionsArray, option.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
rootFS.MountOptions = &mountOptionsArray
|
rootFS.MountOptions = &mountOptionsArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user