@@ -767,30 +767,42 @@ func diffSuppressFuncLocality(_, oldValue, newValue string, _ *schema.ResourceDa
767767// diffSuppressFuncOrderDiff suppresses diffs for TypeList attributes when the only change is the order of elements.
768768// https://github.com/hashicorp/terraform-plugin-sdk/issues/477#issuecomment-1238807249
769769func diffSuppressFuncOrderDiff (k , _ , _ string , d * schema.ResourceData ) bool {
770- // Extract the base key path to the list attribute, ignoring the index and value parts
770+ baseKey := extractBaseKey (k )
771+ oldList , newList := getStringListsFromState (baseKey , d )
772+
773+ return compareStringListsIgnoringOrder (oldList , newList )
774+ }
775+
776+ func extractBaseKey (k string ) string {
771777 lastDotIndex := strings .LastIndex (k , "." )
772- baseKey := k
773778 if lastDotIndex != - 1 {
774- baseKey = k [:lastDotIndex ]
779+ return k [:lastDotIndex ]
775780 }
776781
777- oldList , newList := d .GetChange (baseKey )
778- if oldList == nil || newList == nil {
779- return false
780- }
782+ return k
783+ }
781784
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- }
785+ func getStringListsFromState (key string , d * schema.ResourceData ) ([]string , []string ) {
786+ oldList , newList := d .GetChange (key )
786787
787- oldListStr , newListStr := make ([]string , len (oldListSlice )), make ([]string , len (newListSlice ))
788- for i , oldItem := range oldListSlice {
789- oldListStr [i ] = fmt .Sprint (oldItem )
788+ oldListStr := make ([]string , len (oldList .([]interface {})))
789+ newListStr := make ([]string , len (newList .([]interface {})))
790+
791+ for i , v := range oldList .([]interface {}) {
792+ oldListStr [i ] = fmt .Sprint (v )
793+ }
794+ for i , v := range newList .([]interface {}) {
795+ newListStr [i ] = fmt .Sprint (v )
790796 }
791- for j , newItem := range newListSlice {
792- newListStr [j ] = fmt .Sprint (newItem )
797+
798+ return oldListStr , newListStr
799+ }
800+
801+ func compareStringListsIgnoringOrder (oldListStr , newListStr []string ) bool {
802+ if len (oldListStr ) != len (newListStr ) {
803+ return false // different lengths means there's definitely a change
793804 }
805+
794806 sort .Strings (oldListStr )
795807 sort .Strings (newListStr )
796808
0 commit comments