From 378ac45815c1474ccbab6de964b1e0c4479ede54 Mon Sep 17 00:00:00 2001 From: Patrick Decat Date: Mon, 28 Oct 2024 14:40:25 +0100 Subject: [PATCH] fix: instances column of gcp_compute_instance_group errors for regional groups (#670) --- gcp/table_gcp_compute_instance_group.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/gcp/table_gcp_compute_instance_group.go b/gcp/table_gcp_compute_instance_group.go index fb4b5357..17f5a209 100644 --- a/gcp/table_gcp_compute_instance_group.go +++ b/gcp/table_gcp_compute_instance_group.go @@ -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 == "" { + 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