Skip to content

Commit aa738f8

Browse files
billingbudget: make threshold optional (#6259) (#12087)
Signed-off-by: Modular Magician <[email protected]>
1 parent 90267ea commit aa738f8

File tree

4 files changed

+105
-46
lines changed

4 files changed

+105
-46
lines changed

.changelog/6259.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
billingbudget: made `thresholdRules` optional in `google_billing_budget`
3+
```

google/resource_billing_budget.go

+26-25
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,6 @@ is "USD", then 1 unit is one US dollar.`,
125125
ForceNew: true,
126126
Description: `ID of the billing account to set a budget on.`,
127127
},
128-
"threshold_rules": {
129-
Type: schema.TypeList,
130-
Required: true,
131-
Description: `Rules that trigger alerts (notifications of thresholds being
132-
crossed) when spend exceeds the specified percentages of the
133-
budget.`,
134-
Elem: &schema.Resource{
135-
Schema: map[string]*schema.Schema{
136-
"threshold_percent": {
137-
Type: schema.TypeFloat,
138-
Required: true,
139-
Description: `Send an alert when this threshold is exceeded. This is a
140-
1.0-based percentage, so 0.5 = 50%. Must be >= 0.`,
141-
},
142-
"spend_basis": {
143-
Type: schema.TypeString,
144-
Optional: true,
145-
ValidateFunc: validateEnum([]string{"CURRENT_SPEND", "FORECASTED_SPEND", ""}),
146-
Description: `The type of basis used to determine if spend has passed
147-
the threshold. Default value: "CURRENT_SPEND" Possible values: ["CURRENT_SPEND", "FORECASTED_SPEND"]`,
148-
Default: "CURRENT_SPEND",
149-
},
150-
},
151-
},
152-
},
153128
"all_updates_rule": {
154129
Type: schema.TypeList,
155130
Optional: true,
@@ -175,6 +150,7 @@ Account Users IAM roles for the target account.`,
175150
channel in the form
176151
projects/{project_id}/notificationChannels/{channel_id}.
177152
A maximum of 5 channels are allowed.`,
153+
MaxItems: 5,
178154
Elem: &schema.Schema{
179155
Type: schema.TypeString,
180156
},
@@ -374,6 +350,31 @@ account and all subaccounts, if they exist.`,
374350
Optional: true,
375351
Description: `User data for display name in UI. Must be <= 60 chars.`,
376352
},
353+
"threshold_rules": {
354+
Type: schema.TypeList,
355+
Optional: true,
356+
Description: `Rules that trigger alerts (notifications of thresholds being
357+
crossed) when spend exceeds the specified percentages of the
358+
budget.`,
359+
Elem: &schema.Resource{
360+
Schema: map[string]*schema.Schema{
361+
"threshold_percent": {
362+
Type: schema.TypeFloat,
363+
Required: true,
364+
Description: `Send an alert when this threshold is exceeded. This is a
365+
1.0-based percentage, so 0.5 = 50%. Must be >= 0.`,
366+
},
367+
"spend_basis": {
368+
Type: schema.TypeString,
369+
Optional: true,
370+
ValidateFunc: validateEnum([]string{"CURRENT_SPEND", "FORECASTED_SPEND", ""}),
371+
Description: `The type of basis used to determine if spend has passed
372+
the threshold. Default value: "CURRENT_SPEND" Possible values: ["CURRENT_SPEND", "FORECASTED_SPEND"]`,
373+
Default: "CURRENT_SPEND",
374+
},
375+
},
376+
},
377+
},
377378
"name": {
378379
Type: schema.TypeString,
379380
Computed: true,

google/resource_billing_budget_generated_test.go

+55
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,61 @@ resource "google_billing_budget" "budget" {
343343
`, context)
344344
}
345345

346+
func TestAccBillingBudget_billingBudgetOptionalExample(t *testing.T) {
347+
t.Parallel()
348+
349+
context := map[string]interface{}{
350+
"billing_acct": getTestBillingAccountFromEnv(t),
351+
"random_suffix": randString(t, 10),
352+
}
353+
354+
vcrTest(t, resource.TestCase{
355+
PreCheck: func() { testAccPreCheck(t) },
356+
Providers: testAccProviders,
357+
CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t),
358+
Steps: []resource.TestStep{
359+
{
360+
Config: testAccBillingBudget_billingBudgetOptionalExample(context),
361+
},
362+
{
363+
ResourceName: "google_billing_budget.budget",
364+
ImportState: true,
365+
ImportStateVerify: true,
366+
ImportStateVerifyIgnore: []string{"billing_account"},
367+
},
368+
},
369+
})
370+
}
371+
372+
func testAccBillingBudget_billingBudgetOptionalExample(context map[string]interface{}) string {
373+
return Nprintf(`
374+
data "google_billing_account" "account" {
375+
billing_account = "%{billing_acct}"
376+
}
377+
378+
resource "google_billing_budget" "budget" {
379+
billing_account = data.google_billing_account.account.id
380+
display_name = "Example Billing Budget%{random_suffix}"
381+
382+
amount {
383+
specified_amount {
384+
currency_code = "USD"
385+
units = "100000"
386+
}
387+
}
388+
389+
all_updates_rule {
390+
disable_default_iam_recipients = true
391+
pubsub_topic = google_pubsub_topic.budget.id
392+
}
393+
}
394+
395+
resource "google_pubsub_topic" "budget" {
396+
name = "tf-test-example-topic%{random_suffix}"
397+
}
398+
`, context)
399+
}
400+
346401
func testAccCheckBillingBudgetDestroyProducer(t *testing.T) func(s *terraform.State) error {
347402
return func(s *terraform.State) error {
348403
for name, rs := range s.RootModule().Resources {

website/docs/r/billing_budget.html.markdown

+21-21
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,6 @@ The following arguments are supported:
238238
The budgeted amount for each usage period.
239239
Structure is [documented below](#nested_amount).
240240

241-
* `threshold_rules` -
242-
(Required)
243-
Rules that trigger alerts (notifications of thresholds being
244-
crossed) when spend exceeds the specified percentages of the
245-
budget.
246-
Structure is [documented below](#nested_threshold_rules).
247-
248241
* `billing_account` -
249242
(Required)
250243
ID of the billing account to set a budget on.
@@ -288,20 +281,6 @@ The following arguments are supported:
288281
zero. For example $-1.75 is represented as units=-1 and
289282
nanos=-750,000,000.
290283

291-
<a name="nested_threshold_rules"></a>The `threshold_rules` block supports:
292-
293-
* `threshold_percent` -
294-
(Required)
295-
Send an alert when this threshold is exceeded. This is a
296-
1.0-based percentage, so 0.5 = 50%. Must be >= 0.
297-
298-
* `spend_basis` -
299-
(Optional)
300-
The type of basis used to determine if spend has passed
301-
the threshold.
302-
Default value is `CURRENT_SPEND`.
303-
Possible values are `CURRENT_SPEND` and `FORECASTED_SPEND`.
304-
305284
- - -
306285

307286

@@ -315,6 +294,13 @@ The following arguments are supported:
315294
spend against the budget.
316295
Structure is [documented below](#nested_budget_filter).
317296

297+
* `threshold_rules` -
298+
(Optional)
299+
Rules that trigger alerts (notifications of thresholds being
300+
crossed) when spend exceeds the specified percentages of the
301+
budget.
302+
Structure is [documented below](#nested_threshold_rules).
303+
318304
* `all_updates_rule` -
319305
(Optional)
320306
Defines notifications that are sent on every update to the
@@ -427,6 +413,20 @@ The following arguments are supported:
427413
(Required)
428414
Day of a month. Must be from 1 to 31 and valid for the year and month.
429415

416+
<a name="nested_threshold_rules"></a>The `threshold_rules` block supports:
417+
418+
* `threshold_percent` -
419+
(Required)
420+
Send an alert when this threshold is exceeded. This is a
421+
1.0-based percentage, so 0.5 = 50%. Must be >= 0.
422+
423+
* `spend_basis` -
424+
(Optional)
425+
The type of basis used to determine if spend has passed
426+
the threshold.
427+
Default value is `CURRENT_SPEND`.
428+
Possible values are `CURRENT_SPEND` and `FORECASTED_SPEND`.
429+
430430
<a name="nested_all_updates_rule"></a>The `all_updates_rule` block supports:
431431

432432
* `pubsub_topic` -

0 commit comments

Comments
 (0)