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"}, }, }, })