Skip to content

Commit

Permalink
Use regular string sorting for custom access context manager ingress …
Browse files Browse the repository at this point in the history
…and egress flatteners (#12288)

Co-authored-by: Charlesleonius <charlesleon@google.com>
  • Loading branch information
Charlesleonius and Charlesleonius authored Nov 11, 2024
1 parent 5fc717a commit 0616a35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
rawConfigValue := d.Get("egress_to.0.resources")

// Convert config value to []string
configValue, err := tpgresource.InterfaceSliceToStringSlice(rawConfigValue)
if err != nil {
log.Printf("[ERROR] Failed to convert config value: %s", err)
return v
}
sortedConfigValue := append([]string{}, configValue...)
sort.Strings(sortedConfigValue)

// Convert v to []string
apiStringValue, err := tpgresource.InterfaceSliceToStringSlice(v)
apiValue, err := tpgresource.InterfaceSliceToStringSlice(v)
if err != nil {
log.Printf("[ERROR] Failed to convert API value: %s", err)
return v
}
sortedApiValue := append([]string{}, apiValue...)
sort.Strings(sortedApiValue)

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

return sortedStrings
return apiValue
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
rawConfigValue := d.Get("ingress_to.0.resources")

// Convert config value to []string
configValue, err := tpgresource.InterfaceSliceToStringSlice(rawConfigValue)
if err != nil {
log.Printf("[ERROR] Failed to convert config value: %s", err)
return v
}
sortedConfigValue := append([]string{}, configValue...)
sort.Strings(sortedConfigValue)

// Convert v to []string
apiStringValue, err := tpgresource.InterfaceSliceToStringSlice(v)
apiValue, err := tpgresource.InterfaceSliceToStringSlice(v)
if err != nil {
log.Printf("[ERROR] Failed to convert API value: %s", err)
return v
}
sortedApiValue := append([]string{}, apiValue...)
sort.Strings(sortedApiValue)

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

return sortedStrings
return apiValue
}

0 comments on commit 0616a35

Please sign in to comment.