-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmain.bicep
More file actions
1346 lines (1268 loc) · 43.7 KB
/
main.bicep
File metadata and controls
1346 lines (1268 loc) · 43.7 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
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
targetScope = 'resourceGroup'
@minLength(3)
@maxLength(16)
@description('Required. A unique application/solution name for all resources in this deployment. This should be 3-16 characters long.')
param solutionName string
@maxLength(5)
@description('Optional. A unique text/token for the solution. This is used to ensure resource names are unique for global resources. Defaults to a 5-character substring of the unique string generated from the subscription ID, resource group name, and solution name.')
param solutionUniqueText string = substring(uniqueString(subscription().id, resourceGroup().name, solutionName), 0, 5)
@minLength(3)
@metadata({ azd: { type: 'location' } })
@description('Required. Azure region for container apps, storage, and other services. Choose a region close to your users.')
param location string
var solutionLocation = empty(location) ? resourceGroup().location : location
@allowed([
'australiaeast'
'eastus'
'eastus2'
'francecentral'
'japaneast'
'norwayeast'
'southindia'
'swedencentral'
'uksouth'
'westus'
'westus3'
])
@metadata({
azd: {
type: 'location'
usageName: [
'OpenAI.GlobalStandard.gpt-5.1, 500'
]
}
})
@description('Required. Azure region for AI services (OpenAI/AI Foundry). Must be a region that supports gpt-5.1 model deployment.')
param azureAiServiceLocation string
@allowed([
'australiaeast'
'eastus'
'eastus2'
'francecentral'
'japaneast'
'norwayeast'
'southindia'
'swedencentral'
'uksouth'
'westus'
'westus3'
])
@description('Required. Azure region for AI model deployment. Should match azureAiServiceLocation for optimal performance.')
#disable-next-line no-unused-params
param aiDeploymentLocation string = azureAiServiceLocation
@description('Optional. The host (excluding https://) of an existing container registry. This is the `loginServer` when using Azure Container Registry.')
param containerRegistryHost string = 'containermigrationacr.azurecr.io'
@description('Optional. The image tag to use for container images. Defaults to "latest".')
param imageTag string = 'latest'
@minLength(1)
@allowed(['Standard', 'GlobalStandard'])
@description('Optional. Model deployment type. Defaults to GlobalStandard.')
param aiDeploymentType string = 'GlobalStandard'
@minLength(1)
@description('Optional. Name of the AI model to deploy. Recommend using gpt-5.1. Defaults to gpt-5.1.')
param aiModelName string = 'gpt-5.1'
@minLength(1)
@description('Optional. Version of AI model. Review available version numbers per model before setting. Defaults to 2025-11-13.')
param aiModelVersion string = '2025-11-13'
@description('Optional. AI model deployment token capacity. Lower this if initial provisioning fails due to capacity. Defaults to 50K tokens per minute to improve regional success rate.')
param aiModelCapacity int = 500
@minLength(1)
@description('Optional. Name of the embedding model to deploy. Defaults to text-embedding-3-large.')
param aiEmbeddingModelName string = 'text-embedding-3-large'
@description('Optional. Version of the embedding model. Defaults to 1.')
param aiEmbeddingModelVersion string = '1'
@minLength(1)
@allowed(['Standard', 'GlobalStandard'])
@description('Optional. Embedding model deployment type. Defaults to GlobalStandard.')
param aiEmbeddingDeploymentType string = 'GlobalStandard'
@description('Optional. Embedding model deployment token capacity. Defaults to 500.')
param aiEmbeddingModelCapacity int = 500
@description('Optional. The tags to apply to all deployed Azure resources.')
param tags resourceInput<'Microsoft.Resources/resourceGroups@2025-04-01'>.tags = {}
@description('Optional. Enable redundancy for applicable resources. Defaults to false.')
param enableRedundancy bool = false
@description('Optional. Enable/Disable usage telemetry for module.')
param enableTelemetry bool = true
@description('Optional. Enable private networking for applicable resources, aligned with the Well Architected Framework recommendations. Defaults to false.')
param enablePrivateNetworking bool = false
@description('Optional. Enable monitoring applicable resources, aligned with the Well Architected Framework recommendations. This setting enables Application Insights and Log Analytics and configures all the resources applicable resources to send logs. Defaults to false.')
param enableMonitoring bool = false
@description('Optional. Enable scalability for applicable resources, aligned with the Well Architected Framework recommendations. Defaults to false.')
param enableScalability bool = false
@description('Optional. CosmosDB Location')
param cosmosLocation string = 'eastus2'
@description('Optional. Existing Log Analytics Workspace Resource ID')
param existingLogAnalyticsWorkspaceId string = ''
@description('Optional. Override for the CreatedBy tag. If not provided, will auto-detect from deployment context.')
param createdBy string = ''
// Get the current deployer's information for local debugging permissions
var deployerInfo = deployer()
var deployingUserPrincipalId = deployerInfo.objectId
var deployingUserType = contains(deployerInfo, 'userPrincipalName') ? 'User' : 'ServicePrincipal'
// Extract human-readable identity name for CreatedBy tag
var deployerIdentityName = !empty(createdBy)
? createdBy
: deployerInfo.?userPrincipalName != null
? split(deployerInfo.userPrincipalName, '@')[0]
: 'Identity-${deployerInfo.objectId}'
// Output for pre-deployment validation - shows what CreatedBy will be
output previewCreatedByTag string = deployerIdentityName
output previewDeployerInfo object = {
identityName: deployerIdentityName
objectId: deployingUserPrincipalId
type: deployingUserType
}
@description('Optional. Resource ID of an existing Foundry project')
param existingFoundryProjectResourceId string = ''
@description('Optional. Admin username for the Jumpbox Virtual Machine. Set to custom value if enablePrivateNetworking is true.')
@secure()
//param vmAdminUsername string = take(newGuid(), 20)
param vmAdminUsername string?
@description('Optional. Admin password for the Jumpbox Virtual Machine. Set to custom value if enablePrivateNetworking is true.')
@secure()
//param vmAdminPassword string = newGuid()
param vmAdminPassword string?
@description('Optional. Size of the Jumpbox Virtual Machine when created. Set to custom value if enablePrivateNetworking is true.')
param vmSize string?
// Extracts subscription, resource group, and workspace name from the resource ID when using an existing Log Analytics workspace
var useExistingLogAnalytics = !empty(existingLogAnalyticsWorkspaceId)
var existingLawSubscription = useExistingLogAnalytics ? split(existingLogAnalyticsWorkspaceId, '/')[2] : ''
var existingLawResourceGroup = useExistingLogAnalytics ? split(existingLogAnalyticsWorkspaceId, '/')[4] : ''
var existingLawName = useExistingLogAnalytics ? split(existingLogAnalyticsWorkspaceId, '/')[8] : ''
resource existingLogAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' existing = if (useExistingLogAnalytics) {
name: existingLawName
scope: resourceGroup(existingLawSubscription, existingLawResourceGroup)
}
var logAnalyticsWorkspaceResourceId = useExistingLogAnalytics
? existingLogAnalyticsWorkspaceId
: logAnalyticsWorkspace!.outputs.resourceId
var solutionSuffix = toLower(trim(replace(
replace(
replace(replace(replace(replace('${solutionName}${solutionUniqueText}', '-', ''), '_', ''), '.', ''), '/', ''),
' ',
''
),
'*',
''
)))
var allTags = union(
{
'azd-env-name': solutionName
TemplateName: 'Container Migration'
},
tags
)
resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = {
name: 'default'
properties: {
tags: {
...resourceGroup().tags
...tags
TemplateName: 'Container Migration'
Type: enablePrivateNetworking ? 'WAF' : 'Non-WAF'
CreatedBy: deployerIdentityName
}
}
}
// Replica regions list based on article in [Azure regions list](https://learn.microsoft.com/azure/reliability/regions-list) and [Enhance resilience by replicating your Log Analytics workspace across regions](https://learn.microsoft.com/azure/azure-monitor/logs/workspace-replication#supported-regions) for supported regions for Log Analytics Workspace.
var replicaRegionPairs = {
australiaeast: 'australiasoutheast'
centralus: 'westus'
eastasia: 'japaneast'
eastus: 'centralus'
eastus2: 'centralus'
japaneast: 'eastasia'
northeurope: 'westeurope'
southeastasia: 'eastasia'
uksouth: 'westeurope'
westeurope: 'northeurope'
westus3: 'eastus'
}
var replicaLocation = replicaRegionPairs[resourceGroup().location]
// ========== User Assigned Identity ========== //
// WAF best practices for identity and access management: https://learn.microsoft.com/en-us/azure/well-architected/security/identity-access
var userAssignedIdentityResourceName = 'id-${solutionSuffix}'
module appIdentity 'br/public:avm/res/managed-identity/user-assigned-identity:0.4.1' = {
name: take('avm.res.managed-identity.user-assigned-identity.${userAssignedIdentityResourceName}', 64)
params: {
name: userAssignedIdentityResourceName
location: solutionLocation
tags: allTags
enableTelemetry: enableTelemetry
}
}
// ========== Log Analytics Workspace ========== //
// WAF best practices for Log Analytics: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/azure-log-analytics
// WAF PSRules for Log Analytics: https://azure.github.io/PSRule.Rules.Azure/en/rules/resource/#azure-monitor-logs
var logAnalyticsWorkspaceResourceName = 'log-${solutionSuffix}'
module logAnalyticsWorkspace 'br/public:avm/res/operational-insights/workspace:0.12.0' = if ((enableMonitoring || enablePrivateNetworking) && !useExistingLogAnalytics) {
name: take('avm.res.operational-insights.workspace.${logAnalyticsWorkspaceResourceName}', 64)
params: {
name: logAnalyticsWorkspaceResourceName
location: solutionLocation
skuName: 'PerGB2018'
dataRetention: 30
diagnosticSettings: [{ useThisWorkspace: true }]
tags: allTags
enableTelemetry: enableTelemetry
features: { enableLogAccessUsingOnlyResourcePermissions: true }
// WAF aligned configuration for Redundancy
dailyQuotaGb: enableRedundancy ? 10 : null //WAF recommendation: 10 GB per day is a good starting point for most workloads
replication: enableRedundancy
? {
enabled: true
location: replicaLocation
}
: null
// WAF aligned configuration for Private Networking
publicNetworkAccessForIngestion: enablePrivateNetworking ? 'Disabled' : 'Enabled'
publicNetworkAccessForQuery: enablePrivateNetworking ? 'Disabled' : 'Enabled'
dataSources: enablePrivateNetworking
? [
{
tags: allTags
eventLogName: 'Application'
eventTypes: [
{
eventType: 'Error'
}
{
eventType: 'Warning'
}
{
eventType: 'Information'
}
]
kind: 'WindowsEvent'
name: 'applicationEvent'
}
{
counterName: '% Processor Time'
instanceName: '*'
intervalSeconds: 60
kind: 'WindowsPerformanceCounter'
name: 'windowsPerfCounter1'
objectName: 'Processor'
}
{
kind: 'IISLogs'
name: 'sampleIISLog1'
state: 'OnPremiseEnabled'
}
]
: null
}
}
// ========== Application Insights ========== //
// WAF best practices for Application Insights: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/application-insights
// WAF PSRules for Application Insights: https://azure.github.io/PSRule.Rules.Azure/en/rules/resource/#application-insights
var applicationInsightsResourceName = 'appi-${solutionSuffix}'
module applicationInsights 'br/public:avm/res/insights/component:0.6.0' = if (enableMonitoring) {
name: take('avm.res.insights.component.${applicationInsightsResourceName}', 64)
#disable-next-line no-unnecessary-dependson
//dependsOn: [logAnalyticsWorkspace]
params: {
name: applicationInsightsResourceName
location: solutionLocation
tags: allTags
enableTelemetry: enableTelemetry
retentionInDays: 365
kind: 'web'
disableIpMasking: false
flowType: 'Bluefield'
// WAF aligned configuration for Monitoring
workspaceResourceId: enableMonitoring ? logAnalyticsWorkspaceResourceId : ''
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
}
}
// ========== Virtual Network ========== //
module virtualNetwork './modules/virtualNetwork.bicep' = if (enablePrivateNetworking) {
name: take('module.virtual-network.${solutionSuffix}', 64)
params: {
name: 'vnet-${solutionSuffix}'
addressPrefixes: ['10.0.0.0/20']
location: location
tags: allTags
logAnalyticsWorkspaceId: enableMonitoring ? logAnalyticsWorkspaceResourceId : ''
resourceSuffix: solutionSuffix
enableTelemetry: enableTelemetry
}
}
// Azure Bastion Host
var bastionHostName = 'bas-${solutionSuffix}' // Bastion host name must be between 3 and 15 characters in length and use numbers and lower-case letters only.
module bastionHost 'br/public:avm/res/network/bastion-host:0.6.1' = if (enablePrivateNetworking) {
name: take('avm.res.network.bastion-host.${bastionHostName}', 64)
params: {
name: bastionHostName
skuName: 'Standard'
location: location
virtualNetworkResourceId: virtualNetwork!.outputs.resourceId
diagnosticSettings: enableMonitoring
? [
{
name: 'bastionDiagnostics'
workspaceResourceId: logAnalyticsWorkspaceResourceId
logCategoriesAndGroups: [
{
categoryGroup: 'allLogs'
enabled: true
}
]
}
]
: null
tags: allTags
enableTelemetry: enableTelemetry
publicIPAddressObject: {
name: 'pip-${bastionHostName}'
zones: []
}
}
}
// Jumpbox Virtual Machine
var jumpboxVmName = take('vm-jumpbox-${solutionSuffix}', 15)
module jumpboxVM 'br/public:avm/res/compute/virtual-machine:0.15.0' = if (enablePrivateNetworking) {
name: take('avm.res.compute.virtual-machine.${jumpboxVmName}', 64)
params: {
name: take(jumpboxVmName, 15) // Shorten VM name to 15 characters to avoid Azure limits
vmSize: vmSize ?? 'Standard_DS2_v2'
location: location
adminUsername: vmAdminUsername ?? 'JumpboxAdminUser'
adminPassword: vmAdminPassword ?? 'JumpboxAdminP@ssw0rd1234!'
tags: allTags
zone: 0
imageReference: {
offer: 'WindowsServer'
publisher: 'MicrosoftWindowsServer'
sku: '2019-datacenter'
version: 'latest'
}
osType: 'Windows'
osDisk: {
name: 'osdisk-${jumpboxVmName}'
managedDisk: {
storageAccountType: 'Standard_LRS'
}
}
encryptionAtHost: false // Some Azure subscriptions do not support encryption at host
nicConfigurations: [
{
name: 'nic-${jumpboxVmName}'
ipConfigurations: [
{
name: 'ipconfig1'
subnetResourceId: virtualNetwork!.outputs.jumpboxSubnetResourceId
}
]
diagnosticSettings: enableMonitoring
? [
{
name: 'jumpboxDiagnostics'
workspaceResourceId: logAnalyticsWorkspaceResourceId
logCategoriesAndGroups: [
{
categoryGroup: 'allLogs'
enabled: true
}
]
metricCategories: [
{
category: 'AllMetrics'
enabled: true
}
]
}
]
: null
}
]
enableTelemetry: enableTelemetry
}
}
var processBlobContainerName = 'processes'
var processQueueName = 'processes-queue'
// ========== Private DNS Zones ========== //
var privateDnsZones = [
'privatelink.cognitiveservices.azure.com'
'privatelink.openai.azure.com'
'privatelink.services.ai.azure.com'
'privatelink.documents.azure.com'
'privatelink.blob.${environment().suffixes.storage}'
'privatelink.queue.${environment().suffixes.storage}'
'privatelink.azconfig.io'
]
// DNS Zone Index Constants
var dnsZoneIndex = {
cognitiveServices: 0
openAI: 1
aiServices: 2
cosmosDB: 3
storageBlob: 4
storageQueue: 5
appConfig: 6
}
// List of DNS zone indices that correspond to AI-related services.
var aiRelatedDnsZoneIndices = [
dnsZoneIndex.cognitiveServices
dnsZoneIndex.openAI
dnsZoneIndex.aiServices
]
// ===================================================
// DEPLOY PRIVATE DNS ZONES
// - Deploys all zones if no existing Foundry project is used
// - Excludes AI-related zones when using with an existing Foundry project
// ===================================================
@batchSize(5)
module avmPrivateDnsZones 'br/public:avm/res/network/private-dns-zone:0.7.1' = [
for (zone, i) in privateDnsZones: if (enablePrivateNetworking && (empty(existingFoundryProjectResourceId) || !contains(
aiRelatedDnsZoneIndices,
i
))) {
name: 'dns-zone-${i}'
params: {
name: zone
tags: allTags
enableTelemetry: enableTelemetry
virtualNetworkLinks: [
{
name: take('vnetlink-${virtualNetwork!.outputs.name}-${split(zone, '.')[1]}', 80)
virtualNetworkResourceId: virtualNetwork!.outputs.resourceId
}
]
}
}
]
// ========== AVM WAF ========== //
// ========== Storage account module ========== //
var storageAccountName = 'st${solutionSuffix}' // Storage account name must be between 3 and 24 characters in length and use numbers and lower-case letters only.
module storageAccount 'br/public:avm/res/storage/storage-account:0.20.0' = {
name: take('avm.res.storage.storage-account.${storageAccountName}', 64)
params: {
name: storageAccountName
location: solutionLocation
managedIdentities: { systemAssigned: true }
minimumTlsVersion: 'TLS1_2'
enableTelemetry: enableTelemetry
tags: allTags
accessTier: 'Hot'
supportsHttpsTrafficOnly: true
roleAssignments: [
{
roleDefinitionIdOrName: 'Storage Blob Data Contributor'
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: 'Storage Queue Data Contributor'
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
// Add deployer permissions
{
roleDefinitionIdOrName: 'Storage Blob Data Contributor'
principalId: deployingUserPrincipalId
principalType: deployingUserType
}
{
roleDefinitionIdOrName: 'Storage Queue Data Contributor'
principalId: deployingUserPrincipalId
principalType: deployingUserType
}
]
// WAF aligned networking
networkAcls: {
bypass: 'AzureServices'
defaultAction: enablePrivateNetworking ? 'Deny' : 'Allow'
}
allowBlobPublicAccess: enablePrivateNetworking ? true : false
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
// Private endpoints for blob and queue
privateEndpoints: enablePrivateNetworking
? [
{
name: 'pep-storage-${storageAccountName}'
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{
name: 'storage-dns-zone-group-blob'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageBlob]!.outputs.resourceId
}
]
}
subnetResourceId: virtualNetwork!.outputs.backendSubnetResourceId
service: 'blob'
}
{
name: 'pep-queue-${solutionSuffix}'
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{
name: 'storage-dns-zone-group-queue'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageQueue]!.outputs.resourceId
}
]
}
subnetResourceId: virtualNetwork!.outputs.backendSubnetResourceId
service: 'queue'
}
]
: []
blobServices: {
corsRules: []
deleteRetentionPolicyEnabled: false
containers: [
{
name: 'data'
publicAccess: 'None'
denyEncryptionScopeOverride: false
defaultEncryptionScope: '$account-encryption-key'
}
]
}
queueServices: {
deleteRetentionPolicyEnabled: true
deleteRetentionPolicyDays: 7
queues: [
for queue in ([processQueueName, '${processQueueName}-dead-letter'] ?? []): {
name: queue
}
]
}
}
}
//========== AVM WAF ========== //
//========== Cosmos DB module ========== //
var cosmosDbResourceName = 'cosmos-${solutionSuffix}'
var cosmosDbZoneRedundantHaRegionPairs = {
australiaeast: 'uksouth' //'southeastasia'
centralus: 'eastus2'
eastasia: 'southeastasia'
eastus: 'centralus'
eastus2: 'centralus'
japaneast: 'australiaeast'
northeurope: 'westeurope'
southeastasia: 'eastasia'
uksouth: 'westeurope'
westeurope: 'northeurope'
westus3: 'eastus'
}
var cosmosDbHaLocation = cosmosDbZoneRedundantHaRegionPairs[resourceGroup().location]
var cosmosDatabaseName = 'migration_db'
var processCosmosContainerName = 'processes'
var agentTelemetryCosmosContainerName = 'agent_telemetry'
var processControlCosmosContainerName = 'processcontrol'
module cosmosDb 'br/public:avm/res/document-db/database-account:0.15.0' = {
name: take('avm.res.document-db.database-account.${cosmosDbResourceName}', 64)
params: {
name: cosmosDbResourceName
location: cosmosLocation
tags: allTags
enableTelemetry: enableTelemetry
sqlDatabases: [
{
name: cosmosDatabaseName
containers: [
{
name: processCosmosContainerName
paths: [
'/_partitionKey'
]
}
{
name: agentTelemetryCosmosContainerName
paths: [
'/_partitionKey'
]
}
{
name: processControlCosmosContainerName
paths: [
'/_partitionKey'
]
}
{
name: 'files'
paths: [
'/_partitionKey'
]
}
{
name: 'process_statuses'
paths: [
'/_partitionKey'
]
}
]
}
]
diagnosticSettings: enableMonitoring
? [
{
workspaceResourceId: logAnalyticsWorkspaceResourceId
}
]
: null
networkRestrictions: {
networkAclBypass: 'None'
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
}
privateEndpoints: enablePrivateNetworking
? [
{
name: 'pep-${cosmosDbResourceName}'
customNetworkInterfaceName: 'nic-${cosmosDbResourceName}'
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{ privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cosmosDB]!.outputs.resourceId }
]
}
service: 'Sql'
subnetResourceId: virtualNetwork!.outputs.backendSubnetResourceId
}
]
: []
zoneRedundant: enableRedundancy ? true : false
capabilitiesToAdd: enableRedundancy
? null
: [
'EnableServerless'
]
automaticFailover: enableRedundancy ? true : false
failoverLocations: enableRedundancy
? [
{
failoverPriority: 0
isZoneRedundant: true
locationName: solutionLocation
}
{
failoverPriority: 1
isZoneRedundant: true
locationName: cosmosDbHaLocation
}
]
: [
{
locationName: solutionLocation
failoverPriority: 0
isZoneRedundant: enableRedundancy
}
]
// Use built-in Cosmos DB roles for RBAC access
roleAssignments: [
{
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: 'DocumentDB Account Contributor'
}
// Add deployer for local debugging
{
principalId: deployingUserPrincipalId
principalType: deployingUserType
roleDefinitionIdOrName: 'DocumentDB Account Contributor'
}
]
// Create custom data plane role definition and assignment
dataPlaneRoleDefinitions: [
{
roleName: 'CosmosDB Data Contributor Custom'
dataActions: [
'Microsoft.DocumentDB/databaseAccounts/readMetadata'
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/executeQuery'
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/readChangeFeed'
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*'
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*'
]
assignments: [
{ principalId: appIdentity.outputs.principalId }
// ADD THIS for local debugging support:
{ principalId: deployingUserPrincipalId }
]
}
]
}
dependsOn: [storageAccount]
}
var aiModelDeploymentName = aiModelName
var useExistingAiFoundryAiProject = !empty(existingFoundryProjectResourceId)
var aiFoundryAiServicesResourceGroupName = useExistingAiFoundryAiProject
? split(existingFoundryProjectResourceId, '/')[4]
: 'rg-${solutionSuffix}'
var aiFoundryAiServicesSubscriptionId = useExistingAiFoundryAiProject
? split(existingFoundryProjectResourceId, '/')[2]
: subscription().id
var aiFoundryAiServicesResourceName = useExistingAiFoundryAiProject
? split(existingFoundryProjectResourceId, '/')[8]
: 'aif-${solutionSuffix}'
resource existingAiFoundryAiServices 'Microsoft.CognitiveServices/accounts@2025-06-01' existing = if (useExistingAiFoundryAiProject) {
name: aiFoundryAiServicesResourceName
scope: resourceGroup(aiFoundryAiServicesSubscriptionId, aiFoundryAiServicesResourceGroupName)
}
module existingAiFoundryAiServicesDeployments 'modules/ai-services-deployments.bicep' = if (useExistingAiFoundryAiProject) {
name: take('module.ai-services-model-deployments.${existingAiFoundryAiServices.name}', 64)
scope: resourceGroup(aiFoundryAiServicesSubscriptionId, aiFoundryAiServicesResourceGroupName)
params: {
name: aiFoundryAiServicesResourceName // Fix: use variable instead of resource reference
deployments: [
{
name: aiModelDeploymentName
model: {
format: 'OpenAI'
name: aiModelName
version: aiModelVersion
}
sku: {
name: aiDeploymentType
capacity: aiModelCapacity
}
}
{
name: aiEmbeddingModelName
model: {
format: 'OpenAI'
name: aiEmbeddingModelName
version: aiEmbeddingModelVersion
}
sku: {
name: aiEmbeddingDeploymentType
capacity: aiEmbeddingModelCapacity
}
}
]
roleAssignments: [
// Service Principal permissions
{
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: 'Cognitive Services OpenAI Contributor'
}
{
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: '64702f94-c441-49e6-a78b-ef80e0188fee'
}
{
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d'
}
// Deployer permissions
{
principalId: deployingUserPrincipalId
principalType: deployingUserType
roleDefinitionIdOrName: 'Cognitive Services OpenAI Contributor'
}
{
principalId: deployingUserPrincipalId
principalType: deployingUserType
roleDefinitionIdOrName: 'Cognitive Services User'
}
]
}
}
// Temporarily disabled AI Foundry due to AML workspace creation issues
module aiFoundry 'br/public:avm/ptn/ai-ml/ai-foundry:0.4.0' = if(!useExistingAiFoundryAiProject) {
name: take('avm.ptn.ai-ml.ai-foundry.${solutionSuffix}', 64)
params: {
#disable-next-line BCP334
baseName: take(aiFoundryAiServicesResourceName, 12)
baseUniqueName: null
location: empty(azureAiServiceLocation) ? location : azureAiServiceLocation
aiFoundryConfiguration: {
accountName:aiFoundryAiServicesResourceName
allowProjectManagement: true
roleAssignments: [
// Service Principal permissions
{
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: 'Cognitive Services OpenAI Contributor'
}
{
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: '64702f94-c441-49e6-a78b-ef80e0188fee' // Azure AI Developer
}
{
principalId: appIdentity.outputs.principalId
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Azure AI User
}
// Deployer permissions for local debugging
{
principalId: deployingUserPrincipalId
principalType: deployingUserType
roleDefinitionIdOrName: 'Cognitive Services OpenAI Contributor'
}
{
principalId: deployingUserPrincipalId
principalType: deployingUserType
roleDefinitionIdOrName: 'Cognitive Services User'
}
]
// Remove networking configuration to avoid AML workspace creation issues
networking: enablePrivateNetworking? {
aiServicesPrivateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.aiServices]!.outputs.resourceId
openAiPrivateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.openAI]!.outputs.resourceId
cognitiveServicesPrivateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cognitiveServices]!.outputs.resourceId
} : null
}
// Disable private endpoints temporarily to fix AML workspace issue
privateEndpointSubnetResourceId: enablePrivateNetworking ? virtualNetwork!.outputs.backendSubnetResourceId : null
// Only attempt model deployment when explicitly enabled to avoid AccountIsNotSucceeded failures due to quota or model availability.
aiModelDeployments: [
{
name: aiModelDeploymentName
model: {
format: 'OpenAI'
name: aiModelName
version: aiModelVersion
}
sku: {
name: aiDeploymentType
capacity: aiModelCapacity
}
}
{
name: aiEmbeddingModelName
model: {
format: 'OpenAI'
name: aiEmbeddingModelName
version: aiEmbeddingModelVersion
}
sku: {
name: aiEmbeddingDeploymentType
capacity: aiEmbeddingModelCapacity
}
}
]
tags: allTags
enableTelemetry: enableTelemetry
}
}
var aiServicesName = useExistingAiFoundryAiProject ? existingAiFoundryAiServices.name : aiFoundryAiServicesResourceName
module appConfiguration 'br/public:avm/res/app-configuration/configuration-store:0.9.1' = {
name: take('avm.res.app-config.store.${solutionSuffix}', 64)
params: {
location: solutionLocation
name: 'appcs-${solutionSuffix}'
disableLocalAuth: false // needed to allow setting app config key values from this module
tags: allTags
// Always set key values during deployment since Container Apps will be in private network
keyValues: [
{
name: 'APP_LOGGING_ENABLE'
value: 'true'
}
{
name: 'APP_LOGGING_LEVEL'
value: 'INFO'
}
{
name: 'AZURE_PACKAGE_LOGGING_LEVEL'
value: 'INFO'
}
{
name: 'AZURE_LOGGING_PACKAGES'
value: ''
}
{
name: 'AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME'
value: ''
}
{
name: 'AZURE_AI_AGENT_PROJECT_CONNECTION_STRING'
value: ''
}
{
name: 'AZURE_OPENAI_API_VERSION'
value: '2025-03-01-preview'
}
{
name: 'AZURE_OPENAI_CHAT_DEPLOYMENT_NAME'
value: aiModelDeploymentName
}
{
name: 'AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME'
value: aiEmbeddingModelName
}
{
name: 'AZURE_OPENAI_ENDPOINT'
value: 'https://${aiServicesName}.cognitiveservices.azure.com/'
}
{
name: 'AZURE_OPENAI_ENDPOINT_BASE'
value: 'https://${aiServicesName}.cognitiveservices.azure.com/'
}
{
name: 'AZURE_TRACING_ENABLED'
value: 'True'
}
{
name: 'STORAGE_ACCOUNT_BLOB_URL'
value: 'https://${storageAccountName}.blob.${environment().suffixes.storage}'
}
{
name: 'STORAGE_ACCOUNT_NAME'
value: storageAccount.outputs.name
}
{
name: 'STORAGE_ACCOUNT_PROCESS_CONTAINER'
value: processBlobContainerName
}
{
name: 'STORAGE_ACCOUNT_PROCESS_QUEUE'
value: processQueueName
}
{
name: 'STORAGE_ACCOUNT_QUEUE_URL'
value: 'https://${storageAccountName}.queue.${environment().suffixes.storage}'
}
{
name: 'COSMOS_DB_CONTAINER_NAME'
value: agentTelemetryCosmosContainerName
}
{
name: 'COSMOS_DB_CONTROL_CONTAINER_NAME'
value: processControlCosmosContainerName
}
{
name: 'COSMOS_DB_DATABASE_NAME'
value: cosmosDatabaseName
}
{
name: 'COSMOS_DB_ACCOUNT_URL'
value: cosmosDb.outputs.endpoint
}
{