Skip to content

Commit

Permalink
feat: add billing_information column to gcp_project and gcp_organizat…
Browse files Browse the repository at this point in the history
…ion_project tables
  • Loading branch information
pdecat committed Oct 7, 2024
1 parent 5c0cec5 commit a44aa32
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gcp/table_gcp_organization_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
29 changes: 29 additions & 0 deletions gcp/table_gcp_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -186,6 +193,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
Expand Down

0 comments on commit a44aa32

Please sign in to comment.