Skip to content

Commit 1ddab3c

Browse files
CharlesleoniusCharlesleonius
authored andcommitted
Use regular string sorting for custom access context manager ingress and egress flatteners (GoogleCloudPlatform#12288)
Co-authored-by: Charlesleonius <[email protected]>
1 parent 6f7d5dc commit 1ddab3c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
22
rawConfigValue := d.Get("egress_to.0.resources")
3-
43
// Convert config value to []string
54
configValue, err := tpgresource.InterfaceSliceToStringSlice(rawConfigValue)
65
if err != nil {
76
log.Printf("[ERROR] Failed to convert config value: %s", err)
87
return v
98
}
9+
sortedConfigValue := append([]string{}, configValue...)
10+
sort.Strings(sortedConfigValue)
1011

1112
// Convert v to []string
12-
apiStringValue, err := tpgresource.InterfaceSliceToStringSlice(v)
13+
apiValue, err := tpgresource.InterfaceSliceToStringSlice(v)
1314
if err != nil {
1415
log.Printf("[ERROR] Failed to convert API value: %s", err)
1516
return v
1617
}
18+
sortedApiValue := append([]string{}, apiValue...)
19+
sort.Strings(sortedApiValue)
1720

18-
sortedStrings, err := tpgresource.SortStringsByConfigOrder(configValue, apiStringValue)
19-
if err != nil {
20-
log.Printf("[ERROR] Could not sort API response value: %s", err)
21-
return v
21+
if (slices.Equal(sortedApiValue, sortedConfigValue)) {
22+
return configValue
2223
}
2324

24-
return sortedStrings
25+
return apiValue
2526
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
22
rawConfigValue := d.Get("ingress_to.0.resources")
3-
43
// Convert config value to []string
54
configValue, err := tpgresource.InterfaceSliceToStringSlice(rawConfigValue)
65
if err != nil {
76
log.Printf("[ERROR] Failed to convert config value: %s", err)
87
return v
98
}
9+
sortedConfigValue := append([]string{}, configValue...)
10+
sort.Strings(sortedConfigValue)
1011

1112
// Convert v to []string
12-
apiStringValue, err := tpgresource.InterfaceSliceToStringSlice(v)
13+
apiValue, err := tpgresource.InterfaceSliceToStringSlice(v)
1314
if err != nil {
1415
log.Printf("[ERROR] Failed to convert API value: %s", err)
1516
return v
1617
}
18+
sortedApiValue := append([]string{}, apiValue...)
19+
sort.Strings(sortedApiValue)
1720

18-
sortedStrings, err := tpgresource.SortStringsByConfigOrder(configValue, apiStringValue)
19-
if err != nil {
20-
log.Printf("[ERROR] Could not sort API response value: %s", err)
21-
return v
21+
if (slices.Equal(sortedApiValue, sortedConfigValue)) {
22+
return configValue
2223
}
2324

24-
return sortedStrings
25+
return apiValue
2526
}

0 commit comments

Comments
 (0)