2023-01-30 22:54:53 +01:00
|
|
|
#todo fix billing alert creation
|
2023-05-26 12:15:44 +02:00
|
|
|
#todo do not create billing if option in variables is off
|
2022-11-23 12:21:10 +01:00
|
|
|
|
2023-01-30 22:54:53 +01:00
|
|
|
resource "google_billing_budget" "budget" {
|
2023-05-26 12:15:44 +02:00
|
|
|
billing_account = data.google_project.current_project.billing_account
|
2023-01-30 22:54:53 +01:00
|
|
|
display_name = "budget"
|
|
|
|
amount {
|
|
|
|
specified_amount {
|
|
|
|
currency_code = "USD"
|
|
|
|
units = var.billing-budget
|
|
|
|
}
|
|
|
|
}
|
2023-05-26 12:15:44 +02:00
|
|
|
|
2022-11-23 12:21:10 +01:00
|
|
|
|
2023-01-30 22:54:53 +01:00
|
|
|
budget_filter {
|
2023-05-26 12:15:44 +02:00
|
|
|
projects = ["projects/${data.google_project.current_project.number}"]
|
2023-01-30 22:54:53 +01:00
|
|
|
credit_types_treatment = "EXCLUDE_ALL_CREDITS"
|
2023-05-26 12:15:44 +02:00
|
|
|
calendar_period = "MONTH"
|
2023-01-30 22:54:53 +01:00
|
|
|
#services = ["services/24E6-581D-38E5"] # Bigquery
|
|
|
|
}
|
2022-11-23 12:21:10 +01:00
|
|
|
|
2023-01-30 22:54:53 +01:00
|
|
|
threshold_rules {
|
|
|
|
threshold_percent = 0.5
|
|
|
|
}
|
|
|
|
threshold_rules {
|
|
|
|
threshold_percent = 0.9
|
|
|
|
}
|
|
|
|
threshold_rules {
|
|
|
|
threshold_percent = 1.0
|
|
|
|
}
|
2022-11-23 12:21:10 +01:00
|
|
|
|
2023-05-26 12:15:44 +02:00
|
|
|
#TODO add if not empty billing admins var. Else use default admins
|
2023-01-30 22:54:53 +01:00
|
|
|
all_updates_rule {
|
|
|
|
monitoring_notification_channels = [
|
|
|
|
for k, v in google_monitoring_notification_channel.notification_channel : google_monitoring_notification_channel.notification_channel[k].id
|
|
|
|
]
|
2023-05-26 12:15:44 +02:00
|
|
|
disable_default_iam_recipients = length(var.billing-admins) < 1 ? false : true
|
2023-01-30 22:54:53 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-23 12:21:10 +01:00
|
|
|
|
2023-01-30 22:54:53 +01:00
|
|
|
resource "google_monitoring_notification_channel" "notification_channel" {
|
|
|
|
for_each = var.billing-admins
|
|
|
|
display_name = each.key
|
|
|
|
type = "email"
|
2022-11-23 12:21:10 +01:00
|
|
|
|
2023-01-30 22:54:53 +01:00
|
|
|
labels = {
|
|
|
|
email_address = each.value
|
|
|
|
}
|
|
|
|
}
|