-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathVM-VM.bicep
1015 lines (932 loc) · 37.3 KB
/
VM-VM.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
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
param Prefix string
param DeploymentID string
param Environment string
param VM object
param AppServer object
param Global object
param DeploymentName string
@secure()
param vmAdminPassword string
@secure()
param devOpsPat string
@secure()
param sshPublic string
@secure()
param saKey string = newGuid()
param deploymentTime string = utcNow()
param month string = utcNow('MM')
param year string = utcNow('yyyy')
// Use same PAT token for 3 month blocks, min PAT age is 6 months, max is 9 months
var SASEnd = dateTimeAdd('${year}-${padLeft((int(month) - (int(month) - 1) % 3), 2, '0')}-01', 'P9M')
// Roll the SAS token one per 3 months, min length of 6 months.
var DSCSAS = saaccountidglobalsource.listServiceSAS('2021-09-01', {
canonicalizedResource: '/blob/${saaccountidglobalsource.name}/${last(split(Global._artifactsLocation, '/'))}'
signedResource: 'c'
signedProtocol: 'https'
signedPermission: 'r'
signedServices: 'b'
signedExpiry: SASEnd
keyToSign: 'key1'
}).serviceSasToken
var Deployment = '${Prefix}-${Global.OrgName}-${Global.Appname}-${Environment}${DeploymentID}'
var DeploymentURI = toLower('${Prefix}${Global.OrgName}${Global.Appname}${Environment}${DeploymentID}')
// os config now shared across subscriptions
var computeGlobal = json(loadTextContent('./global/Global-ConfigVM.json'))
var OSType = computeGlobal.OSType
var WadCfg = computeGlobal.WadCfg
var ladCfg = computeGlobal.ladCfg
var DataDiskInfo = computeGlobal.DataDiskInfo
var computeSizeLookupOptions = computeGlobal.computeSizeLookupOptions
var RGName = '${Prefix}-${Global.OrgName}-${Global.AppName}-RG-${Environment}${DeploymentID}'
var GlobalRGJ = json(Global.GlobalRG)
var GlobalSAJ = json(Global.GlobalSA)
var HubKVJ = json(Global.hubKV)
var HubRGJ = json(Global.hubRG)
var HubAAJ = json(Global.hubAA)
var regionLookup = json(loadTextContent('./global/region.json'))
var primaryPrefix = regionLookup[Global.PrimaryLocation].prefix
var gh = {
globalRGPrefix: contains(GlobalRGJ, 'Prefix') ? GlobalRGJ.Prefix : primaryPrefix
globalRGOrgName: contains(GlobalRGJ, 'OrgName') ? GlobalRGJ.OrgName : Global.OrgName
globalRGAppName: contains(GlobalRGJ, 'AppName') ? GlobalRGJ.AppName : Global.AppName
globalRGName: contains(GlobalRGJ, 'name') ? GlobalRGJ.name : '${Environment}${DeploymentID}'
globalSAPrefix: contains(GlobalSAJ, 'Prefix') ? GlobalSAJ.Prefix : primaryPrefix
globalSAOrgName: contains(GlobalSAJ, 'OrgName') ? GlobalSAJ.OrgName : Global.OrgName
globalSAAppName: contains(GlobalSAJ, 'AppName') ? GlobalSAJ.AppName : Global.AppName
globalSARGName: contains(GlobalSAJ, 'RG') ? GlobalSAJ.RG : contains(GlobalRGJ, 'name') ? GlobalRGJ.name : '${Environment}${DeploymentID}'
hubRGPrefix: HubRGJ.?Prefix ?? Prefix
hubRGOrgName: HubRGJ.?OrgName ?? Global.OrgName
hubRGAppName: HubRGJ.?AppName ?? Global.AppName
hubRGRGName: HubRGJ.?name ?? HubRGJ.?name ?? '${Environment}${DeploymentID}'
// hubVNPrefix: contains(HubVNJ, 'Prefix') ? HubVNJ.Prefix : Prefix
// hubVNOrgName: contains(HubVNJ, 'OrgName') ? HubVNJ.OrgName : Global.OrgName
// hubVNAppName: contains(HubVNJ, 'AppName') ? HubVNJ.AppName : Global.AppName
// hubVNRGName: contains(HubVNJ, 'name') ? HubVNJ.name : HubRGJ.name
hubKVPrefix: contains(HubKVJ, 'Prefix') ? HubKVJ.Prefix : Prefix
hubKVOrgName: contains(HubKVJ, 'OrgName') ? HubKVJ.OrgName : Global.OrgName
hubKVAppName: contains(HubKVJ, 'AppName') ? HubKVJ.AppName : Global.AppName
hubKVRGName: contains(HubKVJ, 'RG') ? HubKVJ.RG : HubRGJ.name
hubAAPrefix: contains(HubAAJ, 'Prefix') ? HubAAJ.Prefix : Prefix
hubAAOrgName: contains(HubAAJ, 'OrgName') ? HubAAJ.OrgName : Global.OrgName
hubAAAppName: contains(HubAAJ, 'AppName') ? HubAAJ.AppName : Global.AppName
hubAARGName: contains(HubAAJ, 'RG') ? HubAAJ.RG : HubRGJ.name
}
var globalRGName = '${gh.globalRGPrefix}-${gh.globalRGOrgName}-${gh.globalRGAppName}-RG-${gh.globalRGName}'
var HubRGName = '${gh.hubRGPrefix}-${gh.hubRGOrgName}-${gh.hubRGAppName}-RG-${gh.hubRGRGName}'
var globalSAName = toLower('${gh.globalSAPrefix}${gh.globalSAOrgName}${gh.globalSAAppName}${gh.globalSARGName}sa${GlobalSAJ.name}')
var HubKVRGName = '${gh.hubKVPrefix}-${gh.hubKVOrgName}-${gh.hubKVAppName}-RG-${gh.hubKVRGName}'
var HubKVName = toLower('${gh.hubKVPrefix}-${gh.hubKVOrgName}-${gh.hubKVAppName}-${gh.hubKVRGName}-kv${HubKVJ.name}')
var AANameHub = toLower('${gh.hubAAPrefix}${gh.hubAAOrgName}${gh.hubAAAppName}${gh.hubAARGName}${HubAAJ.name}')
var AAName = '${DeploymentURI}OMSAutomation'
// resource AAHub 'Microsoft.Automation/automationAccounts@2021-06-22' existing = {
// name: AANameHub
// scope: resourceGroup(HubRGName)
// }
resource AA 'Microsoft.Automation/automationAccounts@2021-06-22' existing = {
name: AAName
}
resource saaccountidglobalsource 'Microsoft.Storage/storageAccounts@2021-04-01' existing = {
name: globalSAName
scope: resourceGroup(globalRGName)
}
var EnvironmentLookup = {
D: 'Dev'
T: 'Test'
I: 'Int'
U: 'UAT'
P: 'PROD'
S: 'SBX'
}
var DSCConfigLookup = {
AppServers: 'AppServers'
InitialDOP: 'AppServers'
WVDServers: 'AppServers'
}
var AppServerSizeLookup = {
D: 'D'
T: 'D'
I: 'D'
U: 'D'
P: 'P'
S: 'D'
}
var RebootNodeLookup = {
D: true
Q: true
T: true
U: true
P: false
}
var ConfigurationMode = {
D: 'ApplyAndAutoCorrect'
Q: 'ApplyAndAutoCorrect'
T: 'ApplyAndAutoCorrect'
U: 'ApplyAndAutoCorrect'
P: 'ApplyAndMonitor'
}
var DSCConfigurationModeFrequencyMins = 15
var autoManageConfigurationProfile = '${DeploymentURI}AutoManage'
// var autoManageConfigurationProfile = '/providers/Microsoft.Automanage/bestPractices/AzureBestPractices${AppServerSizeLookup[Environment] == 'P' ? 'Production' : 'DevTest'}'
resource OMS 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = {
name: '${DeploymentURI}LogAnalytics'
}
resource KV 'Microsoft.KeyVault/vaults@2021-06-01-preview' existing = {
name: HubKVName
scope: resourceGroup(HubKVRGName)
}
resource cert 'Microsoft.KeyVault/vaults/secrets@2021-06-01-preview' existing = {
name: Global.CertName
parent: KV
}
var certUrlLatest = VM.match && bool(VM.Extensions.CertMgmt) ? cert.properties.secretUri : ''
var certUrl = VM.match && bool(VM.Extensions.CertMgmt) ? cert.properties.secretUriWithVersion : ''
var secrets = [
{
sourceVault: {
id: KV.id
}
vaultCertificates: [
{
certificateUrl: certUrl
certificateStore: 'My'
}
{
certificateUrl: certUrl
certificateStore: 'Root'
}
{
certificateUrl: certUrl
certificateStore: 'CA'
}
]
}
]
var networkLookup = json(loadTextContent('./global/network.json'))
var regionNumber = networkLookup[Prefix].Network
var network = json(Global.Network)
var networkId = {
upper: '${network.first}.${network.second - (8 * int(regionNumber)) + Global.AppId}'
lower: '${network.third - (8 * int(DeploymentID))}'
}
var addressPrefixes = [
'${networkId.upper}.${networkId.lower}.0/21'
]
var lowerLookup = {
snWAF01: 1
AzureFirewallSubnet: 1
snFE01: 2
snMT01: 4
snBE01: 6
}
var storageAccountType = Environment == 'P' ? /*
*/ (contains(AppServer, 'Zone') ? 'Premium_LRS' : 'Premium_ZRS') : /*
*/ (contains(AppServer, 'Zone') ? 'StandardSSD_ZRS' : 'StandardSSD_LRS')
var SADiagName = '${DeploymentURI}sadiag'
var saaccountiddiag = resourceId('Microsoft.Storage/storageAccounts/', SADiagName)
var saSQLBackupName = '${DeploymentURI}sasqlbackup'
var MSILookup = {
SQL: 'Cluster'
UTL: 'DefaultKeyVault'
FIL: 'Cluster'
OCR: 'Storage'
WVD: 'WVD'
}
resource UAI 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
name: '${Deployment}-uaiKeyVaultSecretsGet'
}
var userAssignedIdentities = {
Cluster: {
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiKeyVaultSecretsGet')}': {}
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountOperator')}': {}
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountOperatorGlobal')}': {}
}
Default: {
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiKeyVaultSecretsGet')}': {}
// '${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountOperatorGlobal')}': {}
// '${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountOperator')}': {}
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountFileContributor')}': {}
}
DefaultKeyVault: {
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountOperatorGlobal')}': {}
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiKeyVaultSecretsGetApp')}': {}
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiAzureServiceBusDataOwner')}': {}
}
WVD: {
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountOperatorGlobal')}': {}
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountFileContributor')}': {}
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiWVDRegKeyReader')}': {}
}
Storage: {
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountContributor')}': {}
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities/', '${Deployment}-uaiStorageAccountOperatorGlobal')}': {}
}
None: {}
}
var ASNAME = contains(AppServer, 'Zone') ? 'usingZones' : AppServer.ASNAME
resource AS 'Microsoft.Compute/availabilitySets@2022-03-01' = if (ASNAME != 'usingZones') {
name: '${Deployment}-as${ASNAME}'
location: resourceGroup().location
sku: {
name: 'Aligned'
}
properties: {
platformUpdateDomainCount: 5
platformFaultDomainCount: 3
}
}
module AppServerPIP 'x.publicIP.bicep' = {
name: 'dp${Deployment}-AppServer-publicIPDeploy${AppServer.Name}'
params: {
Deployment: Deployment
DeploymentURI: DeploymentURI
NICs: AppServer.NICs
VM: AppServer
PIPprefix: 'vm'
Global: Global
Prefix: Prefix
}
}
module AppServerJITNSG 'x.vmJITNSG.bicep' = {
name: 'dp${Deployment}-AppServer-JITNSG-${AppServer.Name}'
params: {
Deployment: Deployment
VM: AppServer
}
}
module AppServerNIC 'x.NIC.bicep' = {
name: 'dp${Deployment}-AppServer-nicDeployLoop${AppServer.Name}'
params: {
Deployment: Deployment
DeploymentURI: DeploymentURI
DeploymentID: DeploymentID
NICs: AppServer.NICs
VM: AppServer
Global: Global
Prefix: Prefix
Type: 'vm'
}
dependsOn: [
AppServerPIP
]
}
module DISKLOOKUP 'y.disks.bicep' = if (contains(AppServer, 'DDRole')) {
name: 'dp${Deployment}-AppServer-diskLookup${AppServer.Name}'
params: {
Deployment: Deployment
DeploymentID: DeploymentID
Name: AppServer.Name
SOFS: (contains(DataDiskInfo[AppServer.DDRole], 'SOFS') ? DataDiskInfo[AppServer.DDRole].SOFS : json('{"1":1}'))
DATA: (contains(DataDiskInfo[AppServer.DDRole], 'DATA') ? DataDiskInfo[AppServer.DDRole].DATA : json('{"1":1}'))
LOGS: (contains(DataDiskInfo[AppServer.DDRole], 'LOGS') ? DataDiskInfo[AppServer.DDRole].LOGS : json('{"1":1}'))
TEMPDB: (contains(DataDiskInfo[AppServer.DDRole], 'TEMPDB') ? DataDiskInfo[AppServer.DDRole].TEMPDB : json('{"1":1}'))
BACKUP: (contains(DataDiskInfo[AppServer.DDRole], 'BACKUP') ? DataDiskInfo[AppServer.DDRole].BACKUP : json('{"1":1}'))
Global: Global
}
}
resource virtualMachine 'Microsoft.Compute/virtualMachines@2022-03-01' = {
name: '${Deployment}-vm${AppServer.Name}'
location: resourceGroup().location
identity: {
type: 'SystemAssigned, UserAssigned'
userAssignedIdentities: contains(MSILookup, AppServer.ROLE) ? userAssignedIdentities[MSILookup[AppServer.ROLE]] : userAssignedIdentities.Default
}
tags: {
Environment: EnvironmentLookup[Environment]
Zone: contains(AppServer, 'Zone') ? AppServer.Zone : 1 // tag for windows update, set to 1 if using availabilitysets
}
zones: contains(AppServer, 'Zone') ? array(AppServer.Zone) : null
plan: contains(OSType[AppServer.OSType], 'plan') ? OSType[AppServer.OSType].plan : null
properties: {
licenseType: contains(OSType[AppServer.OSType], 'licenseType') ? OSType[AppServer.OSType].licenseType : null
availabilitySet: contains(AppServer, 'Zone') ? null : {
id: resourceId('Microsoft.Compute/availabilitySets', '${Deployment}-as${AppServer.ASName}')
}
hardwareProfile: {
vmSize: computeSizeLookupOptions['${AppServer.ROLE}-${AppServerSizeLookup[Environment]}']
}
osProfile: {
computerName: VM.vmHostName
adminUsername: contains(AppServer, 'AdminUser') ? AppServer.AdminUser : Global.vmAdminUserName
adminPassword: vmAdminPassword
customData: contains(AppServer, 'customData') ? base64(replace(AppServer.customData, '{0}', '${networkId.upper}.${contains(lowerLookup, AppServer.NICs[0].subnet) ? int(networkId.lower) + (1 * lowerLookup[AppServer.NICs[0].subnet]) : networkId.lower}.')) : null
// Use KV extension instead
// secrets: OSType[AppServer.OSType].OS == 'Windows' && Global.?CertName ? secrets : null
windowsConfiguration: OSType[AppServer.OSType].OS == 'Windows' ? VM.windowsConfiguration : null
linuxConfiguration: OSType[AppServer.OSType].OS != 'Windows' ? VM.linuxConfiguration : null
}
storageProfile: {
imageReference: OSType[AppServer.OSType].imageReference
osDisk: {
name: '${Deployment}-vm${AppServer.Name}-OSDisk'
caching: 'ReadWrite'
diskSizeGB: OSType[AppServer.OSType].OSDiskGB
createOption: 'FromImage'
managedDisk: {
storageAccountType: contains(AppServer, 'OSstorageAccountType') ? AppServer.OSstorageAccountType : storageAccountType
}
}
dataDisks: contains(AppServer, 'DDRole') ? DISKLOOKUP.outputs.DATADisks : null
}
networkProfile: {
networkInterfaces: [for (nic, index) in AppServer.NICs: {
id: resourceId('Microsoft.Network/networkInterfaces', '${Deployment}-vm${AppServer.Name}${contains(nic, 'LB') ? '-NICLB' : contains(nic, 'PLB') ? '-NICPLB' : contains(nic, 'SLB') ? '-NICSLB' : '-NIC'}${index == 0 ? '' : index + 1}')
properties: {
primary: contains(nic, 'Primary')
deleteOption: 'Delete'
}
}]
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
storageUri: 'https://${SADiagName}.blob.${environment().suffixes.storage}'
}
}
}
dependsOn: [
AS
AppServerNIC
]
}
// resource AutoManage 'Microsoft.Automanage/configurationProfileAssignments@2022-05-04' = if (VM.match && bool(VM.Extensions.AutoManage)) {
// name: 'default'
// scope: virtualMachine
// properties: {
// configurationProfile: autoManageConfigurationProfile
// }
// }
module AppServerJIT 'x.vmJIT.bicep' = if (bool(AppServer.DeployJIT)) {
name: 'dp${Deployment}-AppServer-JIT-${AppServer.Name}'
params: {
Deployment: Deployment
VM: AppServer
Global: Global
DeploymentID: DeploymentID
Prefix: Prefix
}
dependsOn: [
virtualMachine
AppServerDSC
]
}
resource autoShutdownScheduler 'Microsoft.DevTestLab/schedules@2018-09-15' = if (VM.match && contains(AppServer, 'shutdown')) {
name: 'shutdown-computevm-${Deployment}-vm${AppServer.Name}'
location: resourceGroup().location
properties: {
dailyRecurrence: {
time: AppServer.shutdown.time // "time": "2100"
}
notificationSettings: {
status: contains(AppServer.shutdown, 'notification') && bool(AppServer.shutdown.notification) ? 'Enabled' : 'Disabled'
emailRecipient: join(Global.alertRecipients, ';')
notificationLocale: 'en'
timeInMinutes: 30
}
status: !contains(AppServer.shutdown, 'enabled') || (contains(AppServer.shutdown, 'enabled') && bool(AppServer.shutdown.enabled)) ? 'Enabled' : 'Disabled'
targetResourceId: virtualMachine.id
taskType: 'ComputeVmShutdownTask'
timeZoneId: Global.shutdownSchedulerTimeZone // "Pacific Standard Time"
}
}
// sf ✅
// https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/key-vault-linux#extension-schema
resource AppServerKVAppServerExtension 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && bool(VM.Extensions.CertMgmt)) {
name: OSType[AppServer.OSType].OS == 'Windows' ? 'KeyVaultForWindows' : 'KeyVaultForLinux'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.Azure.KeyVault'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'KeyVaultForWindows' : 'KeyVaultForLinux'
typeHandlerVersion: OSType[AppServer.OSType].OS == 'Windows' ? '3.0' : '2.0'
autoUpgradeMinorVersion: true
enableAutomaticUpgrade: true
forceUpdateTag: '1'
settings: {
secretsManagementSettings: {
pollingIntervalInS: '14400'
// linkOnRenewal: false
// certificateStoreLocation: '/var/lib/waagent/Microsoft.Azure.KeyVault.Store' <-- default linux location
requireInitialSync: true
observedCertificates: OSType[AppServer.OSType].OS == 'Linux' ? [ certUrlLatest ] : [
{
url: certUrlLatest
certificateStoreName: 'MY'
certificateStoreLocation: 'LocalMachine'
}
{
url: certUrlLatest
certificateStoreName: 'Root'
certificateStoreLocation: 'LocalMachine'
}
{
url: certUrlLatest
certificateStoreName: 'CA'
certificateStoreLocation: 'LocalMachine'
}
]
}
authenticationSettings: {
msiEndpoint: 'http://169.254.169.254/metadata/identity/oauth2/token'
msiClientId: UAI.properties.clientId
}
}
}
}
// SF ✅
resource AppServerAADLogin 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && bool(VM.Extensions.AADLogin) && (contains(AppServer, 'ExcludeAADLogin') && AppServer.ExcludeAADLogin != 1)) {
name: 'AADLogin'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.Azure.ActiveDirectory'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'AADLoginForWindows' : 'AADSSHLoginForLinux'
typeHandlerVersion: OSType[AppServer.OSType].OS == 'Windows' ? '2.0' : '1.0'
autoUpgradeMinorVersion: true
}
}
resource AzureDefenderForServers 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && bool(VM.Extensions.AzureDefender)) {
name: 'AzureDefenderForServers'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.Azure.AzureDefenderForServers'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'MDE.Windows' : 'MDE.Linux'
typeHandlerVersion: '1'
autoUpgradeMinorVersion: true
settings: {
azureResourceId: virtualMachine.id
defenderForServersWorkspaceId: OMS.id
forceReOnboarding: false
autoUpdate: true
vNextEnabled: true
}
}
}
resource AppServerAdminCenter 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && bool(VM.Extensions.AdminCenter) && (contains(AppServer, 'ExcludeAdminCenter') && AppServer.ExcludeAdminCenter != 1)) {
name: 'AdminCenter'
parent: virtualMachine
location: resourceGroup().location
properties: {
autoUpgradeMinorVersion: true
publisher: 'Microsoft.AdminCenter'
type: 'AdminCenter'
typeHandlerVersion: '0.0'
settings: {
port: '6516'
cspFrameAncestors: [
'https://portal.azure.com'
'https://*.hosting.portal.azure.net'
'https://localhost:1340'
]
corsOrigins: [
'https://portal.azure.com'
'https://waconazure.com'
]
}
}
}
resource AppServerDomainJoin 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && bool(VM.Extensions.DomainJoin) && !(contains(AppServer, 'ExcludeDomainJoin') && bool(AppServer.ExcludeDomainJoin))) {
name: 'joindomain'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.Compute'
type: 'JsonADDomainExtension'
typeHandlerVersion: '1.3'
autoUpgradeMinorVersion: true
settings: {
Name: Global.ADDomainName
OUPath: contains(AppServer, 'OUPath') ? AppServer.OUPath : ''
User: '${Global.vmAdminUserName}@${Global.ADDomainName}'
Restart: 'true'
Options: 3
}
protectedSettings: {
Password: vmAdminPassword
}
}
}
resource AppServerDSCPull 'Microsoft.Compute/virtualMachines/extensions@2021-03-01' = if (VM.match && bool(VM.Extensions.DSC) && (contains(AppServer, 'DSC') && AppServer.DSC == 'PULL')) {
name: 'Microsoft.Powershell.DSC.Pull'
parent: virtualMachine
location: resourceGroup().location
tags: {
displayName: 'Powershell.DSC.Pull'
}
properties: {
publisher: OSType[AppServer.OSType].OS == 'Windows' ? 'Microsoft.Powershell' : 'Microsoft.OSTCExtensions'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'DSC' : 'DSCForLinux'
typeHandlerVersion: OSType[AppServer.OSType].OS == 'Windows' ? '2.77' : '2.0'
autoUpgradeMinorVersion: true
protectedSettings: {
Items: {
registrationKeyPrivate: AA.listKeys().keys[0].Value
}
}
settings: {
advancedOptions: {
forcePullAndApply: true
}
Properties: [
{
Name: 'RegistrationKey'
Value: {
UserName: 'PLACEHOLDER_DONOTUSE'
Password: 'PrivateSettingsRef:registrationKeyPrivate'
}
TypeName: 'System.Management.Automation.PSCredential'
}
{
Name: 'RegistrationUrl'
#disable-next-line BCP053
Value: AA.properties.RegistrationUrl
TypeName: 'System.String'
}
{
Name: 'NodeConfigurationName'
Value: '${(contains(DSCConfigLookup, DeploymentName) ? DSCConfigLookup[DeploymentName] : 'AppServers')}.${Global.OrgName}_${Global.Appname}_${AppServer.ROLE}_${Environment}${DeploymentID}'
TypeName: 'System.String'
}
{
Name: 'ConfigurationMode'
Value: ConfigurationMode[Environment]
TypeName: 'System.String'
}
{
Name: 'RebootNodeIfNeeded'
Value: RebootNodeLookup[Environment]
TypeName: 'System.Boolean'
}
{
Name: 'ConfigurationModeFrequencyMins'
Value: DSCConfigurationModeFrequencyMins
TypeName: 'System.Int32'
}
{
Name: 'RefreshFrequencyMins'
Value: 30
TypeName: 'System.Int32'
}
{
Name: 'ActionAfterReboot'
Value: 'ContinueConfiguration'
TypeName: 'System.String'
}
{
Name: 'AllowModuleOverwrite'
Value: true
TypeName: 'System.Boolean'
}
]
}
}
dependsOn: [
AppServerDomainJoin
]
}
// resource UAILocal 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
// name: '${Deployment}-uaiStorageAccountOperator'
// scope: resourceGroup(RGName)
// }
resource UAIGlobal 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = {
name: '${Deployment}-uaiStorageAccountFileContributor'
scope: resourceGroup(RGName)
}
resource AppServerDSC 'Microsoft.Compute/virtualMachines/extensions@2021-11-01' = if (VM.match && bool(VM.Extensions.DSC) && !(contains(AppServer, 'DSC') && AppServer.DSC == 'PULL')) {
name: 'Microsoft.Powershell.DSC'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: (OSType[AppServer.OSType].OS == 'Windows' ? 'Microsoft.Powershell' : 'Microsoft.OSTCExtensions')
type: (OSType[AppServer.OSType].OS == 'Windows' ? 'DSC' : 'DSCForLinux')
typeHandlerVersion: (OSType[AppServer.OSType].OS == 'Windows' ? '2.77' : '2.0')
autoUpgradeMinorVersion: true
forceUpdateTag: deploymentTime
settings: {
wmfVersion: 'latest'
configuration: {
url: '${Global._artifactsLocation}/ext-DSC/DSC-${(contains(AppServer, 'DSConfig') ? AppServer.DSConfig : (contains(DSCConfigLookup, DeploymentName) ? DSCConfigLookup[DeploymentName] : DeploymentName))}.zip'
script: 'DSC-${(contains(AppServer, 'DSConfig') ? AppServer.DSConfig : (contains(DSCConfigLookup, DeploymentName) ? DSCConfigLookup[DeploymentName] : DeploymentName))}.ps1'
function: (contains(AppServer, 'DSConfig') ? AppServer.DSConfig : (contains(DSCConfigLookup, DeploymentName) ? DSCConfigLookup[DeploymentName] : DeploymentName))
}
configurationArguments: {
DomainName: Global.ADDomainName
Thumbprint: Global.?CertThumbprint
storageAccountId: saaccountidglobalsource.id
deployment: Deployment
networkid: '${networkId.upper}.${contains(lowerLookup, AppServer.NICs[0].subnet) ? int(networkId.lower) + (1 * lowerLookup[AppServer.NICs[0].subnet]) : networkId.lower}.'
appInfo: contains(AppServer, 'AppInfo') ? string(VM.AppInfo) : ''
DataDiskInfo: string(VM.DataDisk)
// clientIDLocal: '${Environment}${DeploymentID}' == 'G0' ? '' : UAILocal.properties.clientId
clientIDGlobal: '${Environment}${DeploymentID}' == 'G0' ? '' : UAIGlobal.properties.clientId
}
configurationData: {
url: '${Global._artifactsLocation}/ext-CD/${AppServer.Role}-ConfigurationData.psd1'
}
}
protectedSettings: {
configurationArguments: {
AdminCreds: {
UserName: Global.vmAdminUserName
Password: vmAdminPassword
}
sshPublic: {
UserName: 'ssh'
Password: sshPublic
}
devOpsPat: {
UserName: 'pat'
Password: devOpsPat
}
}
configurationUrlSasToken: '?${DSCSAS}'
configurationDataUrlSasToken: '?${DSCSAS}'
}
}
dependsOn: [
AppServerDomainJoin
]
}
resource AppServerDiags 'Microsoft.Compute/virtualMachines/extensions@2020-12-01' = if (VM.match && bool(VM.Extensions.IaaSDiagnostics)) {
name: 'vmDiagnostics'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.Azure.Diagnostics'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'IaaSDiagnostics' : 'LinuxDiagnostic'
typeHandlerVersion: (OSType[AppServer.OSType].OS == 'Windows' ? '1.9' : '3.0')
autoUpgradeMinorVersion: true
settings: {
WadCfg: OSType[AppServer.OSType].OS == 'Windows' ? WadCfg : null
ladCfg: OSType[AppServer.OSType].OS == 'Windows' ? null : ladCfg
StorageAccount: saaccountiddiag
StorageType: 'TableAndBlob'
}
protectedSettings: {
storageAccountName: saaccountiddiag
storageAccountKey: listKeys(saaccountiddiag, '2016-01-01').keys[0].value
storageAccountEndPoint: 'https://${environment().suffixes.storage}/'
}
}
}
// SF ✅
resource AppServerDependencyAgent 'Microsoft.Compute/virtualMachines/extensions@2020-12-01' = if (VM.match && bool(VM.Extensions.DependencyAgent)) {
name: 'DependencyAgent'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.Azure.Monitoring.DependencyAgent'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'DependencyAgentWindows' : 'DependencyAgentLinux'
typeHandlerVersion: '9.0'
autoUpgradeMinorVersion: true
}
}
// SF ✅
resource AppServerAzureMonitor 'Microsoft.Compute/virtualMachines/extensions@2020-12-01' = if (VM.match && bool(VM.Extensions.AzureMonitorAgent)) {
name: OSType[AppServer.OSType].OS == 'Windows' ? 'AzureMonitorWindowsAgent' : 'AzureMonitorLinuxAgent'
parent: virtualMachine
location: resourceGroup().location
properties: {
autoUpgradeMinorVersion: true
publisher: 'Microsoft.Azure.Monitor'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'AzureMonitorWindowsAgent' : 'AzureMonitorLinuxAgent'
typeHandlerVersion: OSType[AppServer.OSType].OS == 'Windows' ? '1.0' : '1.5'
}
}
// SF ✅ - this is now deprecated
//
resource AppServerMonitoringAgent 'Microsoft.Compute/virtualMachines/extensions@2020-12-01' = if (VM.match && bool(VM.Extensions.MonitoringAgent)) {
name: 'MonitoringAgent'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.EnterpriseCloud.Monitoring'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'MicrosoftMonitoringAgent' : 'OmsAgentForLinux'
typeHandlerVersion: OSType[AppServer.OSType].OS == 'Windows' ? '1.0' : '1.4'
autoUpgradeMinorVersion: true
settings: {
workspaceId: OMS.properties.customerId
}
protectedSettings: {
workspaceKey: OMS.listKeys().primarySharedKey
}
}
dependsOn: [
AppServerAzureMonitor
AppServerDSC
]
}
resource AzureGuestConfig 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && bool(VM.Extensions.GuestConfig)) {
name: 'AzureGuestConfig'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.GuestConfiguration'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'ConfigurationForWindows' : 'ConfigurationForLinux'
typeHandlerVersion: '1.2'
autoUpgradeMinorVersion: true
settings: {}
}
}
resource AppServerGuestHealth 'Microsoft.Compute/virtualMachines/extensions@2020-12-01' = if (VM.match && bool(VM.Extensions.GuestHealthAgent)) {
name: (OSType[AppServer.OSType].OS == 'Windows' ? 'GuestHealthWindowsAgent' : 'GuestHealthLinuxAgent')
parent: virtualMachine
location: resourceGroup().location
properties: {
autoUpgradeMinorVersion: true
publisher: 'Microsoft.Azure.Monitor.VirtualMachines.GuestHealth'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'GuestHealthWindowsAgent' : 'GuestHealthLinuxAgent'
typeHandlerVersion: (OSType[AppServer.OSType].OS == 'Windows' ? '1.0' : '1.0')
}
dependsOn: [
AppServerAzureMonitor
AppServerMonitoringAgent
AppServerDSC
]
}
resource vmInsights 'Microsoft.Insights/dataCollectionRuleAssociations@2019-11-01-preview' = {
name: '${DeploymentURI}vmInsights'
scope: virtualMachine
properties: {
description: 'Association of data collection rule for AppServer Insights Health.'
dataCollectionRuleId: resourceId('Microsoft.Insights/dataCollectionRules', '${DeploymentURI}vmInsights')
}
}
resource AppServerChefClient 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && bool(VM.Extensions.chefClient)) {
name: 'chefClient'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Chef.Bootstrap.WindowsAzure'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'ChefClient' : 'LinuxChefClient'
typeHandlerVersion: '1210.12'
settings: {
bootstrap_options: {
chef_server_url: Global.chef_server_url
validation_client_name: Global.chef_validation_client_name
}
runlist: 'recipe[mycookbook::default]'
}
protectedSettings: {
validation_key: Global.chef_validation_key
}
}
}
resource AppServerSqlIaasExtension 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && AppServer.role == 'SQL' && bool(VM.Extensions.SqlIaasExtension)) {
name: 'SqlIaasExtension'
parent: virtualMachine
location: resourceGroup().location
properties: {
type: 'SqlIaaSAgent'
publisher: 'Microsoft.SqlServer.Management'
typeHandlerVersion: '1.2'
autoUpgradeMinorVersion: true
settings: {
AutoTelemetrySettings: {
Region: resourceGroup().location
}
KeyVaultCredentialSettings: {
Enable: true
CredentialName: Global.sqlCredentialName
}
// AutoBackupSettings: {
// Enable: true,
// RetentionPeriod: 5
// EnableEncryption: true
// }
}
protectedSettings: {
PrivateKeyVaultCredentialSettings: {
AzureKeyVaultUrl: KV.properties.vaultUri
// ServicePrincipalName: Global.sqlBackupservicePrincipalName
// ServicePrincipalSecret: Global.sqlBackupservicePrincipalSecret
StorageUrl: reference(resourceId('Microsoft.Storage/storageAccounts', ((AppServer.Role == 'SQL') ? saSQLBackupName : SADiagName)), '2015-06-15').primaryEndpoints.blob
StorageAccessKey: listKeys(resourceId('Microsoft.Storage/storageAccounts', ((AppServer.Role == 'SQL') ? saSQLBackupName : SADiagName)), '2016-01-01').keys[0].value
Password: vmAdminPassword
}
}
}
}
resource AppServerAzureBackupWindowsWorkload 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && AppServer.role == 'SQL' && bool(VM.Extensions.BackupWindowsWorkloadSQL)) {
name: 'AzureBackupWindowsWorkload'
parent: virtualMachine
location: resourceGroup().location
properties: {
autoUpgradeMinorVersion: true
settings: {
locale: 'en-us'
AppServerType: 'microsoft.compute/virtualmachines'
}
publisher: 'Microsoft.Azure.RecoveryServices.WorkloadBackup'
type: 'AzureBackupWindowsWorkload'
typeHandlerVersion: '1.1'
}
}
resource AppServerIaaSAntimalware 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (VM.match && bool(VM.Extensions.Antimalware)) {
name: 'IaaSAntimalware'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.Azure.Security'
type: 'IaaSAntimalware'
typeHandlerVersion: '1.5'
autoUpgradeMinorVersion: true
settings: {
Monitoring: 'ON'
StorageAccountName: SADiagName
AntimalwareEnabled: true
RealtimeProtectionEnabled: 'true'
ScheduledScanSettings: {
isEnabled: 'true'
day: '1'
time: '720'
scanType: 'Full'
}
Exclusions: {
Extensions: ''
Paths: ''
Processes: ''
}
}
protectedSettings: null
}
}
module HRWorker 'x.hybridRunbookWorker.bicep' = if (bool(AppServer.?HRW ?? false)) {
name: '${Deployment}-HRWorker-${AppServer.Name}'
// scope: resourceGroup(HubRGName)
params: {
AAName: AA.name
HRWGroupName: '${Deployment}-vn'
vmResourceId: virtualMachine.id
}
}
resource HRW 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = if (bool(AppServer.?HRW ?? false)) {
name: 'HybridWorkerExtension'
parent: virtualMachine
location: resourceGroup().location
properties: {
publisher: 'Microsoft.Azure.Automation.HybridWorker'
type: OSType[AppServer.OSType].OS == 'Windows' ? 'HybridWorkerForWindows' : 'HybridWorkerForLinux'
typeHandlerVersion: '1.1'
autoUpgradeMinorVersion: true
enableAutomaticUpgrade: true
settings: {
#disable-next-line BCP053
AutomationAccountURL: AA.properties.automationHybridServiceUrl
}
}
}
var policyName = 'DefaultPolicy'
resource RSV 'Microsoft.RecoveryServices/vaults@2016-06-01' existing = {
name: '${DeploymentURI}rsv01'
#disable-next-line BCP081
resource Fabric 'backupFabrics' existing = {
name: 'Azure'
resource protectedVM 'protectionContainers' existing = {
name: 'IaasVMContainer;iaasvmcontainerv2;${resourceGroup().name};${virtualMachine.name}'
resource protectedVM 'protectedItems' = if (VM.match && bool(VM.Extensions.?protectedVM ?? 0)) {
name: toLower('vm;iaasvmcontainerv2;${resourceGroup().name};${virtualMachine.name}')
properties: {
friendlyName: virtualMachine.name
protectedItemType: 'Microsoft.ClassicCompute/virtualMachines'
policyId: resourceId('Microsoft.RecoveryServices/vaults/backupPolicies', RSV.name, policyName)
sourceResourceId: virtualMachine.id
}
}
}
}
}
// resource windowsOpenSSHExtension 'Microsoft.Compute/virtualMachines/extensions@2022-11-01' = if(OSType[AppServer.OSType].OS == 'Windows') {
// name: 'WindowsOpenSSH'
// parent: virtualMachine
// location: resourceGroup().location
// properties: {
// publisher: 'Microsoft.Azure.OpenSSH'
// type: 'WindowsOpenSSH'
// typeHandlerVersion: '3.0'
// }
// }
var runCommandsScriptLookup = {
'setupUbuntu.sh': loadTextContent('loadTextContext/setupUbuntu.sh')
'setupWindows.ps1': loadTextContent('loadTextContext/setupWindows.ps1')
}
resource runCommands 'Microsoft.Compute/virtualMachines/runCommands@2022-11-01' = if (contains(AppServer, 'runCommands')) {
name: 'runCommands'
location: resourceGroup().location
parent: virtualMachine
properties: {
timeoutInSeconds: (60 * 90)