Skip to content

Commit a66e263

Browse files
authored
fix(lb): ignore order changes on certificate ids (#2439)
* fix(lb): ignore order changes on certificate ids * fix
1 parent 34c9d72 commit a66e263

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

scaleway/helpers.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"fmt"
88
"net"
99
"net/http"
10+
"reflect"
11+
"sort"
1012
"strconv"
1113
"strings"
1214
"testing"
@@ -762,6 +764,39 @@ func diffSuppressFuncLocality(_, oldValue, newValue string, _ *schema.ResourceDa
762764
return expandID(oldValue) == expandID(newValue)
763765
}
764766

767+
// diffSuppressFuncOrderDiff suppresses diffs for TypeList attributes when the only change is the order of elements.
768+
// https://github.com/hashicorp/terraform-plugin-sdk/issues/477#issuecomment-1238807249
769+
func diffSuppressFuncOrderDiff(k, _, _ string, d *schema.ResourceData) bool {
770+
// Extract the base key path to the list attribute, ignoring the index and value parts
771+
lastDotIndex := strings.LastIndex(k, ".")
772+
baseKey := k
773+
if lastDotIndex != -1 {
774+
baseKey = k[:lastDotIndex]
775+
}
776+
777+
oldList, newList := d.GetChange(baseKey)
778+
if oldList == nil || newList == nil {
779+
return false
780+
}
781+
782+
oldListSlice, newListSlice := oldList.([]interface{}), newList.([]interface{})
783+
if len(oldListSlice) != len(newListSlice) {
784+
return false // Different lengths means there's definitely a change
785+
}
786+
787+
oldListStr, newListStr := make([]string, len(oldListSlice)), make([]string, len(newListSlice))
788+
for i, oldItem := range oldListSlice {
789+
oldListStr[i] = fmt.Sprint(oldItem)
790+
}
791+
for j, newItem := range newListSlice {
792+
newListStr[j] = fmt.Sprint(newItem)
793+
}
794+
sort.Strings(oldListStr)
795+
sort.Strings(newListStr)
796+
797+
return reflect.DeepEqual(oldListStr, newListStr)
798+
}
799+
765800
// TimedOut returns true if the error represents a "wait timed out" condition.
766801
// Specifically, TimedOut returns true if the error matches all these conditions:
767802
// - err is of type resource.TimeoutError

scaleway/resource_lb_frontend.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ func resourceScalewayLbFrontend() *schema.Resource {
7979
Type: schema.TypeString,
8080
ValidateFunc: validationUUIDorUUIDWithLocality(),
8181
},
82-
Description: "Collection of Certificate IDs related to the load balancer and domain",
82+
Description: "Collection of Certificate IDs related to the load balancer and domain",
83+
DiffSuppressFunc: diffSuppressFuncOrderDiff,
8384
},
8485
"acl": {
8586
Type: schema.TypeList,

0 commit comments

Comments
 (0)