-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.json
275 lines (275 loc) · 10.7 KB
/
main.json
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionid": {
"type": "string"
}
},
"variables": {
"location": "[deployment().location]"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "rg-apa-remediation",
"subscriptionId": "[parameters('subscriptionid')]",
"location": "[deployment().location]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"location": {
"value": "[variables('location')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2023-07-01",
"name": "rg-apa-remediation",
"location": "[parameters('location')]"
}
]
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "umi-apa-remediation",
"subscriptionId": "[format('{0}', parameters('subscriptionid'))]",
"resourceGroup": "rg-apa-remediation",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"location": {
"value": "[variables('location')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.ManagedIdentity/userAssignedIdentities",
"apiVersion": "2023-07-31-preview",
"name": "umi-apa-remediation",
"location": "[parameters('location')]"
}
],
"outputs": {
"umirid": {
"type": "string",
"value": "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', 'umi-apa-remediation')]"
},
"umicid": {
"type": "string",
"value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', 'umi-apa-remediation'), '2023-07-31-preview').clientId]"
},
"umipid": {
"type": "string",
"value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', 'umi-apa-remediation'), '2023-07-31-preview').principalId]"
}
}
}
},
"dependsOn": [
"[subscriptionResourceId(parameters('subscriptionid'), 'Microsoft.Resources/deployments', 'rg-apa-remediation')]"
]
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "role-apa-remediation",
"location": "[deployment().location]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"principalId": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', format('{0}', parameters('subscriptionid')), 'rg-apa-remediation'), 'Microsoft.Resources/deployments', 'umi-apa-remediation'), '2022-09-01').outputs.umipid.value]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"principalId": {
"type": "string"
}
},
"variables": {
"contributorrole": "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
},
"resources": [
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "2022-04-01",
"name": "[guid(parameters('principalId'), variables('contributorrole'), managementGroup().id)]",
"properties": {
"roleDefinitionId": "[variables('contributorrole')]",
"principalId": "[parameters('principalId')]",
"principalType": "ServicePrincipal"
}
}
]
}
},
"dependsOn": [
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', format('{0}', parameters('subscriptionid')), 'rg-apa-remediation'), 'Microsoft.Resources/deployments', 'umi-apa-remediation')]"
]
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "auto-apa-remediation",
"subscriptionId": "[format('{0}', parameters('subscriptionid'))]",
"resourceGroup": "rg-apa-remediation",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"location": {
"value": "[variables('location')]"
},
"umirid": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', format('{0}', parameters('subscriptionid')), 'rg-apa-remediation'), 'Microsoft.Resources/deployments', 'umi-apa-remediation'), '2022-09-01').outputs.umirid.value]"
},
"umicid": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', format('{0}', parameters('subscriptionid')), 'rg-apa-remediation'), 'Microsoft.Resources/deployments', 'umi-apa-remediation'), '2022-09-01').outputs.umicid.value]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"umirid": {
"type": "string"
},
"umicid": {
"type": "string"
},
"utcnow": {
"type": "string",
"defaultValue": "[utcNow()]"
}
},
"resources": [
{
"type": "Microsoft.Automation/automationAccounts",
"apiVersion": "2023-11-01",
"name": "auto-apa-remediation",
"location": "[parameters('location')]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[format('{0}', parameters('umirid'))]": {}
}
},
"properties": {
"disableLocalAuth": true,
"publicNetworkAccess": false,
"sku": {
"name": "basic"
}
}
},
{
"type": "Microsoft.Automation/automationAccounts/runbooks",
"apiVersion": "2023-11-01",
"name": "[format('{0}/{1}', 'auto-apa-remediation', 'AzurePolicyAutomator')]",
"location": "[parameters('location')]",
"properties": {
"logVerbose": false,
"logProgress": false,
"runbookType": "PowerShell72",
"publishContentLink": {
"uri": "https://raw.githubusercontent.com/msdirtbag/AzurePolicyAutomator/main/AzurePolicyAutomator.ps1"
}
},
"dependsOn": [
"[resourceId('Microsoft.Automation/automationAccounts', 'auto-apa-remediation')]"
]
},
{
"type": "Microsoft.Automation/automationAccounts/variables",
"apiVersion": "2023-11-01",
"name": "[format('{0}/{1}', 'auto-apa-remediation', 'clientid')]",
"properties": {
"value": "[format('\"{0}\"', parameters('umicid'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Automation/automationAccounts', 'auto-apa-remediation')]"
]
},
{
"type": "Microsoft.Automation/automationAccounts/schedules",
"apiVersion": "2023-11-01",
"name": "[format('{0}/{1}', 'auto-apa-remediation', 'Every12Hours')]",
"properties": {
"description": "Runs every 12 hours",
"startTime": "[dateTimeAdd(parameters('utcnow'), 'PT1H')]",
"expiryTime": "9999-12-31T00:00:00Z",
"interval": 12,
"frequency": "Hour",
"timeZone": "UTC"
},
"dependsOn": [
"[resourceId('Microsoft.Automation/automationAccounts', 'auto-apa-remediation')]"
]
},
{
"type": "Microsoft.Automation/automationAccounts/jobSchedules",
"apiVersion": "2022-08-08",
"name": "[format('{0}/{1}', 'auto-apa-remediation', guid(resourceGroup().id, subscription().subscriptionId, deployment().name, 'apa'))]",
"properties": {
"parameters": {},
"runbook": {
"name": "AzurePolicyAutomator"
},
"schedule": {
"name": "Every12Hours"
}
},
"dependsOn": [
"[resourceId('Microsoft.Automation/automationAccounts', 'auto-apa-remediation')]",
"[resourceId('Microsoft.Automation/automationAccounts/runbooks', 'auto-apa-remediation', 'AzurePolicyAutomator')]",
"[resourceId('Microsoft.Automation/automationAccounts/schedules', 'auto-apa-remediation', 'Every12Hours')]"
]
}
]
}
},
"dependsOn": [
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', format('{0}', parameters('subscriptionid')), 'rg-apa-remediation'), 'Microsoft.Resources/deployments', 'umi-apa-remediation')]"
]
}
]
}