Skip to content

Commit

Permalink
Merge pull request #1244 from Tinyblargon/1182
Browse files Browse the repository at this point in the history
feat: return same case for MAC
  • Loading branch information
Tinyblargon authored Feb 6, 2025
2 parents 47d9e55 + a0f0eea commit 268dd4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 0 additions & 5 deletions proxmox/Internal/resource/guest/qemu/network/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion proxmox/Internal/resource/guest/qemu/network/terraform.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package network

import (
"net"

pveAPI "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// 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)]
Expand All @@ -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 {
Expand Down

0 comments on commit 268dd4d

Please sign in to comment.