Skip to content

Commit

Permalink
[#9353] Make cloud router sort advertised_ip_ranges in state by confi…
Browse files Browse the repository at this point in the history
…g order (#10572) (#18228)

[upstream:43a016f81c954557aeaad7f4f8286774f294e70e]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored May 23, 2024
1 parent 22607be commit 2fc2311
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
28 changes: 16 additions & 12 deletions google/services/compute/resource_compute_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
})
Expand Down Expand Up @@ -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"},
},
},
})
Expand Down

0 comments on commit 2fc2311

Please sign in to comment.