Skip to content

Commit 8a4c106

Browse files
feat: change budget alerts to alarm by forecast (#1037)
1 parent 27a7427 commit 8a4c106

File tree

17 files changed

+80
-46
lines changed

17 files changed

+80
-46
lines changed

1-org/envs/shared/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
| log\_export\_storage\_location | The location of the storage bucket used to export logs. | `string` | `"US"` | no |
2323
| log\_export\_storage\_retention\_policy | Configuration of the bucket's data retention policy for how long objects in the bucket should be retained. | <pre>object({<br> is_locked = bool<br> retention_period_days = number<br> })</pre> | `null` | no |
2424
| log\_export\_storage\_versioning | (Optional) Toggles bucket versioning, ability to retain a non-current object version when the live object version gets replaced or deleted. | `bool` | `false` | no |
25-
| project\_budget | Budget configuration for projects.<br> budget\_amount: The amount to use as the budget.<br> alert\_spent\_percents: A list of percentages of the budget to alert on when threshold is exceeded.<br> 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}`. | <pre>object({<br> dns_hub_budget_amount = optional(number, 1000)<br> dns_hub_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> dns_hub_alert_pubsub_topic = optional(string, null)<br> base_net_hub_budget_amount = optional(number, 1000)<br> base_net_hub_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> base_net_hub_alert_pubsub_topic = optional(string, null)<br> restricted_net_hub_budget_amount = optional(number, 1000)<br> restricted_net_hub_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> restricted_net_hub_alert_pubsub_topic = optional(string, null)<br> interconnect_budget_amount = optional(number, 1000)<br> interconnect_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> interconnect_alert_pubsub_topic = optional(string, null)<br> org_secrets_budget_amount = optional(number, 1000)<br> org_secrets_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> org_secrets_alert_pubsub_topic = optional(string, null)<br> org_billing_logs_budget_amount = optional(number, 1000)<br> org_billing_logs_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> org_billing_logs_alert_pubsub_topic = optional(string, null)<br> org_audit_logs_budget_amount = optional(number, 1000)<br> org_audit_logs_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> org_audit_logs_alert_pubsub_topic = optional(string, null)<br> scc_notifications_budget_amount = optional(number, 1000)<br> scc_notifications_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> scc_notifications_alert_pubsub_topic = optional(string, null)<br> })</pre> | `{}` | no |
25+
| project\_budget | Budget configuration for projects.<br> budget\_amount: The amount to use as the budget.<br> alert\_spent\_percents: A list of percentages of the budget to alert on when threshold is exceeded.<br> 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}`.<br> alert\_spend\_basis: The type of basis used to determine if spend has passed the threshold. Possible choices are `CURRENT_SPEND` or `FORECASTED_SPEND` (default). | <pre>object({<br> dns_hub_budget_amount = optional(number, 1000)<br> dns_hub_alert_spent_percents = optional(list(number), [1.2])<br> dns_hub_alert_pubsub_topic = optional(string, null)<br> dns_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> base_net_hub_budget_amount = optional(number, 1000)<br> base_net_hub_alert_spent_percents = optional(list(number), [1.2])<br> base_net_hub_alert_pubsub_topic = optional(string, null)<br> base_net_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> restricted_net_hub_budget_amount = optional(number, 1000)<br> restricted_net_hub_alert_spent_percents = optional(list(number), [1.2])<br> restricted_net_hub_alert_pubsub_topic = optional(string, null)<br> restricted_net_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> interconnect_budget_amount = optional(number, 1000)<br> interconnect_alert_spent_percents = optional(list(number), [1.2])<br> interconnect_alert_pubsub_topic = optional(string, null)<br> interconnect_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_secrets_budget_amount = optional(number, 1000)<br> org_secrets_alert_spent_percents = optional(list(number), [1.2])<br> org_secrets_alert_pubsub_topic = optional(string, null)<br> org_secrets_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_billing_logs_budget_amount = optional(number, 1000)<br> org_billing_logs_alert_spent_percents = optional(list(number), [1.2])<br> org_billing_logs_alert_pubsub_topic = optional(string, null)<br> org_billing_logs_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> org_audit_logs_budget_amount = optional(number, 1000)<br> org_audit_logs_alert_spent_percents = optional(list(number), [1.2])<br> org_audit_logs_alert_pubsub_topic = optional(string, null)<br> org_audit_logs_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> scc_notifications_budget_amount = optional(number, 1000)<br> scc_notifications_alert_spent_percents = optional(list(number), [1.2])<br> scc_notifications_alert_pubsub_topic = optional(string, null)<br> scc_notifications_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> })</pre> | `{}` | no |
2626
| remote\_state\_bucket | Backend bucket to load Terraform Remote State Data from previous steps. | `string` | n/a | yes |
2727
| scc\_notification\_filter | Filter used to create the Security Command Center Notification, you can see more details on how to create filters in https://cloud.google.com/security-command-center/docs/how-to-api-filter-notifications#create-filter | `string` | `"state = \"ACTIVE\""` | no |
2828
| scc\_notification\_name | Name of the Security Command Center Notification. It must be unique in the organization. Run `gcloud scc notifications describe <scc_notification_name> --organization=org_id` to check if it already exists. | `string` | n/a | yes |

1-org/envs/shared/projects.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module "org_audit_logs" {
5252
budget_alert_pubsub_topic = var.project_budget.org_audit_logs_alert_pubsub_topic
5353
budget_alert_spent_percents = var.project_budget.org_audit_logs_alert_spent_percents
5454
budget_amount = var.project_budget.org_audit_logs_budget_amount
55+
budget_alert_spend_basis = var.project_budget.org_audit_logs_budget_alert_spend_basis
5556
}
5657

5758
module "org_billing_logs" {
@@ -79,6 +80,7 @@ module "org_billing_logs" {
7980
budget_alert_pubsub_topic = var.project_budget.org_billing_logs_alert_pubsub_topic
8081
budget_alert_spent_percents = var.project_budget.org_billing_logs_alert_spent_percents
8182
budget_amount = var.project_budget.org_billing_logs_budget_amount
83+
budget_alert_spend_basis = var.project_budget.org_billing_logs_budget_alert_spend_basis
8284
}
8385

8486
/******************************************
@@ -110,6 +112,7 @@ module "org_secrets" {
110112
budget_alert_pubsub_topic = var.project_budget.org_secrets_alert_pubsub_topic
111113
budget_alert_spent_percents = var.project_budget.org_secrets_alert_spent_percents
112114
budget_amount = var.project_budget.org_secrets_budget_amount
115+
budget_alert_spend_basis = var.project_budget.org_secrets_budget_alert_spend_basis
113116
}
114117

115118
/******************************************
@@ -141,6 +144,7 @@ module "interconnect" {
141144
budget_alert_pubsub_topic = var.project_budget.interconnect_alert_pubsub_topic
142145
budget_alert_spent_percents = var.project_budget.interconnect_alert_spent_percents
143146
budget_amount = var.project_budget.interconnect_budget_amount
147+
budget_alert_spend_basis = var.project_budget.interconnect_budget_alert_spend_basis
144148
}
145149

146150
/******************************************
@@ -172,6 +176,7 @@ module "scc_notifications" {
172176
budget_alert_pubsub_topic = var.project_budget.scc_notifications_alert_pubsub_topic
173177
budget_alert_spent_percents = var.project_budget.scc_notifications_alert_spent_percents
174178
budget_amount = var.project_budget.scc_notifications_budget_amount
179+
budget_alert_spend_basis = var.project_budget.scc_notifications_budget_alert_spend_basis
175180
}
176181

177182
/******************************************
@@ -211,6 +216,7 @@ module "dns_hub" {
211216
budget_alert_pubsub_topic = var.project_budget.dns_hub_alert_pubsub_topic
212217
budget_alert_spent_percents = var.project_budget.dns_hub_alert_spent_percents
213218
budget_amount = var.project_budget.dns_hub_budget_amount
219+
budget_alert_spend_basis = var.project_budget.dns_hub_budget_alert_spend_basis
214220
}
215221

216222
/******************************************
@@ -251,6 +257,7 @@ module "base_network_hub" {
251257
budget_alert_pubsub_topic = var.project_budget.base_net_hub_alert_pubsub_topic
252258
budget_alert_spent_percents = var.project_budget.base_net_hub_alert_spent_percents
253259
budget_amount = var.project_budget.base_net_hub_budget_amount
260+
budget_alert_spend_basis = var.project_budget.base_net_hub_budget_alert_spend_basis
254261
}
255262

256263
resource "google_project_iam_member" "network_sa_base" {
@@ -299,6 +306,7 @@ module "restricted_network_hub" {
299306
budget_alert_pubsub_topic = var.project_budget.restricted_net_hub_alert_pubsub_topic
300307
budget_alert_spent_percents = var.project_budget.restricted_net_hub_alert_spent_percents
301308
budget_amount = var.project_budget.restricted_net_hub_budget_amount
309+
budget_alert_spend_basis = var.project_budget.restricted_net_hub_budget_alert_spend_basis
302310
}
303311

304312
resource "google_project_iam_member" "network_sa_restricted" {

1-org/envs/shared/variables.tf

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,32 +115,41 @@ variable "project_budget" {
115115
budget_amount: The amount to use as the budget.
116116
alert_spent_percents: A list of percentages of the budget to alert on when threshold is exceeded.
117117
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}`.
118+
alert_spend_basis: The type of basis used to determine if spend has passed the threshold. Possible choices are `CURRENT_SPEND` or `FORECASTED_SPEND` (default).
118119
EOT
119120
type = object({
120-
dns_hub_budget_amount = optional(number, 1000)
121-
dns_hub_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])
122-
dns_hub_alert_pubsub_topic = optional(string, null)
123-
base_net_hub_budget_amount = optional(number, 1000)
124-
base_net_hub_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])
125-
base_net_hub_alert_pubsub_topic = optional(string, null)
126-
restricted_net_hub_budget_amount = optional(number, 1000)
127-
restricted_net_hub_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])
128-
restricted_net_hub_alert_pubsub_topic = optional(string, null)
129-
interconnect_budget_amount = optional(number, 1000)
130-
interconnect_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])
131-
interconnect_alert_pubsub_topic = optional(string, null)
132-
org_secrets_budget_amount = optional(number, 1000)
133-
org_secrets_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])
134-
org_secrets_alert_pubsub_topic = optional(string, null)
135-
org_billing_logs_budget_amount = optional(number, 1000)
136-
org_billing_logs_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])
137-
org_billing_logs_alert_pubsub_topic = optional(string, null)
138-
org_audit_logs_budget_amount = optional(number, 1000)
139-
org_audit_logs_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])
140-
org_audit_logs_alert_pubsub_topic = optional(string, null)
141-
scc_notifications_budget_amount = optional(number, 1000)
142-
scc_notifications_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])
143-
scc_notifications_alert_pubsub_topic = optional(string, null)
121+
dns_hub_budget_amount = optional(number, 1000)
122+
dns_hub_alert_spent_percents = optional(list(number), [1.2])
123+
dns_hub_alert_pubsub_topic = optional(string, null)
124+
dns_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
125+
base_net_hub_budget_amount = optional(number, 1000)
126+
base_net_hub_alert_spent_percents = optional(list(number), [1.2])
127+
base_net_hub_alert_pubsub_topic = optional(string, null)
128+
base_net_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
129+
restricted_net_hub_budget_amount = optional(number, 1000)
130+
restricted_net_hub_alert_spent_percents = optional(list(number), [1.2])
131+
restricted_net_hub_alert_pubsub_topic = optional(string, null)
132+
restricted_net_hub_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
133+
interconnect_budget_amount = optional(number, 1000)
134+
interconnect_alert_spent_percents = optional(list(number), [1.2])
135+
interconnect_alert_pubsub_topic = optional(string, null)
136+
interconnect_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
137+
org_secrets_budget_amount = optional(number, 1000)
138+
org_secrets_alert_spent_percents = optional(list(number), [1.2])
139+
org_secrets_alert_pubsub_topic = optional(string, null)
140+
org_secrets_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
141+
org_billing_logs_budget_amount = optional(number, 1000)
142+
org_billing_logs_alert_spent_percents = optional(list(number), [1.2])
143+
org_billing_logs_alert_pubsub_topic = optional(string, null)
144+
org_billing_logs_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
145+
org_audit_logs_budget_amount = optional(number, 1000)
146+
org_audit_logs_alert_spent_percents = optional(list(number), [1.2])
147+
org_audit_logs_alert_pubsub_topic = optional(string, null)
148+
org_audit_logs_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
149+
scc_notifications_budget_amount = optional(number, 1000)
150+
scc_notifications_alert_spent_percents = optional(list(number), [1.2])
151+
scc_notifications_alert_pubsub_topic = optional(string, null)
152+
scc_notifications_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")
144153
})
145154
default = {}
146155
}

2-environments/modules/env_baseline/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| env | The environment to prepare (ex. development) | `string` | n/a | yes |
88
| environment\_code | A short form of the folder level resources (environment) within the Google Cloud organization (ex. d). | `string` | n/a | yes |
99
| monitoring\_workspace\_users | Google Workspace or Cloud Identity group that have access to Monitoring Workspaces. | `string` | n/a | yes |
10-
| project\_budget | Budget configuration for projects.<br> budget\_amount: The amount to use as the budget.<br> alert\_spent\_percents: A list of percentages of the budget to alert on when threshold is exceeded.<br> 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}`. | <pre>object({<br> base_network_budget_amount = optional(number, 1000)<br> base_network_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> base_network_alert_pubsub_topic = optional(string, null)<br> restricted_network_budget_amount = optional(number, 1000)<br> restricted_network_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> restricted_network_alert_pubsub_topic = optional(string, null)<br> monitoring_budget_amount = optional(number, 1000)<br> monitoring_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> monitoring_alert_pubsub_topic = optional(string, null)<br> secret_budget_amount = optional(number, 1000)<br> secret_alert_spent_percents = optional(list(number), [0.5, 0.75, 0.9, 0.95])<br> secret_alert_pubsub_topic = optional(string, null)<br> })</pre> | `{}` | no |
10+
| project\_budget | Budget configuration for projects.<br> budget\_amount: The amount to use as the budget.<br> alert\_spent\_percents: A list of percentages of the budget to alert on when threshold is exceeded.<br> 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}`.<br> alert\_spend\_basis: The type of basis used to determine if spend has passed the threshold. Possible choices are `CURRENT_SPEND` or `FORECASTED_SPEND` (default). | <pre>object({<br> base_network_budget_amount = optional(number, 1000)<br> base_network_alert_spent_percents = optional(list(number), [1.2])<br> base_network_alert_pubsub_topic = optional(string, null)<br> base_network_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> restricted_network_budget_amount = optional(number, 1000)<br> restricted_network_alert_spent_percents = optional(list(number), [1.2])<br> restricted_network_alert_pubsub_topic = optional(string, null)<br> restricted_network_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> monitoring_budget_amount = optional(number, 1000)<br> monitoring_alert_spent_percents = optional(list(number), [1.2])<br> monitoring_alert_pubsub_topic = optional(string, null)<br> monitoring_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> secret_budget_amount = optional(number, 1000)<br> secret_alert_spent_percents = optional(list(number), [1.2])<br> secret_alert_pubsub_topic = optional(string, null)<br> secret_budget_alert_spend_basis = optional(string, "FORECASTED_SPEND")<br> })</pre> | `{}` | no |
1111
| remote\_state\_bucket | Backend bucket to load Terraform Remote State Data from previous steps. | `string` | n/a | yes |
1212

1313
## Outputs

2-environments/modules/env_baseline/monitoring.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ module "monitoring_project" {
4848
budget_alert_pubsub_topic = var.project_budget.monitoring_alert_pubsub_topic
4949
budget_alert_spent_percents = var.project_budget.monitoring_alert_spent_percents
5050
budget_amount = var.project_budget.monitoring_budget_amount
51+
budget_alert_spend_basis = var.project_budget.monitoring_budget_alert_spend_basis
5152
}

2-environments/modules/env_baseline/networking.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ module "restricted_shared_vpc_host_project" {
8888
budget_alert_pubsub_topic = var.project_budget.restricted_network_alert_pubsub_topic
8989
budget_alert_spent_percents = var.project_budget.restricted_network_alert_spent_percents
9090
budget_amount = var.project_budget.restricted_network_budget_amount
91+
budget_alert_spend_basis = var.project_budget.restricted_network_budget_alert_spend_basis
9192
}

2-environments/modules/env_baseline/secrets.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ module "env_secrets" {
4646
budget_alert_pubsub_topic = var.project_budget.secret_alert_pubsub_topic
4747
budget_alert_spent_percents = var.project_budget.secret_alert_spent_percents
4848
budget_amount = var.project_budget.secret_budget_amount
49+
budget_alert_spend_basis = var.project_budget.secret_budget_alert_spend_basis
4950
}

0 commit comments

Comments
 (0)