Skip to content

Commit bb987fb

Browse files
authored
feat(billing): bump to v2beta1 api (#2378)
* feat(ipam): add support for ip reverse dns * fix * lint * feat(billing): bump to v2beta1 api
1 parent 0ce3154 commit bb987fb

9 files changed

+5550
-175
lines changed

docs/data-sources/billing_consumption.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ data "scaleway_billing_consumptions" "my-consumption" {
1919
## Argument Reference
2020

2121
- `organization_id` - (Defaults to [provider](../index.md#organization_d) `organization_id`) The ID of the organization the consumption list is associated with.
22+
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the consumption list is associated with.
2223

2324
## Attributes Reference
2425

2526
In addition to all arguments above, the following attributes are exported:
2627

2728
- `consumptions` - List of found consumptions
2829
- `value` - The monetary value of the consumption.
29-
- `description` - The description of the consumption.
30+
- `product_name` - The product name.
31+
- `category_name` - The name of the consumption category.
32+
- `sku` - The unique identifier of the product.
33+
- `unit` - The unit of consumed quantity.
34+
- `billed_quantity` - The consumed quantity.
3035
- `project_id` - The project ID of the consumption.
31-
- `category` - The category of the consumption.
32-
- `operation_path` - The unique identifier of the product.
3336
- `updated_at` - The last consumption update date.

docs/data-sources/billing_invoices.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,26 @@ data "scaleway_billing_invoices" "my-invoices" {
2929

3030
- `invoice_type` - (Optional) Invoices with the given type are listed. Valid values are `periodic` and `purchase`.
3131

32+
- `organization_id` - (Defaults to [provider](../index.md#organization_d) `organization_id`) The ID of the organization the invoice list is associated with.
33+
3234
## Attributes Reference
3335

3436
In addition to all arguments above, the following attributes are exported:
3537

3638
- `invoices` - List of found invoices
3739
- `id` - The associated invoice ID.
40+
- `organization_name` - The organization name.
3841
- `start_date` - The start date of the billing period (RFC 3339 format).
42+
- `stop_date` - The end date of the billing period (RFC 3339 format).
43+
- `billing_period` - The billing period of the invoice in the YYYY-MM format.
3944
- `issued_date` - The date when the invoice was sent to the customer (RFC 3339 format).
4045
- `due_date` - The payment time limit, set according to the Organization's payment conditions (RFC 3339 format).
4146
- `total_untaxed` - The total amount, untaxed.
4247
- `total_taxed` - The total amount, taxed.
48+
- `total_tax` - The total tax amount of the invoice.
49+
- `total_discount` - The total discount amount of the invoice.
50+
- `total_undiscount` - The total amount of the invoice before applying the discount.
4351
- `invoice_type` - The type of invoice.
44-
- `number` - The invoice number.
52+
- `state` - The state of the invoice.
53+
- `number` - The invoice number.
54+
- `seller_name` - The name of the seller (Scaleway).

scaleway/data_source_billing_consumption.go

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
billing "github.com/scaleway/scaleway-sdk-go/api/billing/v2alpha1"
10+
billing "github.com/scaleway/scaleway-sdk-go/api/billing/v2beta1"
1111
"github.com/scaleway/scaleway-sdk-go/scw"
1212
)
1313

@@ -16,30 +16,46 @@ func dataSourceScalewayBillingConsumptions() *schema.Resource {
1616
ReadContext: dataSourceScalewayBillingConsumptionsRead,
1717
Schema: map[string]*schema.Schema{
1818
"organization_id": organizationIDSchema(),
19+
"project_id": projectIDSchema(),
1920
"consumptions": {
2021
Type: schema.TypeList,
2122
Computed: true,
2223
Elem: &schema.Resource{
2324
Schema: map[string]*schema.Schema{
2425
"value": {
25-
Computed: true,
26-
Type: schema.TypeString,
26+
Computed: true,
27+
Type: schema.TypeString,
28+
Description: "Monetary value of the consumption",
2729
},
28-
"description": {
29-
Computed: true,
30-
Type: schema.TypeString,
30+
"product_name": {
31+
Computed: true,
32+
Type: schema.TypeString,
33+
Description: "The product name",
3134
},
32-
"project_id": {
33-
Computed: true,
34-
Type: schema.TypeString,
35+
"category_name": {
36+
Computed: true,
37+
Type: schema.TypeString,
38+
Description: "Name of consumption category",
39+
},
40+
"sku": {
41+
Computed: true,
42+
Type: schema.TypeString,
43+
Description: "Unique identifier of the product",
3544
},
36-
"category": {
37-
Computed: true,
38-
Type: schema.TypeString,
45+
"unit": {
46+
Computed: true,
47+
Type: schema.TypeString,
48+
Description: "Unit of consumed quantity",
3949
},
40-
"operation_path": {
41-
Computed: true,
42-
Type: schema.TypeString,
50+
"billed_quantity": {
51+
Computed: true,
52+
Type: schema.TypeString,
53+
Description: "Consumed quantity",
54+
},
55+
"project_id": {
56+
Computed: true,
57+
Type: schema.TypeString,
58+
Description: "Project ID of the consumption",
4359
},
4460
},
4561
},
@@ -55,8 +71,11 @@ func dataSourceScalewayBillingConsumptions() *schema.Resource {
5571
func dataSourceScalewayBillingConsumptionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
5672
api := billingAPI(meta)
5773

58-
res, err := api.GetConsumption(&billing.GetConsumptionRequest{
59-
OrganizationID: d.Get("organization_id").(string),
74+
res, err := api.ListConsumptions(&billing.ListConsumptionsRequest{
75+
CategoryName: expandStringPtr(d.Get("category_name")),
76+
BillingPeriod: expandStringPtr(d.Get("billing_period")),
77+
OrganizationID: expandStringPtr(d.Get("organization_id")),
78+
ProjectID: expandStringPtr(d.Get("project_id")),
6079
}, scw.WithContext(ctx))
6180
if err != nil {
6281
return diag.FromErr(err)
@@ -66,10 +85,12 @@ func dataSourceScalewayBillingConsumptionsRead(ctx context.Context, d *schema.Re
6685
for _, consumption := range res.Consumptions {
6786
rawConsumption := make(map[string]interface{})
6887
rawConsumption["value"] = consumption.Value.String()
69-
rawConsumption["description"] = consumption.Description
88+
rawConsumption["product_name"] = consumption.ProductName
7089
rawConsumption["project_id"] = consumption.ProjectID
71-
rawConsumption["category"] = consumption.Category
72-
rawConsumption["operation_path"] = consumption.OperationPath
90+
rawConsumption["category_name"] = consumption.CategoryName
91+
rawConsumption["sku"] = consumption.Sku
92+
rawConsumption["unit"] = consumption.Unit
93+
rawConsumption["billed_quantity"] = consumption.BilledQuantity
7394

7495
consumptions = append(consumptions, rawConsumption)
7596
}

scaleway/data_source_billing_consumption_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ func testAccCheckScalewayConsumptionsConditionalChecks(resourceName string) reso
3939
if ok && attr != "0" {
4040
checks := []resource.TestCheckFunc{
4141
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.value"),
42-
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.description"),
42+
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.product_name"),
4343
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.project_id"),
44-
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.category"),
45-
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.operation_path"),
44+
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.category_name"),
45+
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.sku"),
46+
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.unit"),
47+
resource.TestCheckResourceAttrSet(resourceName, "consumptions.0.billed_quantity"),
4648
resource.TestCheckResourceAttrSet(resourceName, "updated_at"),
4749
}
4850

scaleway/data_source_billing_invoices.go

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
billing "github.com/scaleway/scaleway-sdk-go/api/billing/v2alpha1"
10+
billing "github.com/scaleway/scaleway-sdk-go/api/billing/v2beta1"
1111
"github.com/scaleway/scaleway-sdk-go/scw"
1212
)
1313

@@ -36,36 +36,84 @@ func dataSourceScalewayBillingInvoices() *schema.Resource {
3636
Elem: &schema.Resource{
3737
Schema: map[string]*schema.Schema{
3838
"id": {
39-
Computed: true,
40-
Type: schema.TypeString,
39+
Computed: true,
40+
Type: schema.TypeString,
41+
Description: "Invoice ID",
42+
},
43+
"organization_name": {
44+
Computed: true,
45+
Type: schema.TypeString,
46+
Description: "Organization name",
4147
},
4248
"start_date": {
43-
Computed: true,
44-
Type: schema.TypeString,
49+
Computed: true,
50+
Type: schema.TypeString,
51+
Description: "Start date of the billing period",
52+
},
53+
"stop_date": {
54+
Computed: true,
55+
Type: schema.TypeString,
56+
Description: "Stop date of the billing period",
57+
},
58+
"billing_period": {
59+
Computed: true,
60+
Type: schema.TypeString,
61+
Description: "Billing period of the invoice in the YYYY-MM format",
4562
},
4663
"issued_date": {
47-
Computed: true,
48-
Type: schema.TypeString,
64+
Computed: true,
65+
Type: schema.TypeString,
66+
Description: "Date when the invoice was sent to the customer",
4967
},
5068
"due_date": {
51-
Computed: true,
52-
Type: schema.TypeString,
69+
Computed: true,
70+
Type: schema.TypeString,
71+
Description: "Payment time limit, set according to the Organization's payment conditions",
5372
},
5473
"total_untaxed": {
55-
Computed: true,
56-
Type: schema.TypeString,
74+
Computed: true,
75+
Type: schema.TypeString,
76+
Description: "Total amount of the invoice, untaxed",
5777
},
5878
"total_taxed": {
59-
Computed: true,
60-
Type: schema.TypeString,
79+
Computed: true,
80+
Type: schema.TypeString,
81+
Description: "Total amount of the invoice, taxed",
82+
},
83+
"total_tax": {
84+
Computed: true,
85+
Type: schema.TypeString,
86+
Description: "The total tax amount of the invoice",
87+
},
88+
"total_discount": {
89+
Computed: true,
90+
Type: schema.TypeString,
91+
Description: "The total discount amount of the invoice",
92+
},
93+
"total_undiscount": {
94+
Computed: true,
95+
Type: schema.TypeString,
96+
Description: "The total amount of the invoice before applying the discount",
6197
},
6298
"invoice_type": {
63-
Computed: true,
64-
Type: schema.TypeString,
99+
Computed: true,
100+
Type: schema.TypeString,
101+
Description: "Type of invoice, either periodic or purchase",
102+
},
103+
"state": {
104+
Computed: true,
105+
Type: schema.TypeString,
106+
Description: "The state of the invoice",
65107
},
66108
"number": {
67-
Computed: true,
68-
Type: schema.TypeInt,
109+
Computed: true,
110+
Type: schema.TypeInt,
111+
Description: "The invoice number",
112+
},
113+
"seller_name": {
114+
Computed: true,
115+
Type: schema.TypeString,
116+
Description: "The name of the seller (Scaleway)",
69117
},
70118
},
71119
},
@@ -79,10 +127,10 @@ func dataSourceScalewayBillingInvoicesRead(ctx context.Context, d *schema.Resour
79127
api := billingAPI(meta)
80128

81129
res, err := api.ListInvoices(&billing.ListInvoicesRequest{
82-
OrganizationID: expandStringPtr(d.Get("organization_id")),
83-
StartedAfter: expandTimePtr(d.Get("started_after").(string)),
84-
StartedBefore: expandTimePtr(d.Get("started_before").(string)),
85-
InvoiceType: billing.InvoiceType(d.Get("invoice_type").(string)),
130+
OrganizationID: expandStringPtr(d.Get("organization_id")),
131+
BillingPeriodStartAfter: expandTimePtr(d.Get("started_after").(string)),
132+
BillingPeriodStartBefore: expandTimePtr(d.Get("started_before").(string)),
133+
InvoiceType: billing.InvoiceType(d.Get("invoice_type").(string)),
86134
}, scw.WithContext(ctx))
87135
if err != nil {
88136
return diag.FromErr(err)
@@ -92,13 +140,21 @@ func dataSourceScalewayBillingInvoicesRead(ctx context.Context, d *schema.Resour
92140
for _, invoice := range res.Invoices {
93141
rawInvoice := make(map[string]interface{})
94142
rawInvoice["id"] = invoice.ID
143+
rawInvoice["organization_name"] = invoice.OrganizationName
95144
rawInvoice["start_date"] = flattenTime(invoice.StartDate)
145+
rawInvoice["stop_date"] = flattenTime(invoice.StopDate)
146+
rawInvoice["billing_period"] = flattenTime(invoice.BillingPeriod)
96147
rawInvoice["issued_date"] = flattenTime(invoice.IssuedDate)
97148
rawInvoice["due_date"] = flattenTime(invoice.DueDate)
98149
rawInvoice["total_untaxed"] = invoice.TotalUntaxed.String()
99150
rawInvoice["total_taxed"] = invoice.TotalTaxed.String()
100-
rawInvoice["invoice_type"] = invoice.InvoiceType.String()
151+
rawInvoice["total_tax"] = invoice.TotalTax.String()
152+
rawInvoice["total_discount"] = invoice.TotalDiscount.String()
153+
rawInvoice["total_undiscount"] = invoice.TotalUndiscount.String()
154+
rawInvoice["invoice_type"] = invoice.Type.String()
155+
rawInvoice["state"] = invoice.State
101156
rawInvoice["number"] = invoice.Number
157+
rawInvoice["seller_name"] = invoice.SellerName
102158

103159
invoices = append(invoices, rawInvoice)
104160
}

scaleway/data_source_billing_invoices_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ func TestAccScalewayDataSourceBillingInvoices_Basic(t *testing.T) {
1919
data "scaleway_billing_invoices" "my-invoices" {}`,
2020
Check: resource.ComposeTestCheckFunc(
2121
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.id"),
22+
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.organization_name"),
2223
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.start_date"),
24+
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.stop_date"),
25+
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.billing_period"),
2326
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.total_untaxed"),
2427
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.total_taxed"),
28+
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.total_tax"),
29+
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.total_discount"),
30+
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.total_undiscount"),
2531
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.invoice_type"),
32+
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.state"),
2633
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.number"),
34+
resource.TestCheckResourceAttrSet("data.scaleway_billing_invoices.my-invoices", "invoices.0.seller_name"),
2735
),
2836
},
2937
},

scaleway/helpers_billing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scaleway
22

33
import (
4-
billing "github.com/scaleway/scaleway-sdk-go/api/billing/v2alpha1"
4+
billing "github.com/scaleway/scaleway-sdk-go/api/billing/v2beta1"
55
)
66

77
// billingAPI returns a new billing API.

0 commit comments

Comments
 (0)