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) (#20294)

[upstream:0616a35f4dddbca1857fbc0c1330bc5ea93cc7e5]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Nov 11, 2024
1 parent b7367a3 commit 6a6aa09
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .changelog/12288.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
accesscontextmanager: Fix permadiff in perimeter ingress / egress rules when there are duplicate resources in the rules
```
Original file line number Diff line number Diff line change
Expand Up @@ -556,28 +556,29 @@ func flattenNestedAccessContextManagerServicePerimeterDryRunEgressPolicyEgressTo
}
func flattenNestedAccessContextManagerServicePerimeterDryRunEgressPolicyEgressToResources(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
}

func flattenNestedAccessContextManagerServicePerimeterDryRunEgressPolicyEgressToExternalResources(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,28 +557,29 @@ func flattenNestedAccessContextManagerServicePerimeterDryRunIngressPolicyIngress
}
func flattenNestedAccessContextManagerServicePerimeterDryRunIngressPolicyIngressToResources(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
}

func flattenNestedAccessContextManagerServicePerimeterDryRunIngressPolicyIngressToOperations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,28 +554,29 @@ func flattenNestedAccessContextManagerServicePerimeterEgressPolicyEgressTo(v int
}
func flattenNestedAccessContextManagerServicePerimeterEgressPolicyEgressToResources(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
}

func flattenNestedAccessContextManagerServicePerimeterEgressPolicyEgressToExternalResources(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,28 +558,29 @@ func flattenNestedAccessContextManagerServicePerimeterIngressPolicyIngressTo(v i
}
func flattenNestedAccessContextManagerServicePerimeterIngressPolicyIngressToResources(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
}

func flattenNestedAccessContextManagerServicePerimeterIngressPolicyIngressToOperations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down

0 comments on commit 6a6aa09

Please sign in to comment.