Skip to content
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

fix: instances column of gcp_compute_instance_group errors for regional groups #670

Merged
Merged
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
23 changes: 16 additions & 7 deletions gcp/table_gcp_compute_instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,23 @@ func getComputeInstanceGroupInstances(ctx context.Context, d *plugin.QueryData,
return nil, err
}

resp, err := service.InstanceGroups.ListInstances(project, getLastPathElement(types.SafeString(instanceGroup.Zone)), instanceGroup.Name, &compute.InstanceGroupsListInstancesRequest{}).Do()

if err != nil {
plugin.Logger(ctx).Error("gcp_compute_instance_group.getComputeInstanceGroupInstances", "api_err", err)
return nil, err
// Regional instance groups do not have any zone specified but a region instead,
// and querying their instances must be done with the regional endpoint
if instanceGroup.Zone == "" {
misraved marked this conversation as resolved.
Show resolved Hide resolved
resp, err := service.RegionInstanceGroups.ListInstances(project, getLastPathElement(types.SafeString(instanceGroup.Region)), instanceGroup.Name, &compute.RegionInstanceGroupsListInstancesRequest{}).Do()
if err != nil {
plugin.Logger(ctx).Error("gcp_compute_instance_group.getComputeInstanceGroupInstances", "api_err", err)
return nil, err
}
return &resp.Items, nil
} else {
resp, err := service.InstanceGroups.ListInstances(project, getLastPathElement(types.SafeString(instanceGroup.Zone)), instanceGroup.Name, &compute.InstanceGroupsListInstancesRequest{}).Do()
if err != nil {
plugin.Logger(ctx).Error("gcp_compute_instance_group.getComputeInstanceGroupInstances", "api_err", err)
return nil, err
}
return &resp.Items, nil
}

return &resp.Items, nil
}

//// TRANSFORM FUNCTIONS
Expand Down
Loading