Skip to content

[#9353] Make cloud router sort advertised_ip_ranges in state by config order #7411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions google-beta/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