diff --git a/gcp/table_gcp_organization_project.go b/gcp/table_gcp_organization_project.go index 0ed76d67..f54564d4 100644 --- a/gcp/table_gcp_organization_project.go +++ b/gcp/table_gcp_organization_project.go @@ -75,6 +75,13 @@ func tableGcpOrganizationProject(_ context.Context) *plugin.Table { Hydrate: getProjectAncestors, Transform: transform.FromValue(), }, + { + Name: "billing_information", + Description: "The billing information of the project.", + Type: proto.ColumnType_JSON, + Hydrate: getProjectBillingInfo, + Transform: transform.FromValue(), + }, // Steampipe standard columns { diff --git a/gcp/table_gcp_project.go b/gcp/table_gcp_project.go index a9d14672..4747e750 100644 --- a/gcp/table_gcp_project.go +++ b/gcp/table_gcp_project.go @@ -75,6 +75,13 @@ func tableGcpProject(_ context.Context) *plugin.Table { Hydrate: getProjectAncestors, Transform: transform.FromValue(), }, + { + Name: "billing_information", + Description: "The billing information of the project.", + Type: proto.ColumnType_JSON, + Hydrate: getProjectBillingInfo, + Transform: transform.FromValue(), + }, // Steampipe standard columns { @@ -188,6 +195,28 @@ func getProjectAncestors(ctx context.Context, d *plugin.QueryData, h *plugin.Hyd return resp.Ancestor, nil } +func getProjectBillingInfo(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + // Create Service Connection + service, err := BillingService(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("gcp_project.getProjectBillingInformation", "connection_error", err) + return nil, err + } + + // Get project details + projectId := h.Item.(*cloudresourcemanager.Project).ProjectId + + resp, err := service.Projects.GetBillingInfo("projects/" + projectId).Do() + if err != nil { + if strings.Contains(err.Error(), "404") { + return nil, nil + } + plugin.Logger(ctx).Error("gcp_project.getProjectBillingInformation", "api_err", err) + return nil, err + } + return resp, nil +} + func projectSelfLink(_ context.Context, d *transform.TransformData) (interface{}, error) { data := d.HydrateItem.(*cloudresourcemanager.Project) selfLink := "https://cloudresourcemanager.googleapis.com/v1/projects/" + data.Name