-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.bicep
More file actions
479 lines (435 loc) · 13.8 KB
/
main.bicep
File metadata and controls
479 lines (435 loc) · 13.8 KB
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
@description('Location for the resources.')
param location string
@description('User name for the Virtual Machine.')
param adminUsername string
@allowed([
'password'
'sshPublicKey'
])
@description('Type of authentication to use on the Virtual Machine.')
param authenticationType string
@secure()
@description('Password or ssh key for the Virtual Machine.')
param adminPasswordOrKey string
@description('virtualNetwork properties from VirtualNetworkCombo')
param virtualNetwork object
// cClear
@description('cclear VM size')
param cClearVMSize string
@description('Number of cClears')
param cClearCount int = 0
@description('cClear VM Name')
param cClearVmName string
@description('cClear Image URI')
param cClearImage object
@description('cClear Image Version')
param cClearImageURI string = ''
// cVu
@description('cvu VM size')
param cvuVMSize string
@description('Number of cVus')
param cvuCount int = 3
@description('cVu Base VM Name')
param cvuVmName string
@description('cvu Image URI')
param cvuImage object
@description('cvu Image Version')
param cVuImageURI string = ''
@description('cVu 3rd Party Tools')
param cVu3rdPartyToolIPs string = ''
// cStor
@description('cvu VM size')
param cstorVMSize string
@description('Number of cStors')
param cstorCount int = 1
@description('cStor VM Name')
param cstorVmName string
@description('cStor Disk Count')
param cstorDiskCount int
@description('cStor Size Count')
param cstorDiskSize int
@description('cstor Image URI')
param cstorImage object
@description('cstor Image Version')
param cStorImageURI string = ''
@description('tags from TagsByResource')
param tagsByResource object
var cvulbName = '${cvuVmName}_iLB'
var cstorlbName = '${cstorVmName}_iLB'
var linuxConfiguration = {
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
path: '/home/${adminUsername}/.ssh/authorized_keys'
keyData: adminPasswordOrKey
}
]
}
}
var cclear_enabled = cClearCount > 0 ? true : false
var cvu_enabled = cvuCount > 0 ? true : false
var cstor_enabled = cstorCount > 0 ? true : false
var cstorilb_enabled = cstorCount > 1 ? true : false
var cvuilb_enabled = cvuCount > 1 ? true : false
var monsubnetId = virtualNetwork.newOrExisting == 'new' ? monsubnet.id : resourceId(virtualNetwork.resourceGroup, 'Microsoft.Network/virtualNetworks/subnets', virtualNetwork.name, virtualNetwork.subnets.monSubnet.name)
var cclearImageURI = empty(cClearImageURI) ? cClearImage.id : cClearImageURI
var cstorImageURI = empty(cStorImageURI) ? cstorImage.id : cStorImageURI
var cvuImageURI = empty(cVuImageURI) ? cvuImage.id : cVuImageURI
resource vnet 'Microsoft.Network/virtualNetworks@2020-11-01' = if (virtualNetwork.newOrExisting == 'new') {
name: virtualNetwork.name
location: location
properties: {
addressSpace: {
addressPrefixes: virtualNetwork.addressPrefixes
}
}
tags: contains(tagsByResource, 'Microsoft.Network/virtualNetworks') ? tagsByResource['Microsoft.Network/virtualNetworks'] : null
}
resource monsubnet 'Microsoft.Network/virtualNetworks/subnets@2020-11-01' = if (virtualNetwork.newOrExisting == 'new') {
name: virtualNetwork.subnets.monSubnet.name
parent: vnet
properties: {
addressPrefix: virtualNetwork.subnets.monSubnet.addressPrefix
}
}
/*
cClear Section
*/
resource cclearnic 'Microsoft.Network/networkInterfaces@2020-11-01' = [for i in range(0, cClearCount): if (cclear_enabled) {
name: '${cClearVmName}-${i}-nic'
location: location
properties: {
ipConfigurations: [
{
name: '${cClearVmName}-${i}-ipconfig-nic'
properties: {
subnet: {
id: monsubnetId
}
privateIPAllocationMethod: 'Dynamic'
}
}
]
}
tags: contains(tagsByResource, 'Microsoft.Network/networkInterfaces') ? tagsByResource['Microsoft.Network/networkInterfaces'] : null
}]
resource cclearvm 'Microsoft.Compute/virtualMachines@2021-03-01' = [for i in range(0, cClearCount): if (cclear_enabled) {
name: '${cClearVmName}-${i}'
location: location
properties: {
hardwareProfile: {
vmSize: cClearVMSize
}
storageProfile: {
imageReference: {
id: cclearImageURI
}
osDisk: {
osType: 'Linux'
createOption: 'FromImage'
caching: 'ReadWrite'
deleteOption: 'Delete'
}
dataDisks: [
{
name: '${cClearVmName}-${i}-DataDisk1'
lun: 1
createOption: 'Empty'
diskSizeGB: 500
caching: 'ReadWrite'
deleteOption: 'Delete'
}
]
}
networkProfile: {
networkInterfaces: [
{
id: cclearnic[i].id
}
]
}
osProfile: {
computerName: '${cClearVmName}-${i}'
adminUsername: adminUsername
adminPassword: adminPasswordOrKey
linuxConfiguration: any(authenticationType == 'password' ? null : linuxConfiguration) // TODO: workaround for https://github.com/Azure/bicep/issues/449
customData: loadFileAsBase64('./userdata-cclear.bash')
}
}
tags: contains(tagsByResource, 'Microsoft.Compute/virtualMachines') ? tagsByResource['Microsoft.Compute/virtualMachines'] : null
}]
/*
cStor Section
*/
resource cstorcapturenic 'Microsoft.Network/networkInterfaces@2020-11-01' = [for i in range(0, cstorCount): if (cstor_enabled) {
name: '${cstorVmName}-${i}-capture-nic'
location: location
dependsOn: any(cstorilb_enabled) ? [
cstorlb01
] : []
properties: {
ipConfigurations: [
{
name: '${cstorVmName}-${i}-capture-ipconfig-nic'
properties: {
subnet: {
id: monsubnetId
}
privateIPAllocationMethod: 'Dynamic'
loadBalancerBackendAddressPools: any(cstorilb_enabled) ? [
{
id: resourceId('Microsoft.Network/loadBalancers/backendAddressPools', cstorlbName, '${cstorlbName}-backend')
}
] : []
}
}
]
enableAcceleratedNetworking: true
enableIPForwarding: true
}
tags: contains(tagsByResource, 'Microsoft.Network/networkInterfaces') ? tagsByResource['Microsoft.Network/networkInterfaces'] : null
}]
resource cstorvm 'Microsoft.Compute/virtualMachines@2021-03-01' = [for i in range(0, cstorCount): if (cstor_enabled) {
name: '${cstorVmName}-${i}'
location: location
properties: {
hardwareProfile: {
vmSize: cstorVMSize
}
storageProfile: {
imageReference: {
id: cstorImageURI
}
osDisk: {
osType: 'Linux'
createOption: 'FromImage'
caching: 'ReadWrite'
deleteOption: 'Delete'
}
dataDisks: [ for j in range(0, cstorDiskCount): {
name: '${cstorVmName}-${i}-DataDisk-${j}'
lun: j
createOption: 'Empty'
diskSizeGB: cstorDiskSize
caching: 'ReadWrite'
//TODO: Make the delete option portal selectable
deleteOption: 'Delete'
}]
}
networkProfile: {
networkInterfaces: [
{
id: cstorcapturenic[i].id
properties: {
primary: true
}
}
]
}
osProfile: {
computerName: '${cstorVmName}-${i}'
adminUsername: adminUsername
adminPassword: adminPasswordOrKey
linuxConfiguration: any(authenticationType == 'password' ? null : linuxConfiguration) // TODO: workaround for https://github.com/Azure/bicep/issues/449
customData: loadFileAsBase64('./userdata-cstor.bash')
}
}
tags: contains(tagsByResource, 'Microsoft.Compute/virtualMachines') ? tagsByResource['Microsoft.Compute/virtualMachines'] : null
}]
resource cvucapturenic 'Microsoft.Network/networkInterfaces@2020-11-01' = [for i in range(0, cvuCount): if (cvu_enabled) {
name: '${cvuVmName}-${i}-capture-nic'
location: location
dependsOn: any(cvuilb_enabled) ? [
cvulb01
] : []
properties: {
ipConfigurations: [
{
name: '${cvuVmName}-${i}-capture-ipconfig-nic'
properties: {
subnet: {
id: monsubnetId
}
privateIPAllocationMethod: 'Dynamic'
loadBalancerBackendAddressPools: any(cvuilb_enabled) ? [
{
id: resourceId('Microsoft.Network/loadBalancers/backendAddressPools', cvulbName, '${cvulbName}-backend')
}
] : []
}
}
]
enableAcceleratedNetworking: true
enableIPForwarding: true
}
tags: contains(tagsByResource, 'Microsoft.Network/networkInterfaces') ? tagsByResource['Microsoft.Network/networkInterfaces'] : null
}]
resource cvuvm 'Microsoft.Compute/virtualMachines@2021-03-01' = [for i in range(0, cvuCount): if (cvu_enabled) {
name: '${cvuVmName}-${i}'
location: location
properties: {
hardwareProfile: {
vmSize: cvuVMSize
}
storageProfile: {
imageReference: {
id: cvuImageURI
}
osDisk: {
osType: 'Linux'
createOption: 'FromImage'
caching: 'ReadWrite'
deleteOption: 'Delete'
}
}
networkProfile: {
networkInterfaces: [
{
id: cvucapturenic[i].id
properties: {
primary: false
}
}
]
}
osProfile: {
computerName: '${cvuVmName}-${i}'
adminUsername: adminUsername
adminPassword: adminPasswordOrKey
linuxConfiguration: any(authenticationType == 'password' ? null : linuxConfiguration) // TODO: workaround for https://github.com/Azure/bicep/issues/449
customData: loadFileAsBase64('./userdata-cvu.bash')
}
}
tags: contains(tagsByResource, 'Microsoft.Compute/virtualMachines') ? tagsByResource['Microsoft.Compute/virtualMachines'] : null
}]
resource cvulb01 'Microsoft.Network/loadBalancers@2021-03-01' = if (cvuilb_enabled) {
name: cvulbName
location: location
sku: {
name: 'Standard'
tier: 'Regional'
}
properties: {
frontendIPConfigurations: [
{
name: '${cvulbName}-frontend'
properties: {
subnet: {
id: monsubnetId
}
}
}
]
backendAddressPools: [
{
name: '${cvulbName}-backend'
}
]
loadBalancingRules: [
{
name: '${cvulbName}-to_server'
properties: {
frontendIPConfiguration: {
id: resourceId('Microsoft.Network/loadBalancers/frontendIpConfigurations', cvulbName, '${cvulbName}-frontend')
}
backendAddressPool: {
id: resourceId('Microsoft.Network/loadBalancers/backendAddressPools', cvulbName, '${cvulbName}-backend')
}
probe: {
id: resourceId('Microsoft.Network/loadBalancers/probes', cvulbName, '${cvulbName}-probe')
}
frontendPort: 0
backendPort: 0
protocol: 'All'
}
}
]
probes: [
{
name: '${cvulbName}-probe'
properties: {
protocol: 'Tcp'
port: 22
intervalInSeconds: 15
numberOfProbes: 2
}
}
]
}
tags: contains(tagsByResource, 'Microsoft.Network/loadBalancers') ? tagsByResource['Microsoft.Network/loadBalancers'] : null
}
resource cstorlb01 'Microsoft.Network/loadBalancers@2021-03-01' = if (cstorilb_enabled) {
name: cstorlbName
location: location
sku: {
name: 'Standard'
tier: 'Regional'
}
properties: {
frontendIPConfigurations: [
{
name: '${cstorlbName}-frontend'
properties: {
subnet: {
id: monsubnetId
}
}
}
]
backendAddressPools: [
{
name: '${cstorlbName}-backend'
}
]
loadBalancingRules: [
{
name: '${cstorlbName}-to_server'
properties: {
frontendIPConfiguration: {
id: resourceId('Microsoft.Network/loadBalancers/frontendIpConfigurations', cstorlbName, '${cstorlbName}-frontend')
}
backendAddressPool: {
id: resourceId('Microsoft.Network/loadBalancers/backendAddressPools', cstorlbName, '${cstorlbName}-backend')
}
probe: {
id: resourceId('Microsoft.Network/loadBalancers/probes', cstorlbName, '${cstorlbName}-probe')
}
frontendPort: 0
backendPort: 0
protocol: 'All'
}
}
]
probes: [
{
name: '${cstorlbName}-probe'
properties: {
protocol: 'Tcp'
port: 22
intervalInSeconds: 15
numberOfProbes: 2
}
}
]
}
tags: contains(tagsByResource, 'Microsoft.Network/loadBalancers') ? tagsByResource['Microsoft.Network/loadBalancers'] : null
}
output To_Finish_Provisioning string = cclear_enabled ? 'ssh ${adminUsername}@${cclearnic[0].properties.ipConfigurations[0].properties.privateIPAddress}' : 'No cClear is Deployed. There is no action to take.'
output Copy_This_and_Paste_Into_ssh_Prompt string = cclear_enabled ? 'until [ -x /opt/cloud/deployer.py ]; do echo "still deploying, please wait..."; sleep 5; done; /opt/cloud/deployer.py' : 'No cClear is Deployed. There is no action to take.'
output cclear_ip string = cclear_enabled ? cclearnic[0].properties.ipConfigurations[0].properties.privateIPAddress : ''
output cvu_ilb_frontend_ip string = cvuilb_enabled ? cvulb01.properties.frontendIPConfigurations[0].properties.privateIPAddress : ''
output cvu_provisioning array = [for i in range(0, cvuCount): cvu_enabled ? {
'index': i
'name': cvuvm[i].name
'nic_name': cvucapturenic[i].name
'private_ip': cvucapturenic[i].properties.ipConfigurations[0].properties.privateIPAddress
} : []]
output cvu_3rd_party_tools string = cVu3rdPartyToolIPs
output cstor_ilb_frontend_ip string = cstorilb_enabled ? cstorlb01.properties.frontendIPConfigurations[0].properties.privateIPAddress : ''
output cstor_provisioning array = [for i in range(0, cstorCount): cstor_enabled ? {
'index': i
'name': cstorvm[i].name
'nic_name': cstorcapturenic[i].name
'private_ip': cstorcapturenic[i].properties.ipConfigurations[0].properties.privateIPAddress
} : []]