Skip to content

Commit

Permalink
Belgium: Set GCP monthly budget alert
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea committed Mar 14, 2024
1 parent b19f07a commit 419a633
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
30 changes: 30 additions & 0 deletions environments/_modules/gateway/billing.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resource "google_billing_budget" "main" {
billing_account = var.gcp_billing_account_id
display_name = "${data.google_project.main.name} (managed by Terraform workspace ${terraform.workspace})"

budget_filter {
projects = ["projects/${data.google_project.main.number}"]
}

amount {
specified_amount {
units = var.gcp_billing_monthly_budget_usd
currency_code = "USD"
}
}

threshold_rules {
threshold_percent = 0.9
}
threshold_rules {
threshold_percent = 1.0
spend_basis = "FORECASTED_SPEND"
}

all_updates_rule {
monitoring_notification_channels = [for channel in google_monitoring_notification_channel.sres_email : channel.name]
disable_default_iam_recipients = true
}

depends_on = [google_project_service.services]
}
3 changes: 3 additions & 0 deletions environments/_modules/gateway/gcp.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "google_project" "main" {
project_id = var.gcp_project_id
}
1 change: 1 addition & 0 deletions environments/_modules/gateway/services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ locals {
"servicenetworking.googleapis.com",
"redis.googleapis.com",
"monitoring.googleapis.com",
"billingbudgets.googleapis.com",
]
}

Expand Down
3 changes: 3 additions & 0 deletions environments/_modules/gateway/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ variable "alert_email_addresses" {
type = list(string)
}

variable "gcp_billing_account_id" {}
variable "gcp_billing_monthly_budget_usd" {}

variable "gcp_shared_infra_project_id" {}
variable "gcp_project_id" {}
variable "gcp_region" {
Expand Down
8 changes: 5 additions & 3 deletions environments/belgium/gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ module "gateway" {
mongodbatlas_project_id = var.mongodbatlas_project_id
mongodbatlas_region = "WESTERN_EUROPE"

alert_email_addresses = var.alert_email_addresses
sre_iam_uri = var.sre_iam_uri

alert_email_addresses = var.alert_email_addresses
sre_iam_uri = var.sre_iam_uri
gcp_shared_infra_project_id = var.shared_infra_gcp_project_id

gcp_billing_monthly_budget_usd = 200
gcp_billing_account_id = var.gcp_billing_account_id
}
1 change: 1 addition & 0 deletions environments/belgium/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ variable "alert_email_addresses" {
type = list(string)
}

variable "gcp_billing_account_id" {}
variable "gcp_project_id" {}
variable "shared_infra_gcp_project_id" {}

Expand Down

0 comments on commit 419a633

Please sign in to comment.