Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable budget alerts on azure clusters #4476

Merged
merged 7 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions docs/howto/budget-alerts.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

This document describes how to enable budget alerts for a cluster.

```{note}
This feature is currently only available on GCP!
```

## GCP
`````{tab-set}
````{tab-item} GCP
:sync: gcp-key

```{attention}
We can only enable budget alerting on GCP projects where we have enough permissions to enable APIs and view the billing account.
Expand All @@ -31,3 +29,28 @@ Then edit the following variables in the relevant `.tfvars` file for the cluster
In this case, we cannot enable budget alerting for this project.

With these variables set, you are ready to open a PR and perform a terraform apply!
````

````{tab-item} Azure
:sync: azure-key

To enable budget alerts for an Azure cluster, edit the following variables in the relevant `.tfvars` file for the cluster.

- **Set `budget_alert_enabled = true`**

This will ensure that the relevant resources will be created by terraform.

- **Set `budget_alert_amount`**

Current practice is to set this to the average expenditure of the last 3 months.

Then the alert will be triggered when the forecasted cost will exceed this value plus 20%.

You can find values to calculate that in the Cost analysis tab of the relevant Azure subscription: `Azure subscription` -> `Cost Management` -> `Cost analysis`.

If you are setting this up for a new cluster, you obviously don't have this information yet!
Instead, set the value to something like `500` and we can adjust as the community begins to use it.

- With these variables set, you are ready to open a PR and perform a terraform apply!
````
`````
24 changes: 24 additions & 0 deletions terraform/azure/budget-alerts.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
data "azurerm_subscription" "current" {}
resource "azurerm_consumption_budget_subscription" "budget" {
name = "BudgetSubscription-${var.resourcegroup_name}"
subscription_id = data.azurerm_subscription.current.id

amount = var.budget_alert_amount
time_grain = "Monthly"

time_period {
start_date = "2024-07-01T00:00:00Z"
end_date = "2029-07-01T00:00:00Z"
}

notification {
enabled = var.budget_alert_enabled ? true : false
threshold = 120
operator = "GreaterThanOrEqualTo"
threshold_type = "Forecasted"

contact_emails = [
"support+budget-${var.resourcegroup_name}@2i2c.org",
]
}
}
4 changes: 4 additions & 0 deletions terraform/azure/projects/pchub.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ global_container_registry_name = "2i2cpchub"
global_storage_account_name = "2i2cpchub"
location = "westeurope"

budget_alert_enabled = true
# This is approximate total cost for Jun 2024 in USD
budget_alert_amount = "500"

storage_size = 100
ssh_pub_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDEswiqOZ3cdu+OaT1K3ay8brlnnoHIpDyKNfLGeRAFQ4ZP+1OD82CIwrUiU4GhmiKTyyN9DWuKKhbEjMIrAKnoybQZBk/x21sHLyrqit1wq/X+f7/SKqDTFQGFYO5cERl/MwMRIp5WHEcLXi6WnaRczCQxOW6J36V5/frynz2Qq/3XwhQnkW9401HYt9H4Ur6JTZC0G0hMVklIT+gGsIml6Qu2O8+iuA2saGn3SCmTs7WBxVsEQTFt1w6JoJi4ohi7RtlT9QDSx4J+cawBNqzAK+gkozj2lN5Yiq7gtPJMe8sdLqmg9vSPCuAMMZeP+DhEGbre7Y+MMplSJrqkeT61WeCl39ffqwievGFkdTxzCiqX9TKSR2SS98W6jpCYrSkA1ymzn+HUADfyszU7sn6/F9I2w8oUbuFfMKDD4XfgkdK7Jqew7YJ4CDK2f4D94MWAmFicVKsYXPautnk+d3JqXarUN7k8bF9On2N8xZln0Zsui/Pmj1jQsnm0KXZOb9k= [email protected]"

Expand Down
17 changes: 17 additions & 0 deletions terraform/azure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,20 @@ variable "fileshare_alert_available_fraction" {
Decimal fraction (between 0 and 1) of total space available in fileshare. If used space is over this, we fire an alert to pagerduty.
EOT
}

variable "budget_alert_enabled" {
type = bool
default = false
description = <<-EOT
Enable budget alerts. Disable in cases where we do not have enough permissions
on the billing account or cloud account to enable APIs.
EOT
}

variable "budget_alert_amount" {
type = string
description = <<-EOT
Amount of *forecasted spend* at which to send a billing alert. Current practice
is to set this to the average of the last 3 months expenditure + 20%.
EOT
}