From 8d2a51434958330d39ffd36fc436d8ac7700f2d6 Mon Sep 17 00:00:00 2001 From: Sylvia McLaughlin <85905333+sylviamclaughlin@users.noreply.github.com> Date: Thu, 27 Feb 2025 23:24:23 +0000 Subject: [PATCH 1/2] Add budget alarms so that we are aware of costs --- terragrunt/modules/openai_api_key/main.tf | 25 +++++++++++++++++++ .../modules/openai_api_key/variables.tf | 17 +++++++++++++ terragrunt/openai_api_keys.tf | 3 +++ 3 files changed, 45 insertions(+) diff --git a/terragrunt/modules/openai_api_key/main.tf b/terragrunt/modules/openai_api_key/main.tf index 6ed499f..08f04b6 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 10 years. + 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 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..f4f9fda 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.0 +} + +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"] } From 24a5e5ab208fe8952ab6a158c535bed322e6eb94 Mon Sep 17 00:00:00 2001 From: Sylvia McLaughlin <85905333+sylviamclaughlin@users.noreply.github.com> Date: Thu, 27 Feb 2025 23:28:41 +0000 Subject: [PATCH 2/2] Updating variables --- terragrunt/modules/openai_api_key/main.tf | 4 ++-- terragrunt/modules/openai_api_key/variables.tf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/terragrunt/modules/openai_api_key/main.tf b/terragrunt/modules/openai_api_key/main.tf index 08f04b6..f496a35 100644 --- a/terragrunt/modules/openai_api_key/main.tf +++ b/terragrunt/modules/openai_api_key/main.tf @@ -68,7 +68,7 @@ resource "azurerm_consumption_budget_resource_group" "openai_budget" { 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 10 years. + # 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" @@ -78,7 +78,7 @@ resource "azurerm_consumption_budget_resource_group" "openai_budget" { threshold = 80 operator = "EqualTo" threshold_type = "Forecasted" - # Send notifications to the SRE team when we are at 80% of the forecasted budget + # 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 f4f9fda..2187e96 100644 --- a/terragrunt/modules/openai_api_key/variables.tf +++ b/terragrunt/modules/openai_api_key/variables.tf @@ -56,7 +56,7 @@ 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.0 + default = 25 } variable "budget_time_grain" {