-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.bicep
521 lines (450 loc) · 19 KB
/
main.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
@description('The base URI where artifacts required by this template are located.')
param artifactsLocation string = 'https://raw.githubusercontent.com/Azure/RDS-Templates/master/ARM-wvd-templates/DSC/Configuration.zip'
@description('The name of the Hostpool to be created.')
param hostpoolName string
@description('The friendly name of the Hostpool to be created.')
param hostpoolFriendlyName string = ''
@description('The description of the Hostpool to be created.')
param hostpoolDescription string = ''
@description('The location where the resources will be deployed.')
param location string
@description('The name of the workspace to be attach to new Applicaiton Group.')
param workSpaceName string = ''
@description('The location of the workspace.')
param workspaceLocation string = ''
@description('The workspace resource group Name.')
param workspaceResourceGroup string = ''
@description('The existing app groups references of the workspace selected.')
param allApplicationGroupReferences string = ''
@description('Whether to add applicationGroup to workspace.')
param addToWorkspace bool
@description('A username in the domain that has privileges to join the session hosts to the domain. For example, \'[email protected]\'.')
param administratorAccountUsername string = ''
@description('The password that corresponds to the existing domain username.')
@secure()
param administratorAccountPassword string = ''
@description('A username to be used as the virtual machine administrator account. The vmAdministratorAccountUsername and vmAdministratorAccountPassword parameters must both be provided. Otherwise, domain administrator credentials provided by administratorAccountUsername and administratorAccountPassword will be used.')
param vmAdministratorAccountUsername string = ''
@description('The password associated with the virtual machine administrator account. The vmAdministratorAccountUsername and vmAdministratorAccountPassword parameters must both be provided. Otherwise, domain administrator credentials provided by administratorAccountUsername and administratorAccountPassword will be used.')
@secure()
param vmAdministratorAccountPassword string = ''
@allowed([
'None'
'AvailabilitySet'
'AvailabilityZone'
])
@description('Select the availability options for the VMs.')
param availabilityOption string = 'None'
@description('The name of avaiability set to be used when create the VMs.')
param availabilitySetName string = ''
@description('Whether to create a new availability set for the VMs.')
param createAvailabilitySet bool = false
@allowed([
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
])
@description('The platform update domain count of avaiability set to be created.')
param availabilitySetUpdateDomainCount int = 5
@allowed([
1
2
3
])
@description('The platform fault domain count of avaiability set to be created.')
param availabilitySetFaultDomainCount int = 2
@allowed([
1
2
3
])
@description('The number of availability zone to be used when create the VMs.')
param availabilityZone int = 1
@description('The resource group of the session host VMs.')
param vmResourceGroup string = ''
@description('The location of the session host VMs.')
param vmLocation string = ''
@description('The size of the session host VMs.')
param vmSize string = ''
@description('Number of session hosts that will be created and added to the hostpool.')
param vmNumberOfInstances int = 0
@description('This prefix will be used in combination with the VM number to create the VM name. If using \'rdsh\' as the prefix, VMs would be named \'rdsh-0\', \'rdsh-1\', etc. You should use a unique prefix to reduce name collisions in Active Directory.')
param vmNamePrefix string = ''
@allowed([
'CustomVHD'
'CustomImage'
'Gallery'
])
@description('Select the image source for the session host vms. VMs from a Gallery image will be created with Managed Disks.')
param vmImageType string = 'Gallery'
@description('(Required when vmImageType = Gallery) Gallery image Offer.')
param vmGalleryImageOffer string = ''
@description('(Required when vmImageType = Gallery) Gallery image Publisher.')
param vmGalleryImagePublisher string = ''
@description('(Required when vmImageType = Gallery) Gallery image SKU.')
param vmGalleryImageSKU string = ''
@description('(Required when vmImageType = CustomVHD) URI of the sysprepped image vhd file to be used to create the session host VMs. For example, https://rdsstorage.blob.core.windows.net/vhds/sessionhostimage.vhd')
param vmImageVhdUri string = ''
@description('(Required when vmImageType = CustomImage) Resource ID of the image')
param vmCustomImageSourceId string = ''
@allowed([
'Premium_LRS'
'StandardSSD_LRS'
'Standard_LRS'
])
@description('The VM disk type for the VM: HDD or SSD.')
param vmDiskType string = 'StandardSSD_LRS'
@description('True indicating you would like to use managed disks or false indicating you would like to use unmanaged disks.')
param vmUseManagedDisks bool = true
@description('(Required when vmUseManagedDisks = False) The resource group containing the storage account of the image vhd file.')
param storageAccountResourceGroupName string = ''
@description('The name of the virtual network the VMs will be connected to.')
param existingVnetName string = ''
@description('The subnet the VMs will be placed in.')
param existingSubnetName string = ''
@description('The resource group containing the existing virtual network.')
param virtualNetworkResourceGroupName string = ''
@description('Whether to create a new network security group or use an existing one')
param createNetworkSecurityGroup bool = false
@description('The resource id of an existing network security group')
param networkSecurityGroupId string = ''
@description('The rules to be given to the new network security group')
param networkSecurityGroupRules array = []
@allowed([
'Personal'
'Pooled'
])
@description('Set this parameter to Personal if you would like to enable Persistent Desktop experience. Defaults to false.')
param hostpoolType string
@allowed([
'Automatic'
'Direct'
''
])
@description('Set the type of assignment for a Personal hostpool type')
param personalDesktopAssignmentType string = ''
@description('Maximum number of sessions.')
param maxSessionLimit int = 99999
@allowed([
'BreadthFirst'
'DepthFirst'
'Persistent'
])
@description('Type of load balancer algorithm.')
param loadBalancerType string = 'BreadthFirst'
@description('Hostpool rdp properties')
param customRdpProperty string = ''
@description('The necessary information for adding more VMs to this Hostpool')
param vmTemplate string = ''
@description('Hostpool token expiration time')
param tokenExpirationTime string
@description('The tags to be assigned to the hostpool')
param hostpoolTags object = {}
@description('The tags to be assigned to the application group')
param applicationGroupTags object = {}
@description('The tags to be assigned to the availability set')
param availabilitySetTags object = {}
@description('The tags to be assigned to the network interfaces')
param networkInterfaceTags object = {}
@description('The tags to be assigned to the network security groups')
param networkSecurityGroupTags object = {}
@description('The tags to be assigned to the virtual machines')
param virtualMachineTags object = {}
@description('The tags to be assigned to the images')
param imageTags object = {}
@description('WVD api version')
param apiVersion string = '2019-12-10-preview'
@description('GUID for the deployment')
param deploymentId string = ''
@description('Whether to use validation enviroment.')
param validationEnvironment bool = false
@description('Preferred App Group type to display')
param preferredAppGroupType string = 'Desktop'
@description('OUPath for the domain join')
param ouPath string = ''
@description('Domain to join')
param domain string = ''
@description('IMPORTANT: Please don\'t use this parameter as AAD Join is not supported yet. True if AAD Join, false if AD join')
param aadJoin bool = false
@description('IMPORTANT: Please don\'t use this parameter as intune enrollment is not supported yet. True if intune enrollment is selected. False otherwise')
param intune bool = false
var createVMs = (vmNumberOfInstances > 0)
var rdshManagedDisks = ((vmImageType == 'CustomVHD') ? vmUseManagedDisks : bool('true'))
var rdshPrefix = '${vmNamePrefix}-'
var avSetSKU = (rdshManagedDisks ? 'Aligned' : 'Classic')
var vhds = 'vhds/${rdshPrefix}'
var subnet_id = resourceId(virtualNetworkResourceGroupName, 'Microsoft.Network/virtualNetworks/subnets', existingVnetName, existingSubnetName)
var hostpoolName_var = replace(hostpoolName, '"', '')
var rdshVmNamesOutput = [for j in range(0, (createVMs ? vmNumberOfInstances : 1)): {
name: '${rdshPrefix}${j}'
}]
var appGroupName_var = '${hostpoolName_var}-DAG'
var appGroupResourceId = [
resourceId('Microsoft.DesktopVirtualization/applicationgroups/', appGroupName_var)
]
var workspaceResourceGroup_var = (empty(workspaceResourceGroup) ? resourceGroup().name : workspaceResourceGroup)
var applicationGroupReferencesArr = (('' == allApplicationGroupReferences) ? appGroupResourceId : concat(split(allApplicationGroupReferences, ','), appGroupResourceId))
var hostpoolRequiredProps = {
friendlyName: hostpoolFriendlyName
description: hostpoolDescription
hostpoolType: hostpoolType
personalDesktopAssignmentType: personalDesktopAssignmentType
maxSessionLimit: maxSessionLimit
loadBalancerType: loadBalancerType
validationEnvironment: validationEnvironment
preferredAppGroupType: preferredAppGroupType
ring: null
registrationInfo: {
expirationTime: tokenExpirationTime
token: null
registrationTokenOperation: 'Update'
}
vmTemplate: vmTemplate
}
var hostpoolOptionalProps = {
customRdpProperty: customRdpProperty
}
resource hostpool 'Microsoft.DesktopVirtualization/hostpools@2019-12-10-preview' = {
name: hostpoolName
location: location
tags: hostpoolTags
properties: (empty(customRdpProperty) ? hostpoolRequiredProps : union(hostpoolOptionalProps, hostpoolRequiredProps))
}
resource appGroupName 'Microsoft.DesktopVirtualization/applicationgroups@2019-12-10-preview' = {
name: appGroupName_var
location: location
tags: applicationGroupTags
properties: {
hostPoolArmPath: hostpool.id
friendlyName: 'Default Desktop'
description: 'Desktop Application Group created through the Hostpool Wizard'
applicationGroupType: 'Desktop'
}
}
module workspace './modules/workspace.bicep' = if (addToWorkspace) {
name: 'Workspace-linkedTemplate-${deploymentId}'
scope: resourceGroup(workspaceResourceGroup_var)
params: {
//apiVersion: apiVersion
workSpaceName: workSpaceName
workspaceLocation: workspaceLocation
applicationGroupReferencesArr: applicationGroupReferencesArr
}
}
module AVSet './modules/AVSet.bicep' = if (createVMs && (availabilityOption == 'AvailabilitySet') && createAvailabilitySet) {
name: 'AVSet-deployment' //'AVSet-linkedTemplate-${deploymentId}'
scope: resourceGroup(vmResourceGroup)
params: {
availabilitySetName: availabilitySetName
vmLocation: vmLocation
availabilitySetTags: availabilitySetTags
availabilitySetUpdateDomainCount: availabilitySetUpdateDomainCount
availabilitySetFaultDomainCount: availabilitySetFaultDomainCount
avSetSKU: avSetSKU
}
dependsOn: [
appGroupName
]
}
// Deploy vmImageType = CustomVHD, managed disks
module vmCreation_customVHD_managedDisks './modules/managedDisks-customvhdvm.bicep' = if ((createVMs) && (vmImageType == 'CustomVHD') && (vmUseManagedDisks)) {
name: 'vmCreation-linkedTemplate-${deploymentId}-managedDisks-customvhdvm'
scope: resourceGroup(vmResourceGroup)
params: {
artifactsLocation: artifactsLocation
availabilityOption: availabilityOption
availabilitySetName: availabilitySetName
availabilityZone: availabilityZone
vmImageVhdUri: vmImageVhdUri
storageAccountResourceGroupName: storageAccountResourceGroupName
vmGalleryImageOffer: vmGalleryImageOffer
vmGalleryImagePublisher: vmGalleryImagePublisher
vmGalleryImageSKU: vmGalleryImageSKU
rdshPrefix: rdshPrefix
rdshNumberOfInstances: vmNumberOfInstances
rdshVMDiskType: vmDiskType
rdshVmSize: vmSize
enableAcceleratedNetworking: false
vmAdministratorAccountUsername: vmAdministratorAccountUsername
vmAdministratorAccountPassword: vmAdministratorAccountPassword
administratorAccountUsername: administratorAccountUsername
administratorAccountPassword: administratorAccountPassword
subnet_id: subnet_id
vhds: vhds
rdshImageSourceId: vmCustomImageSourceId
location: vmLocation
createNetworkSecurityGroup: createNetworkSecurityGroup
networkSecurityGroupId: networkSecurityGroupId
networkSecurityGroupRules: networkSecurityGroupRules
networkInterfaceTags: networkInterfaceTags
networkSecurityGroupTags: networkSecurityGroupTags
virtualMachineTags: virtualMachineTags
imageTags: imageTags
hostpoolToken: reference(hostpoolName).registrationInfo.token
hostpoolName: hostpoolName
domain: domain
ouPath: ouPath
aadJoin: aadJoin
intune: intune
guidValue: deploymentId
}
dependsOn: [
AVSet
]
}
// Deploy vmImageType = CustomVHD, unmanaged disks
module vmCreation_customVHD_unmanagedDisks './modules/unmanagedDisks-customvhdvm.bicep' = if ((createVMs) && (vmImageType == 'CustomVHD') && (!vmUseManagedDisks)) {
name: 'vmCreation-linkedTemplate-${deploymentId}-unmanagedDisks-customvhdvm'
scope: resourceGroup(vmResourceGroup)
params: {
artifactsLocation: artifactsLocation
availabilityOption: availabilityOption
availabilitySetName: availabilitySetName
availabilityZone: availabilityZone
vmImageVhdUri: vmImageVhdUri
storageAccountResourceGroupName: storageAccountResourceGroupName
vmGalleryImageOffer: vmGalleryImageOffer
vmGalleryImagePublisher: vmGalleryImagePublisher
vmGalleryImageSKU: vmGalleryImageSKU
rdshPrefix: rdshPrefix
rdshNumberOfInstances: vmNumberOfInstances
rdshVMDiskType: vmDiskType
rdshVmSize: vmSize
enableAcceleratedNetworking: false
vmAdministratorAccountUsername: vmAdministratorAccountUsername
vmAdministratorAccountPassword: vmAdministratorAccountPassword
administratorAccountUsername: administratorAccountUsername
administratorAccountPassword: administratorAccountPassword
subnet_id: subnet_id
vhds: vhds
rdshImageSourceId: vmCustomImageSourceId
location: vmLocation
createNetworkSecurityGroup: createNetworkSecurityGroup
networkSecurityGroupId: networkSecurityGroupId
networkSecurityGroupRules: networkSecurityGroupRules
networkInterfaceTags: networkInterfaceTags
networkSecurityGroupTags: networkSecurityGroupTags
virtualMachineTags: virtualMachineTags
imageTags: imageTags
hostpoolToken: reference(hostpoolName).registrationInfo.token
hostpoolName: hostpoolName
domain: domain
ouPath: ouPath
aadJoin: aadJoin
intune: intune
guidValue: deploymentId
}
dependsOn: [
AVSet
]
}
// Deploy vmImageType = CustomImage
module vmCreation_customeImage './modules/managedDisks-customimagevm.bicep' = if ((createVMs) && (vmImageType == 'CustomImage')) {
name: 'vmCreation-linkedTemplate-${deploymentId}-managedDisks-customimagevm'
scope: resourceGroup(vmResourceGroup)
params: {
artifactsLocation: artifactsLocation
availabilityOption: availabilityOption
availabilitySetName: availabilitySetName
availabilityZone: availabilityZone
vmImageVhdUri: vmImageVhdUri
storageAccountResourceGroupName: storageAccountResourceGroupName
vmGalleryImageOffer: vmGalleryImageOffer
vmGalleryImagePublisher: vmGalleryImagePublisher
vmGalleryImageSKU: vmGalleryImageSKU
rdshPrefix: rdshPrefix
rdshNumberOfInstances: vmNumberOfInstances
rdshVMDiskType: vmDiskType
rdshVmSize: vmSize
enableAcceleratedNetworking: false
vmAdministratorAccountUsername: vmAdministratorAccountUsername
vmAdministratorAccountPassword: vmAdministratorAccountPassword
administratorAccountUsername: administratorAccountUsername
administratorAccountPassword: administratorAccountPassword
subnet_id: subnet_id
vhds: vhds
rdshImageSourceId: vmCustomImageSourceId
location: vmLocation
createNetworkSecurityGroup: createNetworkSecurityGroup
networkSecurityGroupId: networkSecurityGroupId
networkSecurityGroupRules: networkSecurityGroupRules
networkInterfaceTags: networkInterfaceTags
networkSecurityGroupTags: networkSecurityGroupTags
virtualMachineTags: virtualMachineTags
imageTags: imageTags
hostpoolToken: reference(hostpoolName).registrationInfo.token
hostpoolName: hostpoolName
domain: domain
ouPath: ouPath
aadJoin: aadJoin
intune: intune
guidValue: deploymentId
}
dependsOn: [
AVSet
]
}
// Deploy vmImageType = CustomVHD, managed disks
module vmCreation_Gallery './modules/managedDisks-galleryvm.bicep' = if ((createVMs) && (vmImageType == 'Gallery') && (vmUseManagedDisks)) {
name: 'vmCreation-linkedTemplate-${deploymentId}-managedDisks-galleryvm'
scope: resourceGroup(vmResourceGroup)
params: {
artifactsLocation: artifactsLocation
availabilityOption: availabilityOption
availabilitySetName: availabilitySetName
availabilityZone: availabilityZone
vmImageVhdUri: vmImageVhdUri
storageAccountResourceGroupName: storageAccountResourceGroupName
vmGalleryImageOffer: vmGalleryImageOffer
vmGalleryImagePublisher: vmGalleryImagePublisher
vmGalleryImageSKU: vmGalleryImageSKU
rdshPrefix: rdshPrefix
rdshNumberOfInstances: vmNumberOfInstances
rdshVMDiskType: vmDiskType
rdshVmSize: vmSize
enableAcceleratedNetworking: false
vmAdministratorAccountUsername: vmAdministratorAccountUsername
vmAdministratorAccountPassword: vmAdministratorAccountPassword
administratorAccountUsername: administratorAccountUsername
administratorAccountPassword: administratorAccountPassword
subnet_id: subnet_id
vhds: vhds
rdshImageSourceId: vmCustomImageSourceId
location: vmLocation
createNetworkSecurityGroup: createNetworkSecurityGroup
networkSecurityGroupId: networkSecurityGroupId
networkSecurityGroupRules: networkSecurityGroupRules
networkInterfaceTags: networkInterfaceTags
networkSecurityGroupTags: networkSecurityGroupTags
virtualMachineTags: virtualMachineTags
imageTags: imageTags
hostpoolToken: reference(hostpoolName).registrationInfo.token
hostpoolName: hostpoolName
domain: domain
ouPath: ouPath
aadJoin: aadJoin
intune: intune
guidValue: deploymentId
}
dependsOn: [
AVSet
]
}
output rdshVmNamesObject array = rdshVmNamesOutput