-
Notifications
You must be signed in to change notification settings - Fork 1
/
policyDefinition.bicep
247 lines (242 loc) · 8.88 KB
/
policyDefinition.bicep
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
targetScope = 'subscription'
// PARAMETERS
param actionGroupName string
param actionGroupRG string
param actionGroupId string
param metricAlertResourceNamespace string
param metricAlertName string
param metricAlertDimension1 string
param metricAlertDimension2 string
param metricAlertDimension3 string
param metricAlertDescription string
param metricAlertSeverity string
param metricAlertEnabled string
param metricAlertEvaluationFrequency string
param metricAlertWindowSize string
param metricAlertSensitivity string
param metricAlertOperator string
param metricAlertTimeAggregation string
param metricAlertCriterionType string
param metricAlertAutoMitigate string
// VARIABLES
var policyDefCategory = 'Custom'
var policySource = 'Bicep'
// OUTPUTS
output bicepExampleInitiativeId string = bicepExampleInitiative.id
// RESOURCES
resource bicepExampleDINEpolicy 'Microsoft.Authorization/policyDefinitions@2020-09-01' = {
name: 'bicepExampleDINEpolicy'
properties: {
displayName: 'DINE metric alert to Load Balancer for dipAvailability'
description: 'DeployIfNotExists a metric alert to Load Balancers for dipAvailability (Average Load Balancer health probe status per time duration)'
policyType: 'Custom'
mode: 'All'
metadata: {
category: policyDefCategory
source: policySource
version: '0.1.0'
}
parameters: {}
policyRule: {
if: {
allOf: [
{
field: 'type'
equals: metricAlertResourceNamespace
}
{
field: 'Microsoft.Network/loadBalancers/sku.name'
equals: 'Standard' // only Standard SKU support metric alerts
}
]
}
then: {
effect: 'deployIfNotExists'
details: {
roleDefinitionIds: [
'/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c' // contributor RBAC role for deployIfNotExists effect
]
type: 'Microsoft.Insights/metricAlerts'
existenceCondition: {
allOf: [
{
field: 'Microsoft.Insights/metricAlerts/criteria.Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria.allOf[*].metricNamespace'
equals: metricAlertResourceNamespace
}
{
field: 'Microsoft.Insights/metricAlerts/criteria.Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria.allOf[*].metricName'
equals: metricAlertName
}
{
field: 'Microsoft.Insights/metricalerts/scopes[*]'
equals: '[concat(subscription().id, \'/resourceGroups/\', resourceGroup().name, \'/providers/${metricAlertResourceNamespace}/\', field(\'fullName\'))]'
}
]
}
deployment: {
properties: {
mode: 'incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
parameters: {
resourceName: {
type: 'String'
metadata: {
displayName: 'resourceName'
description: 'Name of the resource'
}
}
resourceId: {
type: 'String'
metadata: {
displayName: 'resourceId'
description: 'Resource ID of the resource emitting the metric that will be used for the comparison'
}
}
resourceLocation: {
type: 'String'
metadata: {
displayName: 'resourceLocation'
description: 'Location of the resource'
}
}
actionGroupName: {
type: 'String'
metadata: {
displayName: 'actionGroupName'
description: 'Name of the Action Group'
}
}
actionGroupRG: {
type: 'String'
metadata: {
displayName: 'actionGroupRG'
description: 'Resource Group containing the Action Group'
}
}
actionGroupId: {
type: 'String'
metadata: {
displayName: 'actionGroupId'
description: 'The ID of the action group that is triggered when the alert is activated or deactivated'
}
}
}
variables: {}
resources: [
{
type: 'Microsoft.Insights/metricAlerts'
apiVersion: '2018-03-01'
name: '[concat(parameters(\'resourceName\'), \'-${metricAlertName}\')]'
location: 'global'
properties: {
description: metricAlertDescription
severity: metricAlertSeverity
enabled: metricAlertEnabled
scopes: [
'[parameters(\'resourceId\')]'
]
evaluationFrequency: metricAlertEvaluationFrequency
windowSize: metricAlertWindowSize
criteria: {
allOf: [
{
alertSensitivity: metricAlertSensitivity
failingPeriods: {
numberOfEvaluationPeriods: '2'
minFailingPeriodsToAlert: '1'
}
name: 'Metric1'
metricNamespace: metricAlertResourceNamespace
metricName: metricAlertName
dimensions: [
{
name: metricAlertDimension1
operator: 'Include'
values: [
'*'
]
}
{
name: metricAlertDimension2
operator: 'Include'
values: [
'*'
]
}
{
name: metricAlertDimension3
operator: 'Include'
values: [
'*'
]
}
]
operator: metricAlertOperator
timeAggregation: metricAlertTimeAggregation
criterionType: metricAlertCriterionType
}
]
'odata.type': 'Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria'
}
autoMitigate: metricAlertAutoMitigate
targetResourceType: metricAlertResourceNamespace
targetResourceRegion: '[parameters(\'resourceLocation\')]'
actions: [
{
actionGroupId: actionGroupId
webHookProperties: {}
}
]
}
}
]
}
parameters: {
resourceName: {
value: '[field(\'name\')]'
}
resourceId: {
value: '[field(\'id\')]'
}
resourceLocation: {
value: '[field(\'location\')]'
}
actionGroupName: {
value: actionGroupName
}
actionGroupRG: {
value: actionGroupRG
}
actionGroupID: {
value: actionGroupId
}
}
}
}
}
}
}
}
}
resource bicepExampleInitiative 'Microsoft.Authorization/policySetDefinitions@2020-09-01' = {
name: 'bicepExampleInitiative'
properties: {
policyType: 'Custom'
displayName: 'Bicep Example Initiative'
description: 'Bicep Example Initiative'
metadata: {
category: policyDefCategory
source: policySource
version: '0.1.0'
}
parameters: {}
policyDefinitions: [
{
policyDefinitionId: bicepExampleDINEpolicy.id
parameters: {}
}
]
}
}