Skip to content

Commit

Permalink
don't include IGM URLs that 404 in instance_group_urls (#3438)
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow authored Apr 29, 2020
1 parent c926af5 commit 7e909bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,10 @@ func getInstanceGroupUrlsFromManagerUrls(config *Config, igmUrls []string) ([]st
}
matches := instanceGroupManagerURL.FindStringSubmatch(u)
instanceGroupManager, err := config.clientCompute.InstanceGroupManagers.Get(matches[1], matches[2], matches[3]).Do()
if isGoogleApiErrorWithCode(err, 404) {
// The IGM URL is stale; don't include it
continue
}
if err != nil {
return nil, fmt.Errorf("Error reading instance group manager returned as an instance group URL: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,27 @@ func flattenNodePool(d *schema.ResourceData, config *Config, np *containerBeta.N
// instance groups instead. They should all have the same size, but in case a resize
// failed or something else strange happened, we'll just use the average size.
size := 0
igmUrls := []string{}
for _, url := range np.InstanceGroupUrls {
// retrieve instance group manager (InstanceGroupUrls are actually URLs for InstanceGroupManagers)
matches := instanceGroupManagerURL.FindStringSubmatch(url)
if len(matches) < 4 {
return nil, fmt.Errorf("Error reading instance group manage URL '%q'", url)
}
igm, err := config.clientComputeBeta.InstanceGroupManagers.Get(matches[1], matches[2], matches[3]).Do()
if isGoogleApiErrorWithCode(err, 404) {
// The IGM URL in is stale; don't include it
continue
}
if err != nil {
return nil, fmt.Errorf("Error reading instance group manager returned as an instance group URL: %q", err)
}
size += int(igm.TargetSize)
igmUrls = append(igmUrls, url)
}
nodeCount := 0
if len(igmUrls) > 0 {
nodeCount = size / len(igmUrls)
}
nodePool := map[string]interface{}{
"name": np.Name,
Expand All @@ -580,9 +590,9 @@ func flattenNodePool(d *schema.ResourceData, config *Config, np *containerBeta.N
<% unless version == 'ga' -%>
"node_locations": schema.NewSet(schema.HashString, convertStringArrToInterface(np.Locations)),
<% end -%>
"node_count": size / len(np.InstanceGroupUrls),
"node_count": nodeCount,
"node_config": flattenNodeConfig(np.Config),
"instance_group_urls": np.InstanceGroupUrls,
"instance_group_urls": igmUrls,
"version": np.Version,
}

Expand Down

0 comments on commit 7e909bc

Please sign in to comment.