Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

billingbudget: make threshold optional #12087

Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .changelog/6259.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
billingbudget: made `thresholdRules` optional in `google_billing_budget`
```
51 changes: 26 additions & 25 deletions google/resource_billing_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,6 @@ is "USD", then 1 unit is one US dollar.`,
ForceNew: true,
Description: `ID of the billing account to set a budget on.`,
},
"threshold_rules": {
Type: schema.TypeList,
Required: true,
Description: `Rules that trigger alerts (notifications of thresholds being
crossed) when spend exceeds the specified percentages of the
budget.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"threshold_percent": {
Type: schema.TypeFloat,
Required: true,
Description: `Send an alert when this threshold is exceeded. This is a
1.0-based percentage, so 0.5 = 50%. Must be >= 0.`,
},
"spend_basis": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateEnum([]string{"CURRENT_SPEND", "FORECASTED_SPEND", ""}),
Description: `The type of basis used to determine if spend has passed
the threshold. Default value: "CURRENT_SPEND" Possible values: ["CURRENT_SPEND", "FORECASTED_SPEND"]`,
Default: "CURRENT_SPEND",
},
},
},
},
"all_updates_rule": {
Type: schema.TypeList,
Optional: true,
Expand All @@ -175,6 +150,7 @@ Account Users IAM roles for the target account.`,
channel in the form
projects/{project_id}/notificationChannels/{channel_id}.
A maximum of 5 channels are allowed.`,
MaxItems: 5,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down Expand Up @@ -374,6 +350,31 @@ account and all subaccounts, if they exist.`,
Optional: true,
Description: `User data for display name in UI. Must be <= 60 chars.`,
},
"threshold_rules": {
Type: schema.TypeList,
Optional: true,
Description: `Rules that trigger alerts (notifications of thresholds being
crossed) when spend exceeds the specified percentages of the
budget.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"threshold_percent": {
Type: schema.TypeFloat,
Required: true,
Description: `Send an alert when this threshold is exceeded. This is a
1.0-based percentage, so 0.5 = 50%. Must be >= 0.`,
},
"spend_basis": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateEnum([]string{"CURRENT_SPEND", "FORECASTED_SPEND", ""}),
Description: `The type of basis used to determine if spend has passed
the threshold. Default value: "CURRENT_SPEND" Possible values: ["CURRENT_SPEND", "FORECASTED_SPEND"]`,
Default: "CURRENT_SPEND",
},
},
},
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down
55 changes: 55 additions & 0 deletions google/resource_billing_budget_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,61 @@ resource "google_billing_budget" "budget" {
`, context)
}

func TestAccBillingBudget_billingBudgetOptionalExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"billing_acct": getTestBillingAccountFromEnv(t),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBillingBudgetDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBillingBudget_billingBudgetOptionalExample(context),
},
{
ResourceName: "google_billing_budget.budget",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"billing_account"},
},
},
})
}

func testAccBillingBudget_billingBudgetOptionalExample(context map[string]interface{}) string {
return Nprintf(`
data "google_billing_account" "account" {
billing_account = "%{billing_acct}"
}

resource "google_billing_budget" "budget" {
billing_account = data.google_billing_account.account.id
display_name = "Example Billing Budget%{random_suffix}"

amount {
specified_amount {
currency_code = "USD"
units = "100000"
}
}

all_updates_rule {
disable_default_iam_recipients = true
pubsub_topic = google_pubsub_topic.budget.id
}
}

resource "google_pubsub_topic" "budget" {
name = "tf-test-example-topic%{random_suffix}"
}
`, context)
}

func testAccCheckBillingBudgetDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
42 changes: 21 additions & 21 deletions website/docs/r/billing_budget.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,6 @@ The following arguments are supported:
The budgeted amount for each usage period.
Structure is [documented below](#nested_amount).

* `threshold_rules` -
(Required)
Rules that trigger alerts (notifications of thresholds being
crossed) when spend exceeds the specified percentages of the
budget.
Structure is [documented below](#nested_threshold_rules).

* `billing_account` -
(Required)
ID of the billing account to set a budget on.
Expand Down Expand Up @@ -288,20 +281,6 @@ The following arguments are supported:
zero. For example $-1.75 is represented as units=-1 and
nanos=-750,000,000.

<a name="nested_threshold_rules"></a>The `threshold_rules` block supports:

* `threshold_percent` -
(Required)
Send an alert when this threshold is exceeded. This is a
1.0-based percentage, so 0.5 = 50%. Must be >= 0.

* `spend_basis` -
(Optional)
The type of basis used to determine if spend has passed
the threshold.
Default value is `CURRENT_SPEND`.
Possible values are `CURRENT_SPEND` and `FORECASTED_SPEND`.

- - -


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

* `threshold_rules` -
(Optional)
Rules that trigger alerts (notifications of thresholds being
crossed) when spend exceeds the specified percentages of the
budget.
Structure is [documented below](#nested_threshold_rules).

* `all_updates_rule` -
(Optional)
Defines notifications that are sent on every update to the
Expand Down Expand Up @@ -427,6 +413,20 @@ The following arguments are supported:
(Required)
Day of a month. Must be from 1 to 31 and valid for the year and month.

<a name="nested_threshold_rules"></a>The `threshold_rules` block supports:

* `threshold_percent` -
(Required)
Send an alert when this threshold is exceeded. This is a
1.0-based percentage, so 0.5 = 50%. Must be >= 0.

* `spend_basis` -
(Optional)
The type of basis used to determine if spend has passed
the threshold.
Default value is `CURRENT_SPEND`.
Possible values are `CURRENT_SPEND` and `FORECASTED_SPEND`.

<a name="nested_all_updates_rule"></a>The `all_updates_rule` block supports:

* `pubsub_topic` -
Expand Down