forked from 2i2c-org/infrastructure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 2i2c-org#4415 from consideRatio/pr/gcp-terraform-b…
…udgets terraform, gcp: use dynamic budgets based on last month
- Loading branch information
Showing
14 changed files
with
32 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,60 @@ | ||
# Alerts sent to [email protected] for things that *will go bad* in the future | ||
# if left unattended. Should *not* be used for immediate outages | ||
# Alerts sent to support+budget-${var.prefix}@2i2c.org for things that *will go | ||
# bad* in the future if left unattended. Should *not* be used for immediate | ||
# outages | ||
|
||
data "google_project" "project" { | ||
project_id = var.project_id | ||
} | ||
|
||
resource "google_monitoring_notification_channel" "support_email" { | ||
count = var.budget_alert_enabled ? 1 : 0 | ||
project = var.project_id | ||
display_name = "[email protected] email" | ||
display_name = "Email support+budget-${var.prefix}@2i2c.org" | ||
type = "email" | ||
labels = { | ||
email_address = "[email protected]" | ||
email_address = "support+budget-${var.prefix}@2i2c.org" | ||
} | ||
} | ||
|
||
data "google_project" "project" { | ||
project_id = var.project_id | ||
} | ||
|
||
# Need to explicitly enable https://console.cloud.google.com/apis/library/billingbudgets.googleapis.com?project=two-eye-two-see | ||
resource "google_billing_budget" "budget" { | ||
# resource ref: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/billing_budget | ||
resource "google_billing_budget" "budgets" { | ||
count = var.budget_alert_enabled ? 1 : 0 | ||
|
||
billing_account = var.billing_account_id | ||
display_name = "Billing alert" | ||
display_name = "Auto-adjusting budget for ${var.prefix}" | ||
|
||
all_updates_rule { | ||
monitoring_notification_channels = [ | ||
google_monitoring_notification_channel.support_email[0].id, | ||
] | ||
disable_default_iam_recipients = true | ||
} | ||
|
||
budget_filter { | ||
# Use project number here, as project_name seems to be converted internally to number | ||
# If we don't do this, `terraform apply` is not clean | ||
# This is a bug in the google provider / budgets API https://github.com/hashicorp/terraform-provider-google/issues/8444 | ||
projects = ["projects/${data.google_project.project.number}"] | ||
credit_types_treatment = "INCLUDE_ALL_CREDITS" | ||
calendar_period = "MONTH" | ||
} | ||
|
||
amount { | ||
specified_amount { | ||
currency_code = var.budget_alert_currency | ||
units = var.budget_alert_amount | ||
} | ||
last_period_amount = true | ||
} | ||
|
||
all_updates_rule { | ||
monitoring_notification_channels = [ | ||
google_monitoring_notification_channel.support_email[0].id, | ||
] | ||
disable_default_iam_recipients = true | ||
} | ||
# NOTE: These threshold_rules *MUST BE ORDERED BY threshold_percent* in ascending order! | ||
# If not, we'll run into https://github.com/hashicorp/terraform-provider-google/issues/8444 | ||
# and terraform apply won't be clean. | ||
threshold_rules { | ||
# Alert when *actual* spend reached 80% of budget | ||
threshold_percent = 1.0 | ||
# Alert when *actual* spend reached 120% of budget (last month's spend) | ||
threshold_percent = 1.2 | ||
spend_basis = "CURRENT_SPEND" | ||
} | ||
threshold_rules { | ||
# Alert when *forecasted* spend is about to blow over our budget | ||
# Adding the extra 1% to help terraform not redo this each time. | ||
threshold_percent = 1.01 | ||
# Alert when *forecasted* spend reached 120% of budget (last month's spend) | ||
threshold_percent = 1.2 | ||
spend_basis = "FORECASTED_SPEND" | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ region = "{{ cluster_region }}" | |
|
||
# Config required to enable automatic budget alerts to be sent to [email protected] | ||
budget_alert_enabled = false | ||
budget_alert_amount = "" | ||
billing_account_id = "" | ||
|
||
# TODO: Before applying this, identify a k8s version to specify. Pick the latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters