Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.
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
24 changes: 20 additions & 4 deletions azure/terraform/monitoring/budget-alert-subscription/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
locals {
start_date = formatdate("YYYY-MM-01'T'hh:mm:ssZ", timestamp())
end_date = formatdate("2026-MM-01'T'hh:mm:ssZ", local.start_date)
location = "germanywestcentral"
start_date = formatdate("YYYY-MM-01'T'hh:mm:ssZ", timestamp())
end_date = formatdate("2026-MM-01'T'hh:mm:ssZ", local.start_date)
action_group_name = "budget-alert-action-group"
action_group_short_name = "bdgt-ap"
}
//-----------------------------------------------
// Budget on subscription level
Expand All @@ -28,6 +29,7 @@ resource "azurerm_consumption_budget_subscription" "subscription_budget" {
operator = "EqualTo"

contact_emails = var.contact_emails
contact_groups = [azurerm_monitor_action_group.action_group.id]
}

notification {
Expand All @@ -37,7 +39,21 @@ resource "azurerm_consumption_budget_subscription" "subscription_budget" {
threshold_type = "Forecasted"

contact_emails = var.contact_emails

contact_groups = [azurerm_monitor_action_group.action_group.id]
}

}

//-----------------------------------------------
// Action Group
//-----------------------------------------------

resource "azurerm_resource_group" "action_group_rg" {
name = var.resource_group_for_action_group
location = var.location
}
resource "azurerm_monitor_action_group" "action_group" {
name = local.action_group_name
resource_group_name = azurerm_resource_group.action_group_rg.name
short_name = local.action_group_short_name
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ output "end_date" {
output "budget_amount" {
value = azurerm_consumption_budget_subscription.subscription_budget.amount
}

output "action_group_id" {
value = azurerm_monitor_action_group.action_group.id
}

output "resource_group_id" {
value = azurerm_resource_group.action_group_rg.id
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,20 @@ variable "forcasted_threshold" {
description = "The forcasted percentage of the monthly budget at which you wish to activate the alert upon reaching. E.g. '15' for 15% or '120' for 120%"
}

variable "resource_group_for_action_group" {
type = string
description = "the resource group holding the action group"
default = "rg-action-group"
}

// Uncomment next 2 variables if you want to change the start and end date via inputs --------------------------------
variable "location" {
type = string
description = "the location where resources will be deployes"
default = "germanywestcentral"

}
// Uncomment next 2 variables if you want to change the start and end date via inputs
// in main.tf change all 'local.start_date' and 'local.end_date' to 'var.start_date' and 'var.end_date' respectively"
# variable "end_date" {
# type = string
# description = "End date of the budget rule, Timestamp in the format YYYY-MM-DDTHH:MM:SSZ"
Expand Down