Skip to content

Commit

Permalink
Merge pull request #10 from cds-snc/feat/add_budget_alarms
Browse files Browse the repository at this point in the history
Add budget alarms so that we are aware of costs
  • Loading branch information
sylviamclaughlin authored Feb 28, 2025
2 parents 63eb523 + 24a5e5a commit a609ecd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions terragrunt/modules/openai_api_key/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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(
["[email protected]"],
var.requestor_emails
)
}
}
17 changes: 17 additions & 0 deletions terragrunt/modules/openai_api_key/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
3 changes: 3 additions & 0 deletions terragrunt/openai_api_keys.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module "valentine_api_key" {
name = "valentine"
custom_subdomain_name = "valentine"
resource_group_name_prefix = "valentine"
requestor_emails = ["[email protected]"]
}

module "ai_answers_api_key" {
Expand All @@ -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 = ["[email protected]"]
}

0 comments on commit a609ecd

Please sign in to comment.