Skip to content

Commit

Permalink
feat: add full support for custom cloud-init disks
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Mar 26, 2024
1 parent 016fe49 commit 5486b49
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 110 deletions.
14 changes: 13 additions & 1 deletion proxmoxtf/resource/vm/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

// GetInfo returns the disk information for a VM.
func GetInfo(resp *vms.GetResponseData, d *schema.ResourceData) vms.CustomStorageDevices {
func GetInfo(resp *vms.GetResponseData, d *schema.ResourceData, vmID int) vms.CustomStorageDevices {
currentDisk := d.Get(MkDisk)

currentDiskList := currentDisk.([]interface{})
Expand Down Expand Up @@ -82,6 +82,8 @@ func GetInfo(resp *vms.GetResponseData, d *schema.ResourceData) vms.CustomStorag
storageDevices["virtio14"] = resp.VirtualIODevice14
storageDevices["virtio15"] = resp.VirtualIODevice15

cloudInitDiskName := fmt.Sprintf("vm-%d-cloudinit", vmID)

for k, v := range storageDevices {
if v != nil {
if currentDiskMap[k] != nil {
Expand All @@ -98,6 +100,10 @@ func GetInfo(resp *vms.GetResponseData, d *schema.ResourceData) vms.CustomStorag
// defensive copy of the loop variable
iface := k
v.Interface = &iface

if strings.Contains(v.FileVolume, cloudInitDiskName) {
storageDevices["cloudinit"] = v
}
}
}

Expand Down Expand Up @@ -591,13 +597,19 @@ func Read(
currentDiskList := d.Get(MkDisk).([]interface{})
diskMap := map[string]interface{}{}

cloudInitDisk := diskObjects["cloudinit"]

var diags diag.Diagnostics

for di, dd := range diskObjects {
if dd == nil || dd.FileVolume == "none" || strings.HasPrefix(di, "ide") {
continue
}

if cloudInitDisk != nil && cloudInitDisk.FileVolume == dd.FileVolume {
continue
}

if dd.IsCloudInitDrive(vmID) {
continue
}
Expand Down
Loading

0 comments on commit 5486b49

Please sign in to comment.