diff --git a/terragrunt/modules/openai_api_key/main.tf b/terragrunt/modules/openai_api_key/main.tf index 6ed499f..f496a35 100644 --- a/terragrunt/modules/openai_api_key/main.tf +++ b/terragrunt/modules/openai_api_key/main.tf @@ -60,3 +60,28 @@ resource "azurerm_cognitive_deployment" "deployment" { capacity = 50 # Represents 50,000 TPM } } + +# Create a budget alarm with default of $25/month +resource "azurerm_consumption_budget_resource_group" "openai_budget" { + name = "openai-budget" + resource_group_id = azurerm_resource_group.rg.id + amount = var.budget_amount + time_grain = var.budget_time_grain + + # Let the budget alarm expire in 10 years. We basically want to send the budget alarm to the user for indeterminate, which is currently max 10 years in the settings. + time_period { + start_date = "2025-02-01T00:00:00Z" + end_date = "2035-02-01T00:00:00Z" + } + notification { + enabled = true + threshold = 80 + operator = "EqualTo" + threshold_type = "Forecasted" + # Send notifications to the SRE team and requestor email(s) when we are at 80% of the forecasted budget + contact_emails = concat( + ["sre-ifs@cds-snc.ca"], + var.requestor_emails + ) + } +} diff --git a/terragrunt/modules/openai_api_key/variables.tf b/terragrunt/modules/openai_api_key/variables.tf index 6892027..2187e96 100644 --- a/terragrunt/modules/openai_api_key/variables.tf +++ b/terragrunt/modules/openai_api_key/variables.tf @@ -52,3 +52,20 @@ variable "openai_deployments" { } ] } + +variable "budget_amount" { + type = number + description = "The amount of money to spend on the Azure Cognitive Services account per month." + default = 25 +} + +variable "budget_time_grain" { + type = string + description = "The time period for the budget. The default is Monthly." + default = "Monthly" +} + +variable "requestor_emails" { + type = list(string) + description = "The email address of the requestor of the api key." +} diff --git a/terragrunt/openai_api_keys.tf b/terragrunt/openai_api_keys.tf index 6c5e157..04c4af5 100644 --- a/terragrunt/openai_api_keys.tf +++ b/terragrunt/openai_api_keys.tf @@ -4,6 +4,7 @@ module "valentine_api_key" { name = "valentine" custom_subdomain_name = "valentine" resource_group_name_prefix = "valentine" + requestor_emails = ["max.neuvians@cds-snc.ca"] } module "ai_answers_api_key" { @@ -12,4 +13,6 @@ module "ai_answers_api_key" { name = "ai-answers" custom_subdomain_name = "ai-answers" resource_group_name_prefix = "ai-answers" + budget_amount = 50 + requestor_emails = ["HamzaBelal.Aburaneh@cds-snc.ca"] }