From 2fc23113dc8470e48dafbd789539f5cc55bc29ac Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 23 May 2024 09:38:52 -0700 Subject: [PATCH] [#9353] Make cloud router sort advertised_ip_ranges in state by config order (#10572) (#18228) [upstream:43a016f81c954557aeaad7f4f8286774f294e70e] Signed-off-by: Modular Magician --- .../compute/resource_compute_router.go | 28 +++++++++++-------- .../resource_compute_router_generated_test.go | 4 +-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/google/services/compute/resource_compute_router.go b/google/services/compute/resource_compute_router.go index c7460369b54..bc0cd9801ee 100644 --- a/google/services/compute/resource_compute_router.go +++ b/google/services/compute/resource_compute_router.go @@ -633,26 +633,30 @@ func flattenComputeRouterBgpAdvertisedIpRanges(v interface{}, d *schema.Resource return v } l := v.([]interface{}) - transformed := make([]interface{}, 0, len(l)) + apiData := make([]map[string]interface{}, 0, len(l)) for _, raw := range l { original := raw.(map[string]interface{}) if len(original) < 1 { // Do not include empty json objects coming back from the api continue } - transformed = append(transformed, map[string]interface{}{ - "range": flattenComputeRouterBgpAdvertisedIpRangesRange(original["range"], d, config), - "description": flattenComputeRouterBgpAdvertisedIpRangesDescription(original["description"], d, config), + apiData = append(apiData, map[string]interface{}{ + "description": original["description"], + "range": original["range"], }) } - return transformed -} -func flattenComputeRouterBgpAdvertisedIpRangesRange(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { - return v -} - -func flattenComputeRouterBgpAdvertisedIpRangesDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { - return v + configData := []map[string]interface{}{} + if v, ok := d.GetOk("advertised_ip_ranges"); ok { + for _, item := range v.([]interface{}) { + configData = append(configData, item.(map[string]interface{})) + } + } + sorted, err := tpgresource.SortMapsByConfigOrder(configData, apiData, "range") + if err != nil { + log.Printf("[ERROR] Could not support API response for advertisedIpRanges.0.range: %s", err) + return apiData + } + return sorted } func flattenComputeRouterBgpKeepaliveInterval(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { diff --git a/google/services/compute/resource_compute_router_generated_test.go b/google/services/compute/resource_compute_router_generated_test.go index dd68a894e75..0da226091c5 100644 --- a/google/services/compute/resource_compute_router_generated_test.go +++ b/google/services/compute/resource_compute_router_generated_test.go @@ -49,7 +49,7 @@ func TestAccComputeRouter_routerBasicExample(t *testing.T) { ResourceName: "google_compute_router.foobar", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"network", "region"}, + ImportStateVerifyIgnore: []string{"advertisedIpRanges", "network", "region"}, }, }, }) @@ -99,7 +99,7 @@ func TestAccComputeRouter_computeRouterEncryptedInterconnectExample(t *testing.T ResourceName: "google_compute_router.encrypted-interconnect-router", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"network", "region"}, + ImportStateVerifyIgnore: []string{"advertisedIpRanges", "network", "region"}, }, }, })