Skip to content

Commit

Permalink
terraform, gcp: micro refactor by reordering in one file
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jul 11, 2024
1 parent cc6b571 commit bc1f9e1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions terraform/gcp/budget-alerts.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# 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
Expand All @@ -12,10 +16,6 @@ resource "google_monitoring_notification_channel" "support_email" {
}
}

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 ref: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/billing_budget
resource "google_billing_budget" "budget" {
Expand All @@ -24,6 +24,13 @@ resource "google_billing_budget" "budget" {
billing_account = var.billing_account_id
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
Expand All @@ -37,13 +44,6 @@ resource "google_billing_budget" "budget" {
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.
Expand Down

0 comments on commit bc1f9e1

Please sign in to comment.