-
Notifications
You must be signed in to change notification settings - Fork 13
/
workload-stamp.bicep
544 lines (505 loc) · 16 KB
/
workload-stamp.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
@description('The location to deploy the workload stamp to.')
param location string = resourceGroup().location
@description('For Azure resources that support native geo-redundancy, provide the location the redundant service will have its secondary. Should be different than the location parameter and ideally should be a paired region - https://learn.microsoft.com/azure/best-practices-availability-paired-regions. This region does not need to support availability zones.')
@allowed([
'australiasoutheast'
'canadaeast'
'eastus2'
'westus'
'centralus'
'westcentralus'
'francesouth'
'germanynorth'
'westeurope'
'ukwest'
'northeurope'
'japanwest'
'southafricawest'
'northcentralus'
'eastasia'
'eastus'
'westus2'
'francecentral'
'uksouth'
'japaneast'
'southeastasia'
])
param geoRedundancyLocation string = 'centralus'
param droneSchedulerPrincipalId string
param workflowPrincipalId string
param deliveryPrincipalId string
param ingestionPrincipalId string
param packagePrincipalId string
var acrName = uniqueString('acr-', subscription().subscriptionId, resourceGroup().id)
var appInsightsName = 'ai-${uniqueString(resourceGroup().id)}'
var logAnaliticWorkpaceName = 'law-${uniqueString(resourceGroup().id)}'
var nestedACRDeploymentName = '${resourceGroup().name}-acr-deployment'
var deliveryRedisCacheSKU = 'Basic'
var deliveryRedisCacheFamily = 'C'
var deliveryRedisCacheCapacity = 0
var deliveryCosmosDbName = 'd-${uniqueString(resourceGroup().id)}'
var deliveryRedisName = 'dr-${uniqueString(resourceGroup().id)}'
var deliveryKeyVaultName = 'dkv-${uniqueString(resourceGroup().id)}'
var droneSchedulerCosmosDbName = 'ds-${uniqueString(resourceGroup().id)}'
var droneSchedulerKeyVaultName = 'ds-${uniqueString(resourceGroup().id)}'
var packageKeyVaultName = 'pkkv-${uniqueString(resourceGroup().id)}'
var packageMongoDbName = 'p-${uniqueString(resourceGroup().id)}'
var ingestionSBNamespaceName = 'i-${uniqueString(resourceGroup().id)}'
var ingestionSBNamespaceSKU = 'Premium'
var ingestionSBNamespaceTier = 'Premium'
var ingestionSBName = 'i-${uniqueString(resourceGroup().id)}'
var ingestionServiceAccessKeyName = 'IngestionServiceAccessKey'
var ingestionKeyVaultName = 'ingkv-${uniqueString(resourceGroup().id)}'
var workflowKeyVaultName = 'wf-${uniqueString(resourceGroup().id)}'
var workflowServiceAccessKeyName = 'WorkflowServiceAccessKey'
var keyVaultSecretsUserRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6')
@description('Built-in Role: Reader - https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#reader')
resource builtInReaderRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
name: 'acdd72a7-3385-48ef-bd42-f606fba81ae7'
scope: subscription()
}
module containerRegistry './nested_workload-stamp.bicep' = {
name: nestedACRDeploymentName
scope: resourceGroup('rg-shipping-dronedelivery-${location}-acr')
params: {
location: location
acrName: acrName
geoRedundancyLocation: geoRedundancyLocation
}
dependsOn: []
}
resource deliveryRedis 'Microsoft.Cache/Redis@2020-06-01' = {
name: deliveryRedisName
location: location
tags: {
displayName: 'Redis Cache for inflight deliveries'
app: 'fabrikam-delivery'
TODO: 'add log analytics resource'
}
properties: {
sku: {
capacity: deliveryRedisCacheCapacity
family: deliveryRedisCacheFamily
name: deliveryRedisCacheSKU
}
}
dependsOn: []
}
resource deliveryCosmosDb 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = {
name: deliveryCosmosDbName
location: location
tags: {
displayName: 'Delivery Cosmos Db'
app: 'fabrikam-delivery'
}
properties: {
databaseAccountOfferType: 'Standard'
isVirtualNetworkFilterEnabled: false
virtualNetworkRules: []
locations: [
{
locationName: location
failoverPriority: 0
}
]
}
dependsOn: []
}
resource packageMongoDb 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = {
name: packageMongoDbName
kind: 'MongoDB'
location: location
tags: {
displayName: 'Package Cosmos Db'
app: 'fabrikam-package'
}
properties: {
locations: [
{
locationName: location
failoverPriority: 0
}
]
databaseAccountOfferType: 'Standard'
isVirtualNetworkFilterEnabled: false
virtualNetworkRules: []
}
dependsOn: []
}
resource droneSchedulerCosmosDb 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = {
name: droneSchedulerCosmosDbName
location: location
tags: {
displayName: 'Drone Scheduler Cosmos Db'
app: 'fabrikam-dronescheduler'
}
properties: {
databaseAccountOfferType: 'Standard'
isVirtualNetworkFilterEnabled: false
virtualNetworkRules: []
locations: [
{
locationName: location
failoverPriority: 0
}
]
}
dependsOn: []
}
resource ingestionSBNamespace 'Microsoft.ServiceBus/namespaces@2022-10-01-preview' = {
name: ingestionSBNamespaceName
location: location
sku: {
name: ingestionSBNamespaceSKU
tier: ingestionSBNamespaceTier
}
tags: {
displayName: 'Ingestion and Workflow Service Bus'
app: 'fabrikam-ingestion and fabrikam-workflow'
'app-producer': 'fabrikam-ingestion'
'app-consumer': 'fabrikam-workflow'
}
}
resource ingestionSBNamespaceIngestionSB 'Microsoft.ServiceBus/namespaces/queues@2022-10-01-preview' = {
parent: ingestionSBNamespace
name: ingestionSBName
properties: {
lockDuration: 'PT5M'
maxSizeInMegabytes: 1024
}
}
resource ingestionSBNamespaceIngestionServiceAccessKey 'Microsoft.ServiceBus/namespaces/AuthorizationRules@2022-10-01-preview' = {
parent: ingestionSBNamespace
name: ingestionServiceAccessKeyName
properties: {
rights: [
'Send'
]
}
}
resource ingestionSBNamespaceWorkflowServiceAccessKey 'Microsoft.ServiceBus/namespaces/AuthorizationRules@2022-10-01-preview' = {
parent: ingestionSBNamespace
name: workflowServiceAccessKeyName
properties: {
rights: [
'Listen'
]
}
}
resource deliveryKeyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: deliveryKeyVaultName
location: location
tags: {
displayName: 'Delivery Key Vault'
app: 'fabrikam-delivery'
}
properties: {
sku: {
family: 'A'
name: 'standard'
}
tenantId: subscription().tenantId
networkAcls: {
bypass: 'AzureServices'
defaultAction: 'Allow'
virtualNetworkRules: []
}
enableRbacAuthorization: true
accessPolicies: []
}
resource secretCosmosDbEndpoint 'secrets' = {
name: 'CosmosDB-Endpoint'
properties: {
value: deliveryCosmosDb.properties.documentEndpoint
}
}
resource secretCosmosDbKey 'secrets' = {
name: 'CosmosDB-Key'
properties: {
value: deliveryCosmosDb.listKeys().primaryMasterKey
}
}
resource secretRedisEndpoint 'secrets' = {
name: 'Redis-Endpoint'
properties: {
value: deliveryRedis.properties.hostName
}
}
resource secretRedisAccessKey 'secrets' = {
name: 'Redis-AccessKey'
properties: {
value: deliveryRedis.listKeys().primaryKey
}
}
resource secretApplicationInsightsKey 'secrets' = {
name: 'ApplicationInsights--InstrumentationKey'
properties: {
value: appInsights.properties.InstrumentationKey
}
}
}
resource deliveryPrincipalKeyVaultSecretsUserRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: deliveryKeyVault
name: guid(deliveryPrincipalId, deliveryKeyVault.name, keyVaultSecretsUserRole)
properties: {
roleDefinitionId: keyVaultSecretsUserRole
principalId: deliveryPrincipalId
principalType: 'ServicePrincipal'
}
}
resource packageKeyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: packageKeyVaultName
location: location
tags: {
displayName: 'Package Key Vault'
app: 'fabrikam-package'
}
properties: {
sku: {
family: 'A'
name: 'standard'
}
tenantId: subscription().tenantId
networkAcls: {
bypass: 'AzureServices'
defaultAction: 'Allow'
virtualNetworkRules: []
}
enableRbacAuthorization: true
accessPolicies: []
}
resource secretApplicationInsightsKey 'secrets' = {
name: 'ApplicationInsights--InstrumentationKey'
properties: {
value: appInsights.properties.InstrumentationKey
}
}
}
resource packagePrincipalKeyVaultSecretsUserRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: packageKeyVault
name: guid(packagePrincipalId, packageKeyVault.name, keyVaultSecretsUserRole)
properties: {
roleDefinitionId: keyVaultSecretsUserRole
principalId: packagePrincipalId
principalType: 'ServicePrincipal'
}
}
resource ingestionKeyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: ingestionKeyVaultName
location: location
tags: {
displayName: 'Ingestion Key Vault'
app: 'fabrikam-ingestion'
}
properties: {
sku: {
family: 'A'
name: 'standard'
}
tenantId: subscription().tenantId
networkAcls: {
bypass: 'AzureServices'
defaultAction: 'Allow'
virtualNetworkRules: []
}
enableRbacAuthorization: true
accessPolicies: []
}
resource secretQueueKey 'secrets' = {
name: 'Queue--Key'
properties: {
value: ingestionSBNamespaceIngestionServiceAccessKey.listKeys().primaryKey
}
}
resource secretApplicationInsightsKey 'secrets' = {
name: 'ApplicationInsights--InstrumentationKey'
properties: {
value: appInsights.properties.InstrumentationKey
}
}
}
resource ingestionPrincipalVaultSecretsUserRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: ingestionKeyVault
name: guid(ingestionPrincipalId, ingestionKeyVault.name, keyVaultSecretsUserRole)
properties: {
roleDefinitionId: keyVaultSecretsUserRole
principalId: ingestionPrincipalId
principalType: 'ServicePrincipal'
}
}
resource droneSchedulerKeyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: droneSchedulerKeyVaultName
location: location
tags: {
displayName: 'DroneScheduler Key Vault'
app: 'fabrikam-dronescheduler'
}
properties: {
sku: {
family: 'A'
name: 'standard'
}
tenantId: subscription().tenantId
networkAcls: {
bypass: 'AzureServices'
defaultAction: 'Allow'
virtualNetworkRules: []
}
enableRbacAuthorization: true
accessPolicies: []
}
resource secretApplicationInsights 'secrets' = {
name: 'ApplicationInsights--InstrumentationKey'
properties: {
value: reference(appInsights.id, '2015-05-01').InstrumentationKey
}
}
resource secretCosmosDBKey 'secrets' = {
name: 'CosmosDBKey'
properties: {
value: droneSchedulerCosmosDb.listKeys().primaryMasterKey
}
}
}
resource droneSchedulerPrincipalKeyVaultSecretsUserRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: droneSchedulerKeyVault
name: guid(droneSchedulerPrincipalId, droneSchedulerKeyVault.name, keyVaultSecretsUserRole)
properties: {
roleDefinitionId: keyVaultSecretsUserRole
principalId: droneSchedulerPrincipalId
principalType: 'ServicePrincipal'
}
}
resource workflowKeyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: workflowKeyVaultName
location: location
tags: {
displayName: 'Workflow Key Vault'
app: 'fabrikam-workflow'
}
properties: {
sku: {
family: 'A'
name: 'standard'
}
tenantId: subscription().tenantId
networkAcls: {
bypass: 'AzureServices'
defaultAction: 'Allow'
virtualNetworkRules: []
}
enableRbacAuthorization: true
accessPolicies: []
}
resource secretQueueAccessPolicyKey 'secrets' = {
name: 'QueueAccessPolicyKey'
properties: {
value: listkeys(ingestionSBNamespaceWorkflowServiceAccessKey.id, '2017-04-01').primaryKey
}
}
resource secretApplicationInsights 'secrets' = {
name: 'ApplicationInsights--InstrumentationKey'
properties: {
value: reference(appInsights.id, '2015-05-01').InstrumentationKey
}
}
}
resource workflowPrincipalKeyVaultSecretsUserRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: workflowKeyVault
name: guid(workflowPrincipalId, workflowKeyVault.name, keyVaultSecretsUserRole)
properties: {
roleDefinitionId: keyVaultSecretsUserRole
principalId: workflowPrincipalId
principalType: 'ServicePrincipal'
}
}
resource LogAnaliticWorkpace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: logAnaliticWorkpaceName
location: location
properties: {
sku: {
name: 'pergb2018'
}
publicNetworkAccessForIngestion:'Enabled'
publicNetworkAccessForQuery:'Enabled'
}
}
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: appInsightsName
kind: 'other'
location: location
tags: {
displayName: 'App Insights instance - Distributed Tracing'
}
properties: {
Application_Type: 'other'
WorkspaceResourceId: LogAnaliticWorkpace.id
IngestionMode:'LogAnalytics'
publicNetworkAccessForIngestion:'Enabled'
publicNetworkAccessForQuery:'Enabled'
}
}
resource deliveryKeyVaultMicrosoftAuthorizationDeliveryIdNameIdReaderRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('${deliveryKeyVaultName}${resourceGroup().id}', builtInReaderRole.id)
scope: deliveryKeyVault
properties: {
roleDefinitionId: builtInReaderRole.id
principalId: deliveryPrincipalId
principalType: 'ServicePrincipal'
}
}
resource workflowKeyVaultNameMicrosoftAuthorizationWorkflowIdNameIdReaderRole 'Microsoft.Authorization/roleAssignments@2022-04-01'= {
name: guid('${workflowKeyVaultName}${resourceGroup().id}', builtInReaderRole.id)
scope: workflowKeyVault
properties: {
roleDefinitionId: builtInReaderRole.id
principalId: workflowPrincipalId
principalType: 'ServicePrincipal'
}
}
resource droneSchedulerKeyVaultNameMicrosoftAuthorizationDroneSchedulerIdNameIdReaderRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('${droneSchedulerKeyVaultName}${resourceGroup().id}', builtInReaderRole.id)
scope: droneSchedulerKeyVault
properties: {
roleDefinitionId: builtInReaderRole.id
principalId: droneSchedulerPrincipalId
principalType: 'ServicePrincipal'
}
}
resource ingestionKeyVaultNameMicrosoftAuthorizationIngestionIdNameIdReaderRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('${ingestionKeyVaultName}${resourceGroup().id}', builtInReaderRole.id)
scope: ingestionKeyVault
properties: {
roleDefinitionId: builtInReaderRole.id
principalId: ingestionPrincipalId
principalType: 'ServicePrincipal'
}
}
resource packageKeyVaultNameMicrosoftAuthorizationPackageIdNameIdReaderRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('${packageKeyVaultName}${resourceGroup().id}', builtInReaderRole.id)
scope: packageKeyVault
properties: {
roleDefinitionId: builtInReaderRole.id
principalId: packagePrincipalId
principalType: 'ServicePrincipal'
}
}
output acrId string = containerRegistry.outputs.acrId
output acrName string = acrName
output deliveryKeyVaultUri string = deliveryKeyVault.properties.vaultUri
output droneSchedulerKeyVaultUri string = droneSchedulerKeyVault.properties.vaultUri
output deliveryCosmosDbName string = deliveryCosmosDbName
output droneSchedulerCosmosDbName string = droneSchedulerCosmosDbName
output packageMongoDbName string = packageMongoDbName
output ingestionQueueNamespace string = ingestionSBNamespaceName
output ingestionQueueName string = ingestionSBName
output ingestionServiceAccessKeyName string = ingestionServiceAccessKeyName
output workflowKeyVaultName string = workflowKeyVaultName
output deliveryKeyVaultName string = deliveryKeyVaultName
output droneSchedulerKeyVaultName string = droneSchedulerKeyVaultName
output ingestionKeyVaultName string = ingestionKeyVaultName
output packageKeyVaultName string = packageKeyVaultName
output appInsightsName string = appInsightsName
output laWorkspace string = LogAnaliticWorkpace.id
output deliveryRedisName string = deliveryRedis.name
output workflowServiceAccessKeyName string = workflowServiceAccessKeyName