From ea3961ce9b81c37e52577c70c781892eec260c03 Mon Sep 17 00:00:00 2001 From: Pedro Plassen Lopes Date: Wed, 2 Mar 2022 19:37:11 +0000 Subject: [PATCH] feat: expose spend_basis for budget alerts (#681) * add optional argument spend_basis to budget alert configuration * fmt main.tf * tmf and make generate doc * force pull request * regenerate README Co-authored-by: Bharath KKB --- README.md | 1 + main.tf | 1 + modules/budget/README.md | 1 + modules/budget/main.tf | 1 + modules/budget/variables.tf | 6 ++++++ variables.tf | 6 ++++++ 6 files changed, 16 insertions(+) diff --git a/README.md b/README.md index ee1a3626..665019bb 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ determining that location is as follows: | bucket\_ula | Enable Uniform Bucket Level Access | `bool` | `true` | no | | bucket\_versioning | Enable versioning for a GCS bucket to create (optional) | `bool` | `false` | no | | budget\_alert\_pubsub\_topic | The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}` | `string` | `null` | no | +| budget\_alert\_spend\_basis | The type of basis used to determine if spend has passed the threshold | `string` | `"CURRENT_SPEND"` | no | | budget\_alert\_spent\_percents | A list of percentages of the budget to alert on when threshold is exceeded | `list(number)` |
[
0.5,
0.7,
1
]
| no | | budget\_amount | The amount to use for a budget alert | `number` | `null` | no | | budget\_display\_name | The display name of the budget. If not set defaults to `Budget For ` | `string` | `null` | no | diff --git a/main.tf b/main.tf index c4d13416..a7c04a15 100644 --- a/main.tf +++ b/main.tf @@ -93,6 +93,7 @@ module "budget" { billing_account = var.billing_account amount = var.budget_amount alert_spent_percents = var.budget_alert_spent_percents + alert_spend_basis = var.budget_alert_spend_basis alert_pubsub_topic = var.budget_alert_pubsub_topic monitoring_notification_channels = var.budget_monitoring_notification_channels display_name = var.budget_display_name != null ? var.budget_display_name : null diff --git a/modules/budget/README.md b/modules/budget/README.md index bdbec78a..8a252593 100644 --- a/modules/budget/README.md +++ b/modules/budget/README.md @@ -21,6 +21,7 @@ module "project_myproject" { | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | alert\_pubsub\_topic | The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}` | `string` | `null` | no | +| alert\_spend\_basis | The type of basis used to determine if spend has passed the threshold | `string` | `"CURRENT_SPEND"` | no | | alert\_spent\_percents | A list of percentages of the budget to alert on when threshold is exceeded | `list(number)` |
[
0.5,
0.7,
1
]
| no | | amount | The amount to use as the budget | `number` | n/a | yes | | billing\_account | ID of the billing account to set a budget on | `string` | n/a | yes | diff --git a/modules/budget/main.tf b/modules/budget/main.tf index cfdcd5ef..4cfb2427 100644 --- a/modules/budget/main.tf +++ b/modules/budget/main.tf @@ -58,6 +58,7 @@ resource "google_billing_budget" "budget" { for_each = var.alert_spent_percents content { threshold_percent = threshold_rules.value + spend_basis = var.alert_spend_basis } } diff --git a/modules/budget/variables.tf b/modules/budget/variables.tf index 6ef64d79..cf75572b 100644 --- a/modules/budget/variables.tf +++ b/modules/budget/variables.tf @@ -59,6 +59,12 @@ variable "alert_spent_percents" { default = [0.5, 0.7, 1.0] } +variable "alert_spend_basis" { + description = "The type of basis used to determine if spend has passed the threshold" + type = string + default = "CURRENT_SPEND" +} + variable "alert_pubsub_topic" { description = "The name of the Cloud Pub/Sub topic where budget related messages will be published, in the form of `projects/{project_id}/topics/{topic_id}`" type = string diff --git a/variables.tf b/variables.tf index eb7eeec1..242f23c6 100644 --- a/variables.tf +++ b/variables.tf @@ -241,6 +241,12 @@ variable "budget_alert_spent_percents" { default = [0.5, 0.7, 1.0] } +variable "budget_alert_spend_basis" { + description = "The type of basis used to determine if spend has passed the threshold" + type = string + default = "CURRENT_SPEND" +} + variable "budget_labels" { description = "A single label and value pair specifying that usage from only this set of labeled resources should be included in the budget." type = map(string)