diff --git a/proxmox/Internal/resource/guest/qemu/disk/terraform.go b/proxmox/Internal/resource/guest/qemu/disk/terraform.go index 76195371..9a136533 100644 --- a/proxmox/Internal/resource/guest/qemu/disk/terraform.go +++ b/proxmox/Internal/resource/guest/qemu/disk/terraform.go @@ -5,11 +5,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func Terraform(d *schema.ResourceData, config pveAPI.QemuStorages) { +// Requires the caller to check for nil +func Terraform_Unsafe(d *schema.ResourceData, config *pveAPI.QemuStorages, ciDisk *bool) { if _, ok := d.GetOk(RootDisk); ok { - d.Set(RootDisk, terraform_Disk_QemuDisks(config)) + d.Set(RootDisk, terraform_Disk_QemuDisks(*config, ciDisk)) } else { - d.Set(RootDisks, terraform_Disks_QemuDisks(config)) + d.Set(RootDisks, terraform_Disks_QemuDisks(*config, ciDisk)) } } diff --git a/proxmox/Internal/resource/guest/qemu/disk/terraform_disk.go b/proxmox/Internal/resource/guest/qemu/disk/terraform_disk.go index 11484130..34788b49 100644 --- a/proxmox/Internal/resource/guest/qemu/disk/terraform_disk.go +++ b/proxmox/Internal/resource/guest/qemu/disk/terraform_disk.go @@ -19,15 +19,15 @@ func terraform_Disk_QemuCloudInit_unsafe(config *pveAPI.QemuCloudInitDisk) map[s schemaType: schemaCloudInit} } -func terraform_Disk_QemuDisks(config pveAPI.QemuStorages) []map[string]interface{} { +func terraform_Disk_QemuDisks(config pveAPI.QemuStorages, ciDisk *bool) []map[string]interface{} { disks := make([]map[string]interface{}, 0, 56) // max is sum of underlying arrays - if ideDisks := terraform_Disk_QemuIdeDisks(config.Ide); ideDisks != nil { + if ideDisks := terraform_Disk_QemuIdeDisks(config.Ide, ciDisk); ideDisks != nil { disks = append(disks, ideDisks...) } - if sataDisks := terraform_Disk_QemuSataDisks(config.Sata); sataDisks != nil { + if sataDisks := terraform_Disk_QemuSataDisks(config.Sata, ciDisk); sataDisks != nil { disks = append(disks, sataDisks...) } - if scsiDisks := terraform_Disk_QemuScsiDisks(config.Scsi); scsiDisks != nil { + if scsiDisks := terraform_Disk_QemuScsiDisks(config.Scsi, ciDisk); scsiDisks != nil { disks = append(disks, scsiDisks...) } if virtioDisks := terraform_Disk_QemuVirtIODisks(config.VirtIO); virtioDisks != nil { @@ -39,18 +39,18 @@ func terraform_Disk_QemuDisks(config pveAPI.QemuStorages) []map[string]interface return disks } -func terraform_Disk_QemuIdeDisks(config *pveAPI.QemuIdeDisks) []map[string]interface{} { +func terraform_Disk_QemuIdeDisks(config *pveAPI.QemuIdeDisks, ciDisk *bool) []map[string]interface{} { if config == nil { return nil } disks := make([]map[string]interface{}, 0, 3) - if disk := terraform_Disk_QemuIdeStorage(config.Disk_0, schemaIDE+"0"); disk != nil { + if disk := terraform_Disk_QemuIdeStorage(config.Disk_0, schemaIDE+"0", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuIdeStorage(config.Disk_1, schemaIDE+"1"); disk != nil { + if disk := terraform_Disk_QemuIdeStorage(config.Disk_1, schemaIDE+"1", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuIdeStorage(config.Disk_2, schemaIDE+"2"); disk != nil { + if disk := terraform_Disk_QemuIdeStorage(config.Disk_2, schemaIDE+"2", ciDisk); disk != nil { disks = append(disks, disk) } if len(disks) == 0 { @@ -59,7 +59,7 @@ func terraform_Disk_QemuIdeDisks(config *pveAPI.QemuIdeDisks) []map[string]inter return disks } -func terraform_Disk_QemuIdeStorage(config *pveAPI.QemuIdeStorage, slot string) (settings map[string]interface{}) { +func terraform_Disk_QemuIdeStorage(config *pveAPI.QemuIdeStorage, slot string, ciDisk *bool) (settings map[string]interface{}) { if config == nil { return nil } @@ -101,33 +101,34 @@ func terraform_Disk_QemuIdeStorage(config *pveAPI.QemuIdeStorage, slot string) ( settings = terraform_Disk_QemuCdRom_unsafe(config.CdRom) } if config.CloudInit != nil { + *ciDisk = true settings = terraform_Disk_QemuCloudInit_unsafe(config.CloudInit) } settings[schemaSlot] = slot return settings } -func terraform_Disk_QemuSataDisks(config *pveAPI.QemuSataDisks) []map[string]interface{} { +func terraform_Disk_QemuSataDisks(config *pveAPI.QemuSataDisks, ciDisk *bool) []map[string]interface{} { if config == nil { return nil } disks := make([]map[string]interface{}, 0, 6) - if disk := terraform_Disk_QemuSataStorage(config.Disk_0, schemaSata+"0"); disk != nil { + if disk := terraform_Disk_QemuSataStorage(config.Disk_0, schemaSata+"0", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuSataStorage(config.Disk_1, schemaSata+"1"); disk != nil { + if disk := terraform_Disk_QemuSataStorage(config.Disk_1, schemaSata+"1", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuSataStorage(config.Disk_2, schemaSata+"2"); disk != nil { + if disk := terraform_Disk_QemuSataStorage(config.Disk_2, schemaSata+"2", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuSataStorage(config.Disk_2, schemaSata+"3"); disk != nil { + if disk := terraform_Disk_QemuSataStorage(config.Disk_2, schemaSata+"3", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuSataStorage(config.Disk_2, schemaSata+"4"); disk != nil { + if disk := terraform_Disk_QemuSataStorage(config.Disk_2, schemaSata+"4", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuSataStorage(config.Disk_2, schemaSata+"5"); disk != nil { + if disk := terraform_Disk_QemuSataStorage(config.Disk_2, schemaSata+"5", ciDisk); disk != nil { disks = append(disks, disk) } if len(disks) == 0 { @@ -136,7 +137,7 @@ func terraform_Disk_QemuSataDisks(config *pveAPI.QemuSataDisks) []map[string]int return disks } -func terraform_Disk_QemuSataStorage(config *pveAPI.QemuSataStorage, slot string) (settings map[string]interface{}) { +func terraform_Disk_QemuSataStorage(config *pveAPI.QemuSataStorage, slot string, ciDisk *bool) (settings map[string]interface{}) { if config == nil { return nil } @@ -178,108 +179,109 @@ func terraform_Disk_QemuSataStorage(config *pveAPI.QemuSataStorage, slot string) settings = terraform_Disk_QemuCdRom_unsafe(config.CdRom) } if config.CloudInit != nil { + *ciDisk = true settings = terraform_Disk_QemuCloudInit_unsafe(config.CloudInit) } settings[schemaSlot] = slot return settings } -func terraform_Disk_QemuScsiDisks(config *pveAPI.QemuScsiDisks) []map[string]interface{} { +func terraform_Disk_QemuScsiDisks(config *pveAPI.QemuScsiDisks, ciDisk *bool) []map[string]interface{} { if config == nil { return nil } disks := make([]map[string]interface{}, 0, 31) - if disk := terraform_Disk_QemuScsiStorage(config.Disk_0, schemaScsi+"0"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_0, schemaScsi+"0", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_1, schemaScsi+"1"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_1, schemaScsi+"1", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_2, schemaScsi+"2"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_2, schemaScsi+"2", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_3, schemaScsi+"3"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_3, schemaScsi+"3", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_4, schemaScsi+"4"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_4, schemaScsi+"4", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_5, schemaScsi+"5"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_5, schemaScsi+"5", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_6, schemaScsi+"6"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_6, schemaScsi+"6", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_7, schemaScsi+"7"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_7, schemaScsi+"7", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_8, schemaScsi+"8"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_8, schemaScsi+"8", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_9, schemaScsi+"9"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_9, schemaScsi+"9", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_10, schemaScsi+"10"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_10, schemaScsi+"10", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_11, schemaScsi+"11"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_11, schemaScsi+"11", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_12, schemaScsi+"12"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_12, schemaScsi+"12", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_13, schemaScsi+"13"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_13, schemaScsi+"13", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_14, schemaScsi+"14"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_14, schemaScsi+"14", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_15, schemaScsi+"15"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_15, schemaScsi+"15", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_16, schemaScsi+"16"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_16, schemaScsi+"16", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_17, schemaScsi+"17"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_17, schemaScsi+"17", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_18, schemaScsi+"18"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_18, schemaScsi+"18", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_19, schemaScsi+"19"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_19, schemaScsi+"19", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_20, schemaScsi+"20"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_20, schemaScsi+"20", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_21, schemaScsi+"21"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_21, schemaScsi+"21", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_22, schemaScsi+"22"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_22, schemaScsi+"22", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_23, schemaScsi+"23"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_23, schemaScsi+"23", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_24, schemaScsi+"24"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_24, schemaScsi+"24", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_25, schemaScsi+"25"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_25, schemaScsi+"25", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_26, schemaScsi+"26"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_26, schemaScsi+"26", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_27, schemaScsi+"27"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_27, schemaScsi+"27", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_28, schemaScsi+"28"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_28, schemaScsi+"28", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_29, schemaScsi+"29"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_29, schemaScsi+"29", ciDisk); disk != nil { disks = append(disks, disk) } - if disk := terraform_Disk_QemuScsiStorage(config.Disk_30, schemaScsi+"30"); disk != nil { + if disk := terraform_Disk_QemuScsiStorage(config.Disk_30, schemaScsi+"30", ciDisk); disk != nil { disks = append(disks, disk) } if len(disks) == 0 { @@ -288,7 +290,7 @@ func terraform_Disk_QemuScsiDisks(config *pveAPI.QemuScsiDisks) []map[string]int return disks } -func terraform_Disk_QemuScsiStorage(config *pveAPI.QemuScsiStorage, slot string) (settings map[string]interface{}) { +func terraform_Disk_QemuScsiStorage(config *pveAPI.QemuScsiStorage, slot string, ciDisk *bool) (settings map[string]interface{}) { if config == nil { return nil } @@ -334,6 +336,7 @@ func terraform_Disk_QemuScsiStorage(config *pveAPI.QemuScsiStorage, slot string) settings = terraform_Disk_QemuCdRom_unsafe(config.CdRom) } if config.CloudInit != nil { + *ciDisk = true settings = terraform_Disk_QemuCloudInit_unsafe(config.CloudInit) } settings[schemaSlot] = slot diff --git a/proxmox/Internal/resource/guest/qemu/disk/terraform_disks.go b/proxmox/Internal/resource/guest/qemu/disk/terraform_disks.go index b7772063..589d8bd7 100644 --- a/proxmox/Internal/resource/guest/qemu/disk/terraform_disks.go +++ b/proxmox/Internal/resource/guest/qemu/disk/terraform_disks.go @@ -23,10 +23,10 @@ func terraform_Disks_QemuCloudInit_unsafe(config *pveAPI.QemuCloudInitDisk) []in schemaStorage: string(config.Storage)}}}} } -func terraform_Disks_QemuDisks(config pveAPI.QemuStorages) []interface{} { - ide := terraform_Disks_QemuIdeDisks(config.Ide) - sata := terraform_Disks_QemuSataDisks(config.Sata) - scsi := terraform_Disks_QemuScsiDisks(config.Scsi) +func terraform_Disks_QemuDisks(config pveAPI.QemuStorages, ciDisk *bool) []interface{} { + ide := terraform_Disks_QemuIdeDisks(config.Ide, ciDisk) + sata := terraform_Disks_QemuSataDisks(config.Sata, ciDisk) + scsi := terraform_Disks_QemuScsiDisks(config.Scsi, ciDisk) virtio := terraform_Disks_QemuVirtIODisks(config.VirtIO) if ide == nil && sata == nil && scsi == nil && virtio == nil { return nil @@ -38,18 +38,18 @@ func terraform_Disks_QemuDisks(config pveAPI.QemuStorages) []interface{} { schemaVirtIO: virtio}} } -func terraform_Disks_QemuIdeDisks(config *pveAPI.QemuIdeDisks) []interface{} { +func terraform_Disks_QemuIdeDisks(config *pveAPI.QemuIdeDisks, ciDisk *bool) []interface{} { if config == nil { return nil } return []interface{}{map[string]interface{}{ - schemaIDE + "0": terraform_Disks_QemuIdeStorage(config.Disk_0), - schemaIDE + "1": terraform_Disks_QemuIdeStorage(config.Disk_1), - schemaIDE + "2": terraform_Disks_QemuIdeStorage(config.Disk_2), - schemaIDE + "3": terraform_Disks_QemuIdeStorage(config.Disk_3)}} + schemaIDE + "0": terraform_Disks_QemuIdeStorage(config.Disk_0, ciDisk), + schemaIDE + "1": terraform_Disks_QemuIdeStorage(config.Disk_1, ciDisk), + schemaIDE + "2": terraform_Disks_QemuIdeStorage(config.Disk_2, ciDisk), + schemaIDE + "3": terraform_Disks_QemuIdeStorage(config.Disk_3, ciDisk)}} } -func terraform_Disks_QemuIdeStorage(config *pveAPI.QemuIdeStorage) []interface{} { +func terraform_Disks_QemuIdeStorage(config *pveAPI.QemuIdeStorage, ciDisk *bool) []interface{} { if config == nil { return nil } @@ -88,25 +88,26 @@ func terraform_Disks_QemuIdeStorage(config *pveAPI.QemuIdeStorage) []interface{} schemaPassthrough: []interface{}{mapParams}}} } if config.CloudInit != nil { + *ciDisk = true return terraform_Disks_QemuCloudInit_unsafe(config.CloudInit) } return terraform_Disks_QemuCdRom(config.CdRom) } -func terraform_Disks_QemuSataDisks(config *pveAPI.QemuSataDisks) []interface{} { +func terraform_Disks_QemuSataDisks(config *pveAPI.QemuSataDisks, ciDisk *bool) []interface{} { if config == nil { return nil } return []interface{}{map[string]interface{}{ - schemaSata + "0": terraform_Disks_QemuSataStorage(config.Disk_0), - schemaSata + "1": terraform_Disks_QemuSataStorage(config.Disk_1), - schemaSata + "2": terraform_Disks_QemuSataStorage(config.Disk_2), - schemaSata + "3": terraform_Disks_QemuSataStorage(config.Disk_3), - schemaSata + "4": terraform_Disks_QemuSataStorage(config.Disk_4), - schemaSata + "5": terraform_Disks_QemuSataStorage(config.Disk_5)}} + schemaSata + "0": terraform_Disks_QemuSataStorage(config.Disk_0, ciDisk), + schemaSata + "1": terraform_Disks_QemuSataStorage(config.Disk_1, ciDisk), + schemaSata + "2": terraform_Disks_QemuSataStorage(config.Disk_2, ciDisk), + schemaSata + "3": terraform_Disks_QemuSataStorage(config.Disk_3, ciDisk), + schemaSata + "4": terraform_Disks_QemuSataStorage(config.Disk_4, ciDisk), + schemaSata + "5": terraform_Disks_QemuSataStorage(config.Disk_5, ciDisk)}} } -func terraform_Disks_QemuSataStorage(config *pveAPI.QemuSataStorage) []interface{} { +func terraform_Disks_QemuSataStorage(config *pveAPI.QemuSataStorage, ciDisk *bool) []interface{} { if config == nil { return nil } @@ -145,50 +146,51 @@ func terraform_Disks_QemuSataStorage(config *pveAPI.QemuSataStorage) []interface schemaPassthrough: []interface{}{mapParams}}} } if config.CloudInit != nil { + *ciDisk = true return terraform_Disks_QemuCloudInit_unsafe(config.CloudInit) } return terraform_Disks_QemuCdRom(config.CdRom) } -func terraform_Disks_QemuScsiDisks(config *pveAPI.QemuScsiDisks) []interface{} { +func terraform_Disks_QemuScsiDisks(config *pveAPI.QemuScsiDisks, ciDisk *bool) []interface{} { if config == nil { return nil } return []interface{}{map[string]interface{}{ - schemaScsi + "0": terraform_Disks_QemuScsiStorage(config.Disk_0), - schemaScsi + "1": terraform_Disks_QemuScsiStorage(config.Disk_1), - schemaScsi + "2": terraform_Disks_QemuScsiStorage(config.Disk_2), - schemaScsi + "3": terraform_Disks_QemuScsiStorage(config.Disk_3), - schemaScsi + "4": terraform_Disks_QemuScsiStorage(config.Disk_4), - schemaScsi + "5": terraform_Disks_QemuScsiStorage(config.Disk_5), - schemaScsi + "6": terraform_Disks_QemuScsiStorage(config.Disk_6), - schemaScsi + "7": terraform_Disks_QemuScsiStorage(config.Disk_7), - schemaScsi + "8": terraform_Disks_QemuScsiStorage(config.Disk_8), - schemaScsi + "9": terraform_Disks_QemuScsiStorage(config.Disk_9), - schemaScsi + "10": terraform_Disks_QemuScsiStorage(config.Disk_10), - schemaScsi + "11": terraform_Disks_QemuScsiStorage(config.Disk_11), - schemaScsi + "12": terraform_Disks_QemuScsiStorage(config.Disk_12), - schemaScsi + "13": terraform_Disks_QemuScsiStorage(config.Disk_13), - schemaScsi + "14": terraform_Disks_QemuScsiStorage(config.Disk_14), - schemaScsi + "15": terraform_Disks_QemuScsiStorage(config.Disk_15), - schemaScsi + "16": terraform_Disks_QemuScsiStorage(config.Disk_16), - schemaScsi + "17": terraform_Disks_QemuScsiStorage(config.Disk_17), - schemaScsi + "18": terraform_Disks_QemuScsiStorage(config.Disk_18), - schemaScsi + "19": terraform_Disks_QemuScsiStorage(config.Disk_19), - schemaScsi + "20": terraform_Disks_QemuScsiStorage(config.Disk_20), - schemaScsi + "21": terraform_Disks_QemuScsiStorage(config.Disk_21), - schemaScsi + "22": terraform_Disks_QemuScsiStorage(config.Disk_22), - schemaScsi + "23": terraform_Disks_QemuScsiStorage(config.Disk_23), - schemaScsi + "24": terraform_Disks_QemuScsiStorage(config.Disk_24), - schemaScsi + "25": terraform_Disks_QemuScsiStorage(config.Disk_25), - schemaScsi + "26": terraform_Disks_QemuScsiStorage(config.Disk_26), - schemaScsi + "27": terraform_Disks_QemuScsiStorage(config.Disk_27), - schemaScsi + "28": terraform_Disks_QemuScsiStorage(config.Disk_28), - schemaScsi + "29": terraform_Disks_QemuScsiStorage(config.Disk_29), - schemaScsi + "30": terraform_Disks_QemuScsiStorage(config.Disk_30)}} + schemaScsi + "0": terraform_Disks_QemuScsiStorage(config.Disk_0, ciDisk), + schemaScsi + "1": terraform_Disks_QemuScsiStorage(config.Disk_1, ciDisk), + schemaScsi + "2": terraform_Disks_QemuScsiStorage(config.Disk_2, ciDisk), + schemaScsi + "3": terraform_Disks_QemuScsiStorage(config.Disk_3, ciDisk), + schemaScsi + "4": terraform_Disks_QemuScsiStorage(config.Disk_4, ciDisk), + schemaScsi + "5": terraform_Disks_QemuScsiStorage(config.Disk_5, ciDisk), + schemaScsi + "6": terraform_Disks_QemuScsiStorage(config.Disk_6, ciDisk), + schemaScsi + "7": terraform_Disks_QemuScsiStorage(config.Disk_7, ciDisk), + schemaScsi + "8": terraform_Disks_QemuScsiStorage(config.Disk_8, ciDisk), + schemaScsi + "9": terraform_Disks_QemuScsiStorage(config.Disk_9, ciDisk), + schemaScsi + "10": terraform_Disks_QemuScsiStorage(config.Disk_10, ciDisk), + schemaScsi + "11": terraform_Disks_QemuScsiStorage(config.Disk_11, ciDisk), + schemaScsi + "12": terraform_Disks_QemuScsiStorage(config.Disk_12, ciDisk), + schemaScsi + "13": terraform_Disks_QemuScsiStorage(config.Disk_13, ciDisk), + schemaScsi + "14": terraform_Disks_QemuScsiStorage(config.Disk_14, ciDisk), + schemaScsi + "15": terraform_Disks_QemuScsiStorage(config.Disk_15, ciDisk), + schemaScsi + "16": terraform_Disks_QemuScsiStorage(config.Disk_16, ciDisk), + schemaScsi + "17": terraform_Disks_QemuScsiStorage(config.Disk_17, ciDisk), + schemaScsi + "18": terraform_Disks_QemuScsiStorage(config.Disk_18, ciDisk), + schemaScsi + "19": terraform_Disks_QemuScsiStorage(config.Disk_19, ciDisk), + schemaScsi + "20": terraform_Disks_QemuScsiStorage(config.Disk_20, ciDisk), + schemaScsi + "21": terraform_Disks_QemuScsiStorage(config.Disk_21, ciDisk), + schemaScsi + "22": terraform_Disks_QemuScsiStorage(config.Disk_22, ciDisk), + schemaScsi + "23": terraform_Disks_QemuScsiStorage(config.Disk_23, ciDisk), + schemaScsi + "24": terraform_Disks_QemuScsiStorage(config.Disk_24, ciDisk), + schemaScsi + "25": terraform_Disks_QemuScsiStorage(config.Disk_25, ciDisk), + schemaScsi + "26": terraform_Disks_QemuScsiStorage(config.Disk_26, ciDisk), + schemaScsi + "27": terraform_Disks_QemuScsiStorage(config.Disk_27, ciDisk), + schemaScsi + "28": terraform_Disks_QemuScsiStorage(config.Disk_28, ciDisk), + schemaScsi + "29": terraform_Disks_QemuScsiStorage(config.Disk_29, ciDisk), + schemaScsi + "30": terraform_Disks_QemuScsiStorage(config.Disk_30, ciDisk)}} } -func terraform_Disks_QemuScsiStorage(config *pveAPI.QemuScsiStorage) []interface{} { +func terraform_Disks_QemuScsiStorage(config *pveAPI.QemuScsiStorage, ciDisk *bool) []interface{} { if config == nil { return nil } @@ -230,6 +232,7 @@ func terraform_Disks_QemuScsiStorage(config *pveAPI.QemuScsiStorage) []interface schemaPassthrough: []interface{}{mapParams}}} } if config.CloudInit != nil { + *ciDisk = true return terraform_Disks_QemuCloudInit_unsafe(config.CloudInit) } return terraform_Disks_QemuCdRom(config.CdRom) diff --git a/proxmox/Internal/resource/guest/qemu/network/schema.go b/proxmox/Internal/resource/guest/qemu/network/schema.go index 52fbc588..927a4035 100644 --- a/proxmox/Internal/resource/guest/qemu/network/schema.go +++ b/proxmox/Internal/resource/guest/qemu/network/schema.go @@ -13,7 +13,7 @@ import ( const ( Root string = "network" - maximumNetworkInterfaces int = int(pveAPI.QemuNetworkInterfacesAmount) + MaximumNetworkInterfaces int = int(pveAPI.QemuNetworkInterfacesAmount) schemaID string = "id" @@ -32,7 +32,7 @@ func Schema() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, Optional: true, - MaxItems: maximumNetworkInterfaces, + MaxItems: MaximumNetworkInterfaces, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ schemaID: { diff --git a/proxmox/Internal/resource/guest/qemu/network/sdk.go b/proxmox/Internal/resource/guest/qemu/network/sdk.go index 08189885..abc50a73 100644 --- a/proxmox/Internal/resource/guest/qemu/network/sdk.go +++ b/proxmox/Internal/resource/guest/qemu/network/sdk.go @@ -14,8 +14,8 @@ import ( // Converts the Terraform configuration to the SDK configuration func SDK(d *schema.ResourceData) (pveAPI.QemuNetworkInterfaces, diag.Diagnostics) { - networks := make(pveAPI.QemuNetworkInterfaces, maximumNetworkInterfaces) - for i := 0; i < maximumNetworkInterfaces; i++ { + networks := make(pveAPI.QemuNetworkInterfaces, MaximumNetworkInterfaces) + for i := 0; i < MaximumNetworkInterfaces; i++ { networks[pveAPI.QemuNetworkInterfaceID(i)] = pveAPI.QemuNetworkInterface{Delete: true} } var diags diag.Diagnostics diff --git a/proxmox/Internal/resource/guest/qemu/network/terraform.go b/proxmox/Internal/resource/guest/qemu/network/terraform.go index 57182742..ae83f178 100644 --- a/proxmox/Internal/resource/guest/qemu/network/terraform.go +++ b/proxmox/Internal/resource/guest/qemu/network/terraform.go @@ -8,7 +8,7 @@ import ( // Converts the SDK configuration to the Terraform configuration func Terraform(config pveAPI.QemuNetworkInterfaces, d *schema.ResourceData) { paramMap := make([]interface{}, 0, len(config)) - for i := 0; i < maximumNetworkInterfaces; i++ { + for i := 0; i < MaximumNetworkInterfaces; i++ { v, ok := config[pveAPI.QemuNetworkInterfaceID(i)] if !ok { continue diff --git a/proxmox/heper_qemu.go b/proxmox/heper_qemu.go index 16459d55..8fed5b00 100644 --- a/proxmox/heper_qemu.go +++ b/proxmox/heper_qemu.go @@ -1,6 +1,7 @@ package proxmox import ( + "net" "strings" pxapi "github.com/Telmate/proxmox-api-go/proxmox" @@ -53,13 +54,13 @@ func (conn connectionInfo) agentDiagnostics() diag.Diagnostics { return diag.Diagnostics{diag.Diagnostic{ Severity: diag.Warning, Summary: errorGuestAgentNoIPSummary, - Detail: "Qemu Guest Agent is enabled in your configuration but no IP address was found before the time ran out, increasing 'agent_timeout' could resolve this issue."}} + Detail: "Qemu Guest Agent is enabled in your configuration but no IP address was found before the time ran out, increasing '" + schemaAgentTimeout + "' could resolve this issue."}} } if !conn.SkipIPv4 { return diag.Diagnostics{diag.Diagnostic{ Severity: diag.Warning, Summary: errorGuestAgentNoIPv4Summary, - Detail: "Qemu Guest Agent is enabled in your configuration but no IPv4 address was found before the time ran out, increasing 'agent_timeout' could resolve this issue. To suppress this warning set 'skip_ipv4' to true."}} + Detail: "Qemu Guest Agent is enabled in your configuration but no IPv4 address was found before the time ran out, increasing '" + schemaAgentTimeout + "' could resolve this issue. To suppress this warning set '" + schemaSkipIPv4 + "' to true."}} } return diag.Diagnostics{} } @@ -67,7 +68,7 @@ func (conn connectionInfo) agentDiagnostics() diag.Diagnostics { return diag.Diagnostics{diag.Diagnostic{ Severity: diag.Warning, Summary: errorGuestAgentNoIPv6Summary, - Detail: "Qemu Guest Agent is enabled in your configuration but no IPv6 address was found before the time ran out, increasing 'agent_timeout' could resolve this issue. To suppress this warning set 'skip_ipv6' to true."}} + Detail: "Qemu Guest Agent is enabled in your configuration but no IPv6 address was found before the time ran out, increasing '" + schemaAgentTimeout + "' could resolve this issue. To suppress this warning set '" + schemaSkipIPv6 + "' to true."}} } return diag.Diagnostics{} } @@ -79,10 +80,10 @@ func (conn connectionInfo) hasRequiredIP() bool { return true } -func (conn connectionInfo) parsePrimaryIPs(interfaces []pxapi.AgentNetworkInterface, mac string) connectionInfo { - lowerCaseMac := strings.ToLower(mac) +func (conn connectionInfo) parsePrimaryIPs(interfaces []pxapi.AgentNetworkInterface, mac net.HardwareAddr) connectionInfo { + macString := mac.String() for _, iFace := range interfaces { - if iFace.MacAddress.String() == lowerCaseMac { + if iFace.MacAddress.String() == macString { for _, addr := range iFace.IpAddresses { if addr.IsGlobalUnicast() { if addr.To4() != nil { diff --git a/proxmox/heper_qemu_test.go b/proxmox/heper_qemu_test.go index 32ba8226..cbc78bbe 100644 --- a/proxmox/heper_qemu_test.go +++ b/proxmox/heper_qemu_test.go @@ -313,7 +313,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { } type testInput struct { interfaces []pxapi.AgentNetworkInterface - mac string + mac net.HardwareAddr conn connectionInfo } tests := []struct { @@ -323,7 +323,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { }{ {name: `Only Loopback`, input: testInput{ - mac: "9c:7a:1b:4f:3e:a2", + mac: parseMac("9c:7a:1b:4f:3e:a2"), interfaces: []pxapi.AgentNetworkInterface{ { MacAddress: parseMac("9C:7A:1B:4F:3E:A2"), @@ -333,7 +333,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { parseIP("::1/128")}}}}}, {name: `Only IPv4`, input: testInput{ - mac: "3A:7E:9D:1F:5B:8C", + mac: parseMac("3A:7E:9D:1F:5B:8C"), interfaces: []pxapi.AgentNetworkInterface{ {MacAddress: parseMac("3A:7E:9D:1F:5B:8C"), Name: "eth1", @@ -344,7 +344,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { output: connectionInfo{IPs: primaryIPs{IPv4: formatIP("192.168.1.1")}}}, {name: `Only IPv6`, input: testInput{ - mac: "6F:2C:4A:8E:7D:1B", + mac: parseMac("6F:2C:4A:8E:7D:1B"), interfaces: []pxapi.AgentNetworkInterface{ {MacAddress: parseMac("6F:2C:4A:8E:7D:1B"), Name: "eth1", @@ -355,7 +355,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { output: connectionInfo{IPs: primaryIPs{IPv6: formatIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")}}}, {name: `Full test`, input: testInput{ - mac: "3A:7E:9D:1F:5B:8C", + mac: parseMac("3A:7E:9D:1F:5B:8C"), interfaces: []pxapi.AgentNetworkInterface{ {MacAddress: parseMac("6F:2C:4A:8E:7D:1B"), Name: "lo", @@ -380,7 +380,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { }, {name: `IPv4 Already Set`, input: testInput{ - mac: "3A:7E:9D:1F:5B:8C", + mac: parseMac("3A:7E:9D:1F:5B:8C"), interfaces: []pxapi.AgentNetworkInterface{ {MacAddress: parseMac("3A:7E:9D:1F:5B:8C"), IpAddresses: []net.IP{parseIP("192.168.1.1/24")}}}, @@ -388,7 +388,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { output: connectionInfo{IPs: primaryIPs{IPv4: formatIP("10.10.1.1")}}}, {name: `IPv6 Already Set`, input: testInput{ - mac: "3A:7E:9D:1F:5B:8C", + mac: parseMac("3A:7E:9D:1F:5B:8C"), interfaces: []pxapi.AgentNetworkInterface{ {MacAddress: parseMac("3A:7E:9D:1F:5B:8C"), IpAddresses: []net.IP{parseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64")}}}, diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index c401ca0a..44321e13 100755 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -8,6 +8,7 @@ import ( "fmt" "log" "math/rand" + "net" "net/url" "path" "regexp" @@ -45,6 +46,13 @@ const ( stateStopped string = "stopped" ) +const ( + schemaAdditionalWait = "additional_wait" + schemaAgentTimeout = "agent_timeout" + schemaSkipIPv4 = "skip_ipv4" + schemaSkipIPv6 = "skip_ipv6" +) + func resourceVmQemu() *schema.Resource { thisResource = &schema.Resource{ CreateContext: resourceVmQemuCreate, @@ -81,7 +89,7 @@ func resourceVmQemu() *schema.Resource { Optional: true, Default: 0, }, - "agent_timeout": { + schemaAgentTimeout: { Type: schema.TypeInt, Optional: true, Default: 60, @@ -97,7 +105,7 @@ func resourceVmQemu() *schema.Resource { if v > 0 { return nil } - return diag.Errorf("agent_timeout must be greater than 0") + return diag.Errorf(schemaAgentTimeout + " must be greater than 0") }, }, "vmid": { @@ -489,7 +497,7 @@ func resourceVmQemu() *schema.Resource { Default: 10, Description: "Value in second to wait after a VM has been cloned, useful if system is not fast or during I/O intensive parallel terraform tasks", }, - "additional_wait": { + schemaAdditionalWait: { Type: schema.TypeInt, Optional: true, Default: 5, @@ -629,17 +637,17 @@ func resourceVmQemu() *schema.Resource { Optional: true, ForceNew: true, }, - "skip_ipv4": { + schemaSkipIPv4: { Type: schema.TypeBool, Optional: true, Default: false, - ConflictsWith: []string{"skip_ipv6"}, + ConflictsWith: []string{schemaSkipIPv6}, }, - "skip_ipv6": { + schemaSkipIPv6: { Type: schema.TypeBool, Optional: true, Default: false, - ConflictsWith: []string{"skip_ipv4"}, + ConflictsWith: []string{schemaSkipIPv4}, }, "reboot_required": { Type: schema.TypeBool, @@ -907,7 +915,7 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte logger.Debug().Int("vmid", vmr.VmId()).Msgf("Set this vm (resource Id) to '%v'", d.Id()) // give sometime to proxmox to catchup - time.Sleep(time.Duration(d.Get("additional_wait").(int)) * time.Second) + time.Sleep(time.Duration(d.Get(schemaAdditionalWait).(int)) * time.Second) if d.Get("vm_state").(string) == "running" || d.Get("vm_state").(string) == "started" { log.Print("[DEBUG][QemuVmCreate] starting VM") @@ -1148,7 +1156,7 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte return append(diags, diag.FromErr(err)...) } // give sometime to proxmox to catchup - dur := time.Duration(d.Get("additional_wait").(int)) * time.Second + dur := time.Duration(d.Get(schemaAdditionalWait).(int)) * time.Second log.Printf("[DEBUG][QemuVmUpdate] waiting for (%v) before starting the VM again", dur) time.Sleep(dur) if _, err := client.StartVm(vmr); err != nil { @@ -1238,6 +1246,11 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf return diag.FromErr(err) } + var ciDisk bool + if config.Disks != nil { + disk.Terraform_Unsafe(d, config.Disks, &ciDisk) + } + vmState, err := client.GetVmState(vmr) if err != nil { return diag.FromErr(err) @@ -1247,7 +1260,7 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf if vmState["status"] == "running" { log.Printf("[DEBUG] VM is running, checking the IP") // TODO when network interfaces are reimplemented check if we have an interface before getting the connection info - diags = append(diags, initConnInfo(d, client, vmr, config)...) + diags = append(diags, initConnInfo(d, client, vmr, config, ciDisk)...) } else { // Optional convenience attributes for provisioners err = d.Set("default_ipv4_address", nil) @@ -1281,9 +1294,6 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("args", config.Args) d.Set("smbios", ReadSmbiosArgs(config.Smbios1)) d.Set("linked_vmid", config.LinkedVmId) - if config.Disks != nil { - disk.Terraform(d, *config.Disks) - } mapFromStruct_QemuGuestAgent(d, config.Agent) mapToTerraform_CPU(config.CPU, d) mapToTerraform_CloudInit(config.CloudInit, d) @@ -1575,12 +1585,7 @@ func UpdateDevicesSet( return devicesSet } -func initConnInfo( - d *schema.ResourceData, - client *pxapi.Client, - vmr *pxapi.VmRef, - config *pxapi.ConfigQemu, -) diag.Diagnostics { +func initConnInfo(d *schema.ResourceData, client *pxapi.Client, vmr *pxapi.VmRef, config *pxapi.ConfigQemu, hasCiDisk bool) diag.Diagnostics { logger, _ := CreateSubLogger("initConnInfo") var diags diag.Diagnostics // allow user to opt-out of setting the connection info for the resource @@ -1615,7 +1620,7 @@ func initConnInfo( log.Printf("[DEBUG][initConnInfo] retries will end at %s", guestAgentWaitEnd) logger.Debug().Int("vmid", vmr.VmId()).Msgf("retrying for at most %v minutes before giving up", guestAgentTimeout) logger.Debug().Int("vmid", vmr.VmId()).Msgf("retries will end at %s", guestAgentWaitEnd) - IPs, agentDiags := getPrimaryIP(config, vmr, client, guestAgentWaitEnd, d.Get("additional_wait").(int), d.Get("agent_timeout").(int), ciAgentEnabled, d.Get("skip_ipv4").(bool), d.Get("skip_ipv6").(bool)) + IPs, agentDiags := getPrimaryIP(config.CloudInit, config.Networks, vmr, client, guestAgentWaitEnd, d.Get(schemaAdditionalWait).(int), d.Get(schemaAgentTimeout).(int), ciAgentEnabled, d.Get(schemaSkipIPv4).(bool), d.Get(schemaSkipIPv6).(bool), hasCiDisk) if len(agentDiags) > 0 { diags = append(diags, agentDiags...) } @@ -1646,7 +1651,7 @@ func initConnInfo( return diags } -func getPrimaryIP(config *pxapi.ConfigQemu, vmr *pxapi.VmRef, client *pxapi.Client, endTime time.Time, additionalWait, agentTimeout int, ciAgentEnabled, skipIPv4 bool, skipIPv6 bool) (primaryIPs, diag.Diagnostics) { +func getPrimaryIP(cloudInit *pxapi.CloudInit, networks pxapi.QemuNetworkInterfaces, vmr *pxapi.VmRef, client *pxapi.Client, endTime time.Time, additionalWait, agentTimeout int, ciAgentEnabled, skipIPv4, skipIPv6, hasCiDisk bool) (primaryIPs, diag.Diagnostics) { logger, _ := CreateSubLogger("getPrimaryIP") // TODO allow the primary interface to be a different one than the first @@ -1654,39 +1659,42 @@ func getPrimaryIP(config *pxapi.ConfigQemu, vmr *pxapi.VmRef, client *pxapi.Clie SkipIPv4: skipIPv4, SkipIPv6: skipIPv6, } - // check if cloud init is enabled - if config.CloudInit != nil { - log.Print("[INFO][getPrimaryIP] vm has a cloud-init configuration") - logger.Debug().Int("vmid", vmr.VmId()).Msgf(" vm has a cloud-init configuration") - var cicustom bool - if config.CloudInit.Custom != nil && config.CloudInit.Custom.Network != nil { - cicustom = true - } - conn = parseCloudInitInterface(config.CloudInit.NetworkInterfaces[pxapi.QemuNetworkInterfaceID0], cicustom, conn.SkipIPv4, conn.SkipIPv6) - // early return, we have all information we wanted - if conn.hasRequiredIP() { - if conn.IPs.IPv4 == "" && conn.IPs.IPv6 == "" { - return primaryIPs{}, diag.Diagnostics{diag.Diagnostic{ - Severity: diag.Warning, - Summary: "Cloud-init is enabled but no IP config is set", - Detail: "Cloud-init is enabled in your configuration but no static IP address is set, nor is the DHCP option enabled"}} + if hasCiDisk { // Check if we have a Cloud-Init disk, cloud-init setting won't have any effect if without it. + if cloudInit != nil { // Check if we have a Cloud-Init configuration + log.Print("[INFO][getPrimaryIP] vm has a cloud-init configuration") + logger.Debug().Int("vmid", vmr.VmId()).Msgf(" vm has a cloud-init configuration") + var cicustom bool + if cloudInit.Custom != nil && cloudInit.Custom.Network != nil { + cicustom = true + } + conn = parseCloudInitInterface(cloudInit.NetworkInterfaces[pxapi.QemuNetworkInterfaceID0], cicustom, conn.SkipIPv4, conn.SkipIPv6) + // early return, we have all information we wanted + if conn.hasRequiredIP() { + if conn.IPs.IPv4 == "" && conn.IPs.IPv6 == "" { + return primaryIPs{}, diag.Diagnostics{diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Cloud-init is enabled but no IP config is set", + Detail: "Cloud-init is enabled in your configuration but no static IP address is set, nor is the DHCP option enabled"}} + } + return conn.IPs, diag.Diagnostics{} } - return conn.IPs, diag.Diagnostics{} + } else { + return primaryIPs{}, diag.Diagnostics{diag.Diagnostic{ + Severity: diag.Warning, + Summary: "VM has a Cloud-init disk but no Cloud-init settings"}} } } // get all information we can from qemu agent until the timer runs out if ciAgentEnabled { - var waitedTime int - // TODO rework this logic when network interfaces are properly handled in the SDK - vmConfig, err := client.GetVmConfig(vmr) - if err != nil { - return primaryIPs{}, diag.FromErr(err) - } - var primaryMacAddress string - for i := 0; i < 16; i++ { - if _, ok := vmConfig["net"+strconv.Itoa(i)]; ok { - primaryMacAddress = macAddressRegex.FindString(vmConfig["net"+strconv.Itoa(i)].(string)) + var ( + waitedTime int + primaryMacAddress net.HardwareAddr + err error + ) + for i := 0; i < network.MaximumNetworkInterfaces; i++ { + if v, ok := networks[pxapi.QemuNetworkInterfaceID(i)]; ok && v.MAC != nil { + primaryMacAddress = *v.MAC break } } diff --git a/proxmox/util.go b/proxmox/util.go index 1acd0ee9..1a801f53 100644 --- a/proxmox/util.go +++ b/proxmox/util.go @@ -22,8 +22,6 @@ var rxRsId = regexp.MustCompile(`([^/]+)/([^/]+)/(\d+)`) var rxClusterRsId = regexp.MustCompile(`([^/]+)/([^/]+)`) -var macAddressRegex = regexp.MustCompile(`([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}`) - var machineModelsRegex = regexp.MustCompile(`(^pc|^q35|^virt)`) // given a string, return the appropriate zerolog level