From a0f0eea596f0527d24f8b3175b21768572181c5b Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Tue, 4 Feb 2025 08:04:42 +0100 Subject: [PATCH] feat: return same case for MAC Ensures that the return value for MAC is in the same case as the input in the .tf file, regardless of it's case in PVE --- .../resource/guest/qemu/network/schema.go | 5 ----- .../resource/guest/qemu/network/terraform.go | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/proxmox/Internal/resource/guest/qemu/network/schema.go b/proxmox/Internal/resource/guest/qemu/network/schema.go index 1d8ced5f..fd4209b0 100644 --- a/proxmox/Internal/resource/guest/qemu/network/schema.go +++ b/proxmox/Internal/resource/guest/qemu/network/schema.go @@ -65,11 +65,6 @@ func Schema() *schema.Schema { Type: schema.TypeString, Optional: true, Computed: true, - DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - oldMAC, _ := net.ParseMAC(old) - newMAC, _ := net.ParseMAC(new) - return oldMAC.String() == newMAC.String() - }, ValidateDiagFunc: func(i interface{}, p cty.Path) diag.Diagnostics { v := i.(string) if _, err := net.ParseMAC(v); err != nil { diff --git a/proxmox/Internal/resource/guest/qemu/network/terraform.go b/proxmox/Internal/resource/guest/qemu/network/terraform.go index 75a1bec1..a534c8db 100644 --- a/proxmox/Internal/resource/guest/qemu/network/terraform.go +++ b/proxmox/Internal/resource/guest/qemu/network/terraform.go @@ -1,6 +1,8 @@ package network import ( + "net" + pveAPI "github.com/Telmate/proxmox-api-go/proxmox" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -8,6 +10,11 @@ import ( // Converts the SDK configuration to the Terraform configuration func Terraform(config pveAPI.QemuNetworkInterfaces, d *schema.ResourceData) { paramArray := make([]interface{}, len(config)) + tfConfig := d.Get(Root).([]interface{}) + tfMap := make(map[int]interface{}, len(tfConfig)) + for i := range tfConfig { + tfMap[tfConfig[i].(map[string]interface{})[schemaID].(int)] = tfConfig[i] + } var index int for i := 0; i < AmountNetworkInterfaces; i++ { v, ok := config[pveAPI.QemuNetworkInterfaceID(i)] @@ -26,7 +33,17 @@ func Terraform(config pveAPI.QemuNetworkInterfaces, d *schema.ResourceData) { params[schemaFirewall] = *v.Firewall } if v.MAC != nil { - params[schemaMAC] = v.MAC.String() + if vv, ok := tfMap[i]; ok { + tfMAC := vv.(map[string]interface{})[schemaMAC].(string) + mac, _ := net.ParseMAC(tfMAC) + if mac.String() == v.MAC.String() { + params[schemaMAC] = tfMAC + } else { + params[schemaMAC] = v.MAC.String() + } + } else { + params[schemaMAC] = v.MAC.String() + } } if v.MTU != nil { if v.MTU.Inherit {