-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbudget.tf
More file actions
100 lines (84 loc) · 2.81 KB
/
Copy pathbudget.tf
File metadata and controls
100 lines (84 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
resource "azurerm_monitor_action_group" "mag1" {
name = "Monitor action group"
resource_group_name = azurerm_resource_group.rg1.name
short_name = "mag"
}
locals {
notification_email = "nikos.tsirmirakis@winopsdba.com"
}
# Forecast
locals {
budget_forecast_notifications = {
80.0 = { operator = "GreaterThanOrEqualTo", contact_emails = [local.notification_email] }
90.0 = { operator = "GreaterThanOrEqualTo", contact_emails = [local.notification_email] }
100.0 = { operator = "GreaterThanOrEqualTo", contact_emails = [local.notification_email] }
120.0 = { operator = "GreaterThanOrEqualTo", contact_emails = [local.notification_email] }
}
}
resource "azurerm_consumption_budget_resource_group" "cbrgf" {
name = "${azurerm_resource_group.rg1.name}-m-forecast-${var.budget_amount}"
resource_group_id = azurerm_resource_group.rg1.id
amount = var.budget_amount
time_grain = "Monthly"
time_period {
start_date = "2023-10-01T00:00:00Z"
}
filter {
dimension {
name = "ResourceId"
values = [
azurerm_monitor_action_group.mag1.id,
]
}
}
dynamic "notification" {
for_each = local.budget_forecast_notifications
content {
enabled = true
threshold = notification.key
threshold_type = "Forecasted"
operator = notification.value.operator
contact_emails = notification.value.contact_emails
contact_groups = [azurerm_monitor_action_group.mag1.id]
contact_roles = ["Owner"]
}
}
}
# Actual
locals {
budget_actual_notifications = {
80.0 = { operator = "GreaterThanOrEqualTo", contact_emails = [local.notification_email] }
90.0 = { operator = "GreaterThanOrEqualTo", contact_emails = [local.notification_email] }
100.0 = { operator = "GreaterThanOrEqualTo", contact_emails = [local.notification_email] }
120.0 = { operator = "GreaterThanOrEqualTo", contact_emails = [local.notification_email] }
}
}
resource "azurerm_consumption_budget_resource_group" "cbrga" {
name = "${azurerm_resource_group.rg1.name}-m-actual-${var.budget_amount}"
resource_group_id = azurerm_resource_group.rg1.id
amount = var.budget_amount
time_grain = "Monthly"
time_period {
start_date = "2023-10-01T00:00:00Z"
}
filter {
dimension {
name = "ResourceId"
values = [
azurerm_monitor_action_group.mag1.id,
]
}
}
dynamic "notification" {
for_each = local.budget_actual_notifications
content {
enabled = true
threshold = notification.key
threshold_type = "Actual"
operator = notification.value.operator
contact_emails = notification.value.contact_emails
contact_groups = [azurerm_monitor_action_group.mag1.id]
contact_roles = ["Owner"]
}
}
}