Skip to content

Commit

Permalink
feat: expose spend_basis for budget alerts (#681)
Browse files Browse the repository at this point in the history
* 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 <bharathkrishnakb@gmail.com>
  • Loading branch information
plassen and bharathkkb committed Mar 2, 2022
1 parent cb56c27 commit ea3961c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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)` | <pre>[<br> 0.5,<br> 0.7,<br> 1<br>]</pre> | 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 <projects[0]|All Projects>` | `string` | `null` | no |
Expand Down
1 change: 1 addition & 0 deletions main.tf
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/budget/README.md
Expand Up @@ -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)` | <pre>[<br> 0.5,<br> 0.7,<br> 1<br>]</pre> | 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 |
Expand Down
1 change: 1 addition & 0 deletions modules/budget/main.tf
Expand Up @@ -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
}
}

Expand Down
6 changes: 6 additions & 0 deletions modules/budget/variables.tf
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Expand Up @@ -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)
Expand Down

0 comments on commit ea3961c

Please sign in to comment.