Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions docs/tables/scaleway_billing_consumption.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Scaleway Billing Consumption tracks the costs of various scaleway products such

**Important Notes**
- This table requires an Organization ID to be configured in the `scaleway.spc` file.
- You can optionally filter by `billing_period` (format: YYYY-MM) to query specific months.

## Table Usage Guide

Expand Down
25 changes: 25 additions & 0 deletions scaleway/table_scaleway_billing_consumption.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ func tableScalewayBillingConsumption(_ context.Context) *plugin.Table {
Name: "category_name",
Require: plugin.Optional,
},
{
Name: "billing_period",
Require: plugin.Optional,
},
},
},
Columns: []*plugin.Column{
{
Name: "billing_period",
Description: "The billing period for the consumption data (format: YYYY-MM).",
Type: proto.ColumnType_STRING,
Hydrate: getBillingPeriod,
Transform: transform.FromValue(),
},
{
Name: "category_name",
Description: "The CategoryName: name of consumption category.",
Expand Down Expand Up @@ -106,6 +117,10 @@ func listBillingConsumption(ctx context.Context, d *plugin.QueryData, _ *plugin.
req.CategoryName = scw.StringPtr(quals["category_name"].GetStringValue())
}

if quals["billing_period"] != nil {
req.BillingPeriod = scw.StringPtr(quals["billing_period"].GetStringValue())
}

// Retrieve the list of consumptions
maxResult := int64(100)

Expand Down Expand Up @@ -146,3 +161,13 @@ func listBillingConsumption(ctx context.Context, d *plugin.QueryData, _ *plugin.

return nil, nil
}

//// TRANSFORM FUNCTIONS

func getBillingPeriod(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
quals := d.EqualsQuals
if quals["billing_period"] != nil {
return quals["billing_period"].GetStringValue(), nil
}
return nil, nil
}
Loading