-
Notifications
You must be signed in to change notification settings - Fork 1
/
azuredeploy.json
564 lines (560 loc) · 21.3 KB
/
azuredeploy.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"defaultValue": "simpleLinuxVM",
"metadata": {
"description": "The name of your Virtual Machine."
}
},
"adminUsername": {
"type": "string",
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"authenticationType": {
"type": "string",
"defaultValue": "password",
"allowedValues": [
"sshPublicKey",
"password"
],
"metadata": {
"description": "Type of authentication to use on the Virtual Machine. SSH key is recommended."
}
},
"adminPasswordOrKey": {
"type": "securestring",
"metadata": {
"description": "SSH Key or password for the Virtual Machine. SSH key is recommended."
}
},
"dnsLabelPrefix": {
"type": "string",
"defaultValue": "[toLower(concat(parameters('vmName'), '-', uniqueString(resourceGroup().id)))]",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
}
},
"storageAccountName": {
"type": "string",
"defaultValue": "[toLower(concat('ladstorage', uniqueString(resourceGroup().id)))]",
"metadata": {
"description": "Globally Unique Name for the Azure Storage Account."
}
},
"eventHubNamespaceName": {
"type": "string",
"defaultValue": "[toLower(concat('ladehns', uniqueString(resourceGroup().id)))]",
"metadata": {
"description": "Globally Unique Name for the Event Hub Namespace."
}
},
"ubuntuOSVersion": {
"type": "string",
"defaultValue": "18.04-LTS",
"allowedValues": [
"12.04.5-LTS",
"14.04.5-LTS",
"16.04.0-LTS",
"18.04-LTS"
],
"metadata": {
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"VmSize": {
"type": "string",
"defaultValue": "Standard_B2s",
"metadata": {
"description": "The size of the VM"
}
},
"virtualNetworkName": {
"type": "string",
"defaultValue": "vNet",
"metadata": {
"description": "Name of the VNET"
}
},
"subnetName": {
"type": "string",
"defaultValue": "Subnet",
"metadata": {
"description": "Name of the subnet in the virtual network"
}
},
"networkSecurityGroupName": {
"type": "string",
"defaultValue": "SecGroupNet",
"metadata": {
"description": "Name of the Network Security Group"
}
},
"accountSasProperties": {
"type": "object",
"defaultValue": {
"signedServices": "bt",
"signedPermission": "acluw",
// Defines the expiration date for the SAS token for account storage
"signedExpiry": "2023-02-01T00:00:01Z",
"signedResourceTypes": "co"
}
},
"eventHubSku": {
"type": "string",
"defaultValue": "Standard",
"allowedValues": [ "Basic", "Standard" ],
"metadata": {
"description": "Specifies the messaging tier for Event Hub Namespace."
}
}
},
"variables": {
"publicIpAddressName": "[concat(parameters('vmName'), 'PublicIP' )]",
"networkInterfaceName": "[concat(parameters('vmName'),'NetInt')]",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]",
"osDiskType": "Standard_LRS",
"subnetAddressPrefix": "10.1.0.0/24",
"addressPrefix": "10.1.0.0/16",
"linuxCpuEventHubName": "linuxCpu",
"linuxCpuEventHubSenderAuthRuleName": "[concat(variables('linuxCpuEventHubName'), 'Sender')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
"keyData": "[parameters('adminPasswordOrKey')]"
}
]
}
}
},
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2020-06-01",
"name": "[variables('networkInterfaceName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]",
"[resourceId('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]",
"[resourceId('Microsoft.Network/publicIpAddresses/', variables('publicIpAddressName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[variables('subnetRef')]"
},
"privateIPAllocationMethod": "Dynamic",
"publicIpAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
}
}
}
],
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups',parameters('networkSecurityGroupName'))]"
}
}
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2020-06-01",
"name": "[parameters('networkSecurityGroupName')]",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "SSH",
"properties": {
"priority": 1000,
"protocol": "TCP",
"access": "Allow",
"direction": "Inbound",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "22"
}
}
]
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2020-06-01",
"name": "[parameters('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetAddressPrefix')]",
"privateEndpointNetworkPolicies": "Enabled",
"privateLinkServiceNetworkPolicies": "Enabled"
}
}
]
}
},
{
"type": "Microsoft.Network/publicIpAddresses",
"apiVersion": "2020-06-01",
"name": "[variables('publicIpAddressName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Basic",
"tier": "Regional"
},
"properties": {
"publicIpAllocationMethod": "Dynamic",
"publicIPAddressVersion": "IPv4",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
},
"idleTimeoutInMinutes": 4
}
},
// Defines the storage account which Linux Azure Diagnostics will be configured to use
{
"name": "[parameters('storageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-06-01",
"tags": {
"displayName": "[parameters('storageAccountName')]"
},
"location": "[resourceGroup().location]",
"kind": "StorageV2",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2020-06-01",
"name": "[parameters('vmName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('VmSize')]"
},
"storageProfile": {
"osDisk": {
"createOption": "fromImage",
"managedDisk": {
"storageAccountType": "[variables('osDiskType')]"
}
},
"imageReference": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "[parameters('ubuntuOSVersion')]",
"version": "latest"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
}
]
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
}
}
},
// Defines the Event Hub Namespace which will contain the Event Hub instance
{
"type": "Microsoft.EventHub/namespaces",
"apiVersion": "2018-01-01-preview",
"name": "[parameters('eventHubNamespaceName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('eventHubSku')]",
"tier": "[parameters('eventHubSku')]",
"capacity": 1
},
"properties": {
"isAutoInflateEnabled": false,
"maximumThroughputUnits": 0
},
"resources": [
// Defines the Event Hub instance
{
"type": "eventhubs",
"apiVersion": "2017-04-01",
"name": "[variables('linuxCpuEventHubName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces', parameters('eventHubNamespaceName'))]"
],
"properties": {
"messageRetentionInDays": 7,
"partitionCount": 1
},
"resources": [
/*
* Creates an authorization rule on the Event Hub. Adding "Send" rights to the rule
* allows events to be sent to the Event Hub.
*
* Later in the template, we will use the PrimaryKey from this rule to generate
* a SAS Token URL which the Linux Azure Diagnostics extension will need for authorization
* when sending events to the Event Hub.
*/
{
"apiVersion": "2017-04-01",
"name": "[variables('linuxCpuEventHubSenderAuthRuleName')]",
"type": "authorizationRules",
"dependsOn": [
"[variables('linuxCpuEventHubName')]"
],
"properties": {
"rights": [ "Send" ]
}
}
]
}
]
},
{
/*
Use a Powershell script to generate a SAS Token from the PrimaryKey of the Authorization Rule in the Event Hub
we created. The script contents are defined near the beginning of the template in a variable.
For more on generating Event Hub SAS Tokens to use with Linux Azure Diagostics see:
* https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-linux#the-eventhub-sink
* https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token
For more on using Deployment Scripts in ARM templates see:
* https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-script-template
*/
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "2020-10-01",
"name": "generateLinuxCpuSASTokenScript",
"location": "[resourceGroup().location]",
"kind": "AzurePowerShell",
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', parameters('eventHubNamespaceName'), variables('linuxCpuEventHubName'))]"
],
"properties": {
"forceUpdateTag": "1", // Force this script to execute every time
"azPowerShellVersion": "3.0",
/*
Use the listKeys ARM template function to fetch the primaryKey from the Event Hub Authorization Rule and
use it as a parameter when invoking the Powershell function.
*/
"arguments": "[concat('-ehNamespace \\\"', parameters('eventHubNamespaceName'), '\\\" -ehName \\\"', variables('linuxCpuEventHubName'), '\\\" -Access_Policy_Name \\\"', variables('linuxCpuEventHubSenderAuthRuleName'), '\\\" -Access_Policy_Key \\\"', listkeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', parameters('eventHubNamespaceName'), variables('linuxCpuEventHubName'), variables('linuxCpuEventHubSenderAuthRuleName')), '2017-04-01').primaryKey, '\\\"')]",
"scriptContent": "
param([string] $ehNamespace, [string] $ehName, [string] $Access_Policy_Name, [string] $Access_Policy_Key)
# Script based on https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token#powershell
[Reflection.Assembly]::LoadWithPartialName('System.Web')| out-null
$URI=\"$ehNamespace.servicebus.windows.net/$ehName\"
# Token expires in 1 year
$Expires=([DateTimeOffset]::Now.ToUnixTimeSeconds())+31622400
$SignatureString=[System.Web.HttpUtility]::UrlEncode($URI)+ \"`n\" + [string]$Expires
$HMAC = New-Object System.Security.Cryptography.HMACSHA256
$HMAC.key = [Text.Encoding]::ASCII.GetBytes($Access_Policy_Key)
$Signature = $HMAC.ComputeHash([Text.Encoding]::ASCII.GetBytes($SignatureString))
$Signature = [Convert]::ToBase64String($Signature)
$SASToken = \"sr=\" + [System.Web.HttpUtility]::UrlEncode($URI) + \"&sig=\" + [System.Web.HttpUtility]::UrlEncode($Signature) + \"&se=\" + $Expires + \"&skn=\" + $Access_Policy_Name
$DeploymentScriptOutputs = @{}
$DeploymentScriptOutputs['SASToken'] = $SASToken
",
"timeout": "PT10S",
"cleanupPreference": "Always",
"retentionInterval": "PT1H"
}
},
// Defines the AzureDiagnostics extension for the VM.
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2017-12-01",
"name": "[concat(parameters('vmName'), '/AzureDiagnostics')]",
"tags": {
"displayName": "AzureDiagnostics"
},
"location": "[resourceGroup().location]",
// Prior to setting up the Linux Azure Diagnostics extension, we must first set up:
// * The virtual machine it will be installed on.
// * The storage account to use for Table/Blob storage
// * The script which will generate the SAS Token required for sending to the Event Hub sink.
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines/', parameters('vmName'))]",
"[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
"[resourceId('Microsoft.Resources/deploymentScripts', 'generateLinuxCpuSASTokenScript')]"
],
// Define details of the VM Extension to install
"properties": {
"publisher": "Microsoft.Azure.Diagnostics",
"type": "LinuxDiagnostic",
"autoUpgradeMinorVersion": true,
"typeHandlerVersion": "3.0",
// Defines the protectedSettings for LAD installation. For more information on LAD protectedSettings see:
// * https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-linux#protected-settings
"protectedSettings": {
"storageAccountName": "[parameters('storageAccountName')]",
"storageAccountEndPoint": "https://core.windows.net",
// Use the listAccountSas ARM template function to generate a SAS token for access to Table/Blob storage.
// The expiration date for the token depends on what is defined in the accountSasProperties parameter.
// For more information on using the listAccountSas function see:
// * https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource?tabs=json#list
// * https://docs.microsoft.com/en-us/rest/api/storagerp/storageaccounts/listaccountsas
"storageAccountSasToken": "[listAccountSas(parameters('storageAccountName'), '2019-06-01', parameters('accountSasProperties')).accountSasToken]",
"sinksConfig": {
"sink": [
{
"name": "SyslogJsonBlob",
"type": "JsonBlob"
},
{
"name": "FilelogJsonBlob",
"type": "JsonBlob"
},
{
"name": "LinuxCpuJsonBlob",
"type": "JsonBlob"
},
{
"name": "MyJsonMetricsBlob",
"type": "JsonBlob"
},
{
"name": "LinuxCpuEventHub",
"type": "EventHub",
// Construct the complete sasURL required for writing to the event hub. Refer to the output of the
// generateLinuxCpuSASTokenScript to get the SAS Token part of the URL.
//
// For more info on the sasURL format see:
// * https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-linux#the-eventhub-sink
"sasURL": "[concat('https://', parameters('eventHubNamespaceName') ,'.servicebus.windows.net/', variables('linuxCpuEventHubName'), '?', reference('generateLinuxCpuSASTokenScript').outputs.SASToken)]"
}
]
}
},
// Defines the public settings for LAD installation. For more information on LAD public settings see:
// * https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-linux#public-settings
//
// The settings are based on the example LAD 3.0 configuration:
// * https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-linux#an-example-lad-30-configuration
"settings": {
"StorageAccount": "[parameters('storageAccountName')]",
"ladCfg": {
"sampleRateInSeconds": 15,
"diagnosticMonitorConfiguration": {
"performanceCounters": {
"sinks": "MyJsonMetricsBlob",
"performanceCounterConfiguration": [
{
"unit": "Percent",
"type": "builtin",
"counter": "PercentProcessorTime",
"counterSpecifier": "/builtin/Processor/PercentProcessorTime",
"annotation": [
{
"locale": "en-us",
"displayName": "Aggregate CPU %utilization"
}
],
"condition": "IsAggregate=TRUE",
"class": "Processor"
},
{
"unit": "Bytes",
"type": "builtin",
"counter": "UsedSpace",
"counterSpecifier": "/builtin/FileSystem/UsedSpace",
"annotation": [
{
"locale": "en-us",
"displayName": "Used disk space on /"
}
],
"condition": "Name=\"/\"",
"class": "Filesystem"
}
]
},
"metrics": {
"metricAggregation": [
{
"scheduledTransferPeriod": "PT1H"
},
{
"scheduledTransferPeriod": "PT1M"
}
],
// resourceId property must be set to the resourceId of the virtual machine
"resourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
},
"eventVolume": "Large",
"syslogEvents": {
"sinks": "SyslogJsonBlob",
"syslogEventConfiguration": {
"LOG_USER": "LOG_INFO"
}
}
}
},
"perfCfg": [
{
"query": "SELECT PercentProcessorTime, PercentIdleTime FROM SCX_ProcessorStatisticalInformation WHERE Name='_TOTAL'",
"table": "LinuxCpu",
"frequency": 60,
"sinks": "LinuxCpuJsonBlob,LinuxCpuEventHub"
}
],
// Configure LAD to tail the file /var/log/myladtestlog and upload it
// to the MyLadTestLog Azure table and the FilelogJsonBlob
"fileLogs": [
{
"file": "/var/log/myladtestlog",
"table": "MyLadTestLog",
"sinks": "FilelogJsonBlob"
}
]
}
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
},
"hostname": {
"type": "string",
"value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]"
},
"sshCommand": {
"type": "string",
"value": "[concat('ssh ', parameters('adminUsername'), '@', reference(variables('publicIPAddressName')).dnsSettings.fqdn)]"
}
}
}