Skip to content

Commit ba55b7f

Browse files
committed
feat: add billing_information column to gcp_project and gcp_organization_project tables
1 parent 2912705 commit ba55b7f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

gcp/table_gcp_organization_project.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ func tableGcpOrganizationProject(_ context.Context) *plugin.Table {
7575
Hydrate: getProjectAncestors,
7676
Transform: transform.FromValue(),
7777
},
78+
{
79+
Name: "billing_information",
80+
Description: "The billing information of the project.",
81+
Type: proto.ColumnType_JSON,
82+
Hydrate: getProjectBillingInfo,
83+
Transform: transform.FromValue(),
84+
},
7885

7986
// Steampipe standard columns
8087
{

gcp/table_gcp_project.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ func tableGcpProject(_ context.Context) *plugin.Table {
7575
Hydrate: getProjectAncestors,
7676
Transform: transform.FromValue(),
7777
},
78+
{
79+
Name: "billing_information",
80+
Description: "The billing information of the project.",
81+
Type: proto.ColumnType_JSON,
82+
Hydrate: getProjectBillingInfo,
83+
Transform: transform.FromValue(),
84+
},
7885

7986
// Steampipe standard columns
8087
{
@@ -188,6 +195,28 @@ func getProjectAncestors(ctx context.Context, d *plugin.QueryData, h *plugin.Hyd
188195
return resp.Ancestor, nil
189196
}
190197

198+
func getProjectBillingInfo(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
199+
// Create Service Connection
200+
service, err := BillingService(ctx, d)
201+
if err != nil {
202+
plugin.Logger(ctx).Error("gcp_project.getProjectBillingInformation", "connection_error", err)
203+
return nil, err
204+
}
205+
206+
// Get project details
207+
projectId := h.Item.(*cloudresourcemanager.Project).ProjectId
208+
209+
resp, err := service.Projects.GetBillingInfo("projects/" + projectId).Do()
210+
if err != nil {
211+
if strings.Contains(err.Error(), "404") {
212+
return nil, nil
213+
}
214+
plugin.Logger(ctx).Error("gcp_project.getProjectBillingInformation", "api_err", err)
215+
return nil, err
216+
}
217+
return resp, nil
218+
}
219+
191220
func projectSelfLink(_ context.Context, d *transform.TransformData) (interface{}, error) {
192221
data := d.HydrateItem.(*cloudresourcemanager.Project)
193222
selfLink := "https://cloudresourcemanager.googleapis.com/v1/projects/" + data.Name

0 commit comments

Comments
 (0)