diff --git a/docs/howto/budget-alerts.md b/docs/howto/budget-alerts.md index 3f6ded7439..6f60cd9fda 100644 --- a/docs/howto/budget-alerts.md +++ b/docs/howto/budget-alerts.md @@ -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. @@ -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! +```` +````` \ No newline at end of file diff --git a/terraform/azure/budget-alerts.tf b/terraform/azure/budget-alerts.tf new file mode 100644 index 0000000000..3b697dc800 --- /dev/null +++ b/terraform/azure/budget-alerts.tf @@ -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", + ] + } +} diff --git a/terraform/azure/projects/pchub.tfvars b/terraform/azure/projects/pchub.tfvars index 9d63a4e90b..70e4d0ab6e 100644 --- a/terraform/azure/projects/pchub.tfvars +++ b/terraform/azure/projects/pchub.tfvars @@ -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= yuvipanda@instantaneous-authenticity.local" diff --git a/terraform/azure/variables.tf b/terraform/azure/variables.tf index e43ed5c367..324351db37 100644 --- a/terraform/azure/variables.tf +++ b/terraform/azure/variables.tf @@ -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 +} \ No newline at end of file