This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpolicydefinition-deploy_budget.tf
219 lines (214 loc) · 6.63 KB
/
policydefinition-deploy_budget.tf
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# This file was auto generated
resource "azurerm_policy_definition" "deploy_budget" {
name = "Deploy-Budget"
policy_type = "Custom"
mode = "All"
display_name = "Deploy a default budget on all subscriptions under the assigned scope"
description = "Deploy a default budget on all subscriptions under the assigned scope"
metadata = <<METADATA
{
"version": "1.0.0",
"category": "Budget"
}
METADATA
management_group_name = var.management_group_name
policy_rule = <<POLICYRULE
{
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Resources/subscriptions"
}
]
},
"then": {
"effect": "DeployIfNotExists",
"details": {
"type": "Microsoft.Consumption/budgets",
"deploymentScope": "Subscription",
"existenceScope": "Subscription",
"existenceCondition": {
"allOf": [
{
"field": "Microsoft.Consumption/budgets/amount",
"equals": "[parameters('amount')]"
},
{
"field": "Microsoft.Consumption/budgets/timeGrain",
"equals": "[parameters('timeGrain')]"
},
{
"field": "Microsoft.Consumption/budgets/category",
"equals": "Cost"
}
]
},
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"deployment": {
"location": "northeurope",
"properties": {
"mode": "Incremental",
"parameters": {
"amount": {
"value": "[parameters('amount')]"
},
"timeGrain": {
"value": "[parameters('timeGrain')]"
},
"firstThreshold": {
"value": "[parameters('firstThreshold')]"
},
"secondThreshold": {
"value": "[parameters('secondThreshold')]"
},
"contactEmails": {
"value": "[parameters('contactEmails')]"
},
"contactRoles": {
"value": "[parameters('contactRoles')]"
},
"contactGroups": {
"value": "[parameters('contactGroups')]"
}
},
"template": {
"$schema": "http://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"amount": {
"type": "String"
},
"timeGrain": {
"type": "String"
},
"firstThreshold": {
"type": "String"
},
"secondThreshold": {
"type": "String"
},
"contactEmails": {
"type": "Array"
},
"contactRoles": {
"type": "Array"
},
"contactGroups": {
"type": "Array"
},
"startDate": {
"type": "String",
"defaultValue": "[concat(utcNow('MM'), '/01/', utcNow('yyyy'))]"
}
},
"resources": [
{
"type": "Microsoft.Consumption/budgets",
"apiVersion": "2019-10-01",
"name": "default-sandbox-budget",
"properties": {
"timePeriod": {
"startDate": "[parameters('startDate')]"
},
"timeGrain": "[parameters('timeGrain')]",
"amount": "[parameters('amount')]",
"category": "Cost",
"notifications": {
"NotificationForExceededBudget1": {
"enabled": true,
"operator": "GreaterThan",
"threshold": "[parameters('firstThreshold')]",
"contactEmails": "[parameters('contactEmails')]",
"contactRoles": "[parameters('contactRoles')]",
"contactGroups": "[parameters('contactGroups')]"
},
"NotificationForExceededBudget2": {
"enabled": true,
"operator": "GreaterThan",
"threshold": "[parameters('secondThreshold')]",
"contactEmails": "[parameters('contactEmails')]",
"contactRoles": "[parameters('contactRoles')]",
"contactGroups": "[parameters('contactGroups')]"
}
}
}
}
]
}
}
}
}
}
}
POLICYRULE
parameters = <<PARAMETERS
{
"amount": {
"type": "String",
"defaultValue": "1000",
"metadata": {
"description": "The total amount of cost or usage to track with the budget"
}
},
"timeGrain": {
"type": "String",
"defaultValue": "Monthly",
"allowedValues": [
"Monthly",
"Quarterly",
"Annually",
"BillingMonth",
"BillingQuarter",
"BillingAnnual"
],
"metadata": {
"description": "The time covered by a budget. Tracking of the amount will be reset based on the time grain."
}
},
"firstThreshold": {
"type": "String",
"defaultValue": "90",
"metadata": {
"description": "Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000."
}
},
"secondThreshold": {
"type": "String",
"defaultValue": "100",
"metadata": {
"description": "Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000."
}
},
"contactRoles": {
"type": "Array",
"defaultValue": [
"Owner",
"Contributor"
],
"metadata": {
"description": "The list of contact RBAC roles, in an array, to send the budget notification to when the threshold is exceeded."
}
},
"contactEmails": {
"type": "Array",
"defaultValue": [],
"metadata": {
"description": "The list of email addresses, in an array, to send the budget notification to when the threshold is exceeded."
}
},
"contactGroups": {
"type": "Array",
"defaultValue": [],
"metadata": {
"description": "The list of action groups, in an array, to send the budget notification to when the threshold is exceeded. It accepts array of strings."
}
}
}
PARAMETERS
}
output "policydefinition_deploy_budget" {
value = azurerm_policy_definition.deploy_budget
}