-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathmain_custom.bicep
More file actions
1561 lines (1435 loc) · 57.6 KB
/
main_custom.bicep
File metadata and controls
1561 lines (1435 loc) · 57.6 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
// ========== main.bicep ========== //
targetScope = 'resourceGroup'
@minLength(3)
@maxLength(16)
@description('Optional. A unique prefix for all resources in this deployment. This should be 3-20 characters long.')
param solutionName string = 'kmgen'
@metadata({ azd: { type: 'location' } })
@description('Required. Azure region for all services. Regions are restricted to guarantee compatibility with paired regions and replica locations for data redundancy and failover scenarios based on articles [Azure regions list](https://learn.microsoft.com/azure/reliability/regions-list) and [Azure Database for MySQL Flexible Server - Azure Regions](https://learn.microsoft.com/azure/mysql/flexible-server/overview#azure-regions).')
@allowed([
'australiaeast'
'centralus'
'eastasia'
'eastus2'
'japaneast'
'northeurope'
'southeastasia'
'uksouth'
])
param location string
@allowed([
'australiaeast'
'eastus'
'eastus2'
'francecentral'
'japaneast'
'swedencentral'
'uksouth'
'westus'
'westus3'
])
@metadata({
azd: {
type: 'location'
usageName: [
'OpenAI.GlobalStandard.gpt-4o-mini,150'
'OpenAI.GlobalStandard.text-embedding-3-small,80'
]
}
})
@description('Required. Location for AI Foundry deployment. This is the location where the AI Foundry resources will be deployed.')
param aiServiceLocation string
@minLength(1)
@description('Required. Industry use case for deployment.')
@allowed([
'telecom'
'IT_helpdesk'
])
param usecase string
@minLength(1)
@description('Optional. Location for the Content Understanding service deployment.')
@allowed(['swedencentral', 'australiaeast'])
@metadata({
azd: {
type: 'location'
}
})
param contentUnderstandingLocation string = 'swedencentral'
@minLength(1)
@description('Optional. Secondary location for databases creation (example: eastus2).')
param secondaryLocation string = 'eastus2'
@minLength(1)
@description('Optional. GPT model deployment type.')
@allowed([
'Standard'
'GlobalStandard'
])
param deploymentType string = 'GlobalStandard'
@description('Optional. Name of the GPT model to deploy.')
param gptModelName string = 'gpt-4o-mini'
@description('Optional. Version of the GPT model to deploy.')
param gptModelVersion string = '2024-07-18'
@description('Optional. Version of AI Agent API.')
param azureAiAgentApiVersion string = '2025-05-01'
@description('Optional. Version of Content Understanding API.')
param azureContentUnderstandingApiVersion string = '2024-12-01-preview'
// You can increase this, but capacity is limited per model/region, so you will get errors if you go over
// https://learn.microsoft.com/en-us/azure/ai-services/openai/quotas-limits
@minValue(10)
@description('Optional. Capacity of the GPT deployment.')
param gptDeploymentCapacity int = 150
@minLength(1)
@description('Optional. Name of the Text Embedding model to deploy.')
@allowed([
'text-embedding-3-small'
])
param embeddingModel string = 'text-embedding-3-small'
@minValue(10)
@description('Optional. Capacity of the Embedding Model deployment.')
param embeddingDeploymentCapacity int = 80
@description('Optional. The Container Registry hostname where the docker images for the backend are located.')
param backendContainerRegistryHostname string = 'kmcontainerreg.azurecr.io'
@description('Optional. The Container Image Name to deploy on the backend.')
param backendContainerImageName string = 'km-api'
@description('Optional. The Container Image Tag to deploy on the backend.')
param backendContainerImageTag string = 'latest_waf_2025-12-02_1084'
@description('Optional. The Container Registry hostname where the docker images for the frontend are located.')
param frontendContainerRegistryHostname string = 'kmcontainerreg.azurecr.io'
@description('Optional. The Container Image Name to deploy on the frontend.')
param frontendContainerImageName string = 'km-app'
@description('Optional. The Container Image Tag to deploy on the frontend.')
param frontendContainerImageTag string = 'latest_waf_2025-12-02_1084'
@description('Optional. The tags to apply to all deployed Azure resources.')
param tags resourceInput<'Microsoft.Resources/resourceGroups@2025-04-01'>.tags = {}
@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/Disable usage telemetry for module.')
param enableTelemetry bool = true
@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 redundancy for applicable resources, aligned with the Well Architected Framework recommendations. Defaults to false.')
param enableRedundancy 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. Admin username for the Jumpbox Virtual Machine. Set to custom value if enablePrivateNetworking is true.')
@secure()
param vmAdminUsername string?
@description('Optional. Admin password for the Jumpbox Virtual Machine. Set to custom value if enablePrivateNetworking is true.')
@secure()
param vmAdminPassword string?
@description('Optional. Size of the Jumpbox Virtual Machine when created. Set to custom value if enablePrivateNetworking is true.')
param vmSize string = 'Standard_D2s_v5'
@description('Optional: Existing Log Analytics Workspace Resource ID')
param existingLogAnalyticsWorkspaceId string = ''
@description('Optional. Use this parameter to use an existing AI project resource ID')
param existingAiFoundryAiProjectResourceId string = ''
@description('Optional. Created by user name.')
param createdBy string = contains(deployer(), 'userPrincipalName')? split(deployer().userPrincipalName, '@')[0]: deployer().objectId
@maxLength(5)
@description('Optional. A unique text value 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)
var solutionSuffix = toLower(trim(replace(
replace(
replace(replace(replace(replace('${solutionName}${solutionUniqueText}', '-', ''), '_', ''), '.', ''), '/', ''),
' ',
''
),
'*',
''
)))
var acrName = 'kmcontainerreg'
// 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'
}
var replicaLocation = replicaRegionPairs[resourceGroup().location]
// Region pairs list based on article in [Azure Database for MySQL Flexible Server - Azure Regions](https://learn.microsoft.com/azure/mysql/flexible-server/overview#azure-regions) for supported high availability regions for CosmosDB.
var cosmosDbZoneRedundantHaRegionPairs = {
australiaeast: 'uksouth' //'southeastasia'
centralus: 'eastus2'
eastasia: 'southeastasia'
eastus: 'centralus'
eastus2: 'centralus'
japaneast: 'australiaeast'
northeurope: 'westeurope'
southeastasia: 'eastasia'
uksouth: 'westeurope'
westeurope: 'northeurope'
}
// Paired location calculated based on 'location' parameter. This location will be used by applicable resources if `enableScalability` is set to `true`
var cosmosDbHaLocation = cosmosDbZoneRedundantHaRegionPairs[resourceGroup().location]
// Extracts subscription, resource group, and workspace name from the resource ID when using an existing Log Analytics workspace
var useExistingLogAnalytics = !empty(existingLogAnalyticsWorkspaceId)
var logAnalyticsWorkspaceResourceId = useExistingLogAnalytics
? existingLogAnalyticsWorkspaceId
: logAnalyticsWorkspace!.outputs.resourceId
var existingTags = resourceGroup().tags ?? {}
// ========== Resource Group Tag ========== //
resource resourceGroupTags 'Microsoft.Resources/tags@2025-04-01' = {
name: 'default'
properties: {
tags: union(
existingTags,
tags,
{
TemplateName: 'KM-Generic'
Type: enablePrivateNetworking ? 'WAF' : 'Non-WAF'
CreatedBy: createdBy
DeploymentName: deployment().name
UseCase: usecase
}
)
}
}
#disable-next-line no-deployments-resources
resource avmTelemetry 'Microsoft.Resources/deployments@2024-03-01' = if (enableTelemetry) {
name: '46d3xbcp.ptn.sa-convknowledgemining.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, location), 0, 4)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
outputs: {
telemetry: {
type: 'String'
value: 'For more information, see https://aka.ms/avm/TelemetryInfo'
}
}
}
}
}
// ========== 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.14.2' = if (enableMonitoring && !useExistingLogAnalytics) {
name: take('avm.res.operational-insights.workspace.${logAnalyticsWorkspaceResourceName}', 64)
params: {
name: logAnalyticsWorkspaceResourceName
tags: tags
location: location
enableTelemetry: enableTelemetry
skuName: 'PerGB2018'
dataRetention: 365
features: { enableLogAccessUsingOnlyResourcePermissions: true }
diagnosticSettings: [{ useThisWorkspace: 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: tags
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.7.1' = if (enableMonitoring) {
name: take('avm.res.insights.component.${applicationInsightsResourceName}', 64)
params: {
name: applicationInsightsResourceName
tags: tags
location: location
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 and Networking Components ========== //
// Virtual Network with NSGs and Subnets
module virtualNetwork 'modules/virtualNetwork.bicep' = if (enablePrivateNetworking) {
name: take('module.virtualNetwork.${solutionSuffix}', 64)
params: {
name: 'vnet-${solutionSuffix}'
addressPrefixes: ['10.0.0.0/20'] // 4096 addresses (enough for 8 /23 subnets or 16 /24)
location: location
tags: tags
logAnalyticsWorkspaceId: logAnalyticsWorkspaceResourceId
resourceSuffix: solutionSuffix
enableTelemetry: enableTelemetry
}
}
// Azure Bastion Host
var bastionHostName = 'bas-${solutionSuffix}'
module bastionHost 'br/public:avm/res/network/bastion-host:0.8.2' = if (enablePrivateNetworking) {
name: take('avm.res.network.bastion-host.${bastionHostName}', 64)
params: {
name: bastionHostName
skuName: 'Standard'
location: location
virtualNetworkResourceId: virtualNetwork!.outputs.resourceId
diagnosticSettings: [
{
name: 'bastionDiagnostics'
workspaceResourceId: logAnalyticsWorkspaceResourceId
logCategoriesAndGroups: [
{
categoryGroup: 'allLogs'
enabled: true
}
]
}
]
tags: tags
enableTelemetry: enableTelemetry
publicIPAddressObject: {
name: 'pip-${bastionHostName}'
}
}
}
// Jumpbox Virtual Machine
var jumpboxVmName = take('vm-jumpbox-${solutionSuffix}', 15)
module jumpboxVM 'br/public:avm/res/compute/virtual-machine:0.21.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_D2s_v5'
location: location
adminUsername: vmAdminUsername ?? 'JumpboxAdminUser'
adminPassword: vmAdminPassword ?? 'JumpboxAdminP@ssw0rd1234!'
tags: tags
availabilityZone: -1
imageReference: {
publisher: 'microsoft-dsvm'
offer: 'dsvm-win-2022'
sku: 'winserver-2022'
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: [
{
name: 'jumpboxDiagnostics'
workspaceResourceId: logAnalyticsWorkspaceResourceId
logCategoriesAndGroups: [
{
categoryGroup: 'allLogs'
enabled: true
}
]
metricCategories: [
{
category: 'AllMetrics'
enabled: true
}
]
}
]
}
]
enableTelemetry: enableTelemetry
}
}
// ========== Private DNS Zones ========== //
var privateDnsZones = [
'privatelink.cognitiveservices.azure.com'
'privatelink.openai.azure.com'
'privatelink.services.ai.azure.com'
'privatelink.blob.${environment().suffixes.storage}'
'privatelink.queue.${environment().suffixes.storage}'
'privatelink.file.${environment().suffixes.storage}'
'privatelink.dfs.${environment().suffixes.storage}'
'privatelink.documents.azure.com'
'privatelink${environment().suffixes.sqlServerHostname}'
'privatelink.search.windows.net'
]
// DNS Zone Index Constants
var dnsZoneIndex = {
cognitiveServices: 0
openAI: 1
aiServices: 2
storageBlob: 3
storageQueue: 4
storageFile: 5
storageDfs: 6
cosmosDB: 7
sqlServer: 8
search: 9
}
// ===================================================
// 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.8.0' = [
for (zone, i) in privateDnsZones: if (enablePrivateNetworking) {
name: 'avm.res.network.private-dns-zone.${split(zone, '.')[1]}'
params: {
name: zone
tags: tags
enableTelemetry: enableTelemetry
virtualNetworkLinks: [
{
name: take('vnetlink-${virtualNetwork!.outputs.name}-${split(zone, '.')[1]}', 80)
virtualNetworkResourceId: virtualNetwork!.outputs.resourceId
}
]
}
}
]
// WAF best practices for identity and access management: https://learn.microsoft.com/en-us/azure/well-architected/security/identity-access
// ========== User Assigned Identity ========== //
var userAssignedIdentityResourceName = 'id-${solutionSuffix}'
module userAssignedIdentity 'br/public:avm/res/managed-identity/user-assigned-identity:0.4.3' = {
name: take('avm.res.managed-identity.user-assigned-identity.${userAssignedIdentityResourceName}', 64)
params: {
name: userAssignedIdentityResourceName
location: location
tags: tags
enableTelemetry: enableTelemetry
}
}
// ========== SQL Operations User Assigned Identity ========== //
// Dedicated identity for backend SQL operations with limited permissions (db_datareader, db_datawriter)
var backendUserAssignedIdentityResourceName = 'id-backend-${solutionSuffix}'
module backendUserAssignedIdentity 'br/public:avm/res/managed-identity/user-assigned-identity:0.4.3' = {
name: take('avm.res.managed-identity.user-assigned-identity.${backendUserAssignedIdentityResourceName}', 64)
params: {
name: backendUserAssignedIdentityResourceName
location: location
tags: tags
enableTelemetry: enableTelemetry
}
}
// ========== AVM WAF ========== //
// ==========AI Foundry and related resources ========== //
// ========== AI Foundry: AI Services ========== //
// WAF best practices for Open AI: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/azure-openai
var existingOpenAIEndpoint = !empty(existingAiFoundryAiProjectResourceId) ? format('https://{0}.openai.azure.com/', split(existingAiFoundryAiProjectResourceId, '/')[8]) : ''
var existingProjEndpoint = !empty(existingAiFoundryAiProjectResourceId) ? format('https://{0}.services.ai.azure.com/api/projects/{1}', split(existingAiFoundryAiProjectResourceId, '/')[8], split(existingAiFoundryAiProjectResourceId, '/')[10]) : ''
var existingAIServicesName = !empty(existingAiFoundryAiProjectResourceId) ? split(existingAiFoundryAiProjectResourceId, '/')[8] : ''
var existingAIProjectName = !empty(existingAiFoundryAiProjectResourceId) ? split(existingAiFoundryAiProjectResourceId, '/')[10] : ''
var aiFoundryAiServicesSubscriptionId = useExistingAiFoundryAiProject
? split(existingAiFoundryAiProjectResourceId, '/')[2]
: subscription().id
var useExistingAiFoundryAiProject = !empty(existingAiFoundryAiProjectResourceId)
var aiFoundryAiServicesResourceGroupName = useExistingAiFoundryAiProject
? split(existingAiFoundryAiProjectResourceId, '/')[4]
: 'rg-${solutionSuffix}'
var aiFoundryAiServicesResourceName = useExistingAiFoundryAiProject
? split(existingAiFoundryAiProjectResourceId, '/')[8]
: 'aif-${solutionSuffix}'
var aiFoundryAiProjectResourceName = useExistingAiFoundryAiProject
? split(existingAiFoundryAiProjectResourceId, '/')[10]
: 'proj-${solutionSuffix}'
// NOTE: Required version 'Microsoft.CognitiveServices/accounts@2024-04-01-preview' not available in AVM
// var aiFoundryAiServicesResourceName = 'aif-${solutionSuffix}'
var aiFoundryAiServicesAiProjectResourceName = 'proj-${solutionSuffix}'
var aiFoundryAIservicesEnabled = true
var aiModelDeployments = [
{
name: gptModelName
format: 'OpenAI'
model: gptModelName
sku: {
name: deploymentType
capacity: gptDeploymentCapacity
}
version: gptModelVersion
raiPolicyName: 'Microsoft.Default'
}
{
name: embeddingModel
format: 'OpenAI'
model: embeddingModel
sku: {
name: 'GlobalStandard'
capacity: embeddingDeploymentCapacity
}
version: '1'
raiPolicyName: 'Microsoft.Default'
}
]
resource existingAiFoundryAiServices 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = if (useExistingAiFoundryAiProject) {
name: aiFoundryAiServicesResourceName
scope: resourceGroup(aiFoundryAiServicesSubscriptionId, aiFoundryAiServicesResourceGroupName)
}
resource existingAiFoundryAiServicesProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' existing = if (useExistingAiFoundryAiProject) {
name: aiFoundryAiProjectResourceName
parent: existingAiFoundryAiServices
}
module aiFoundryAiServices 'modules/ai-services.bicep' = if (aiFoundryAIservicesEnabled) {
name: take('avm.res.cognitive-services.account.${aiFoundryAiServicesResourceName}', 64)
params: {
name: aiFoundryAiServicesResourceName
location: aiServiceLocation
tags: tags
existingFoundryProjectResourceId: existingAiFoundryAiProjectResourceId
projectName: !empty(existingAIProjectName) ? existingAIProjectName : aiFoundryAiServicesAiProjectResourceName
projectDescription: 'AI Foundry Project'
sku: 'S0'
kind: 'AIServices'
disableLocalAuth: true
customSubDomainName: aiFoundryAiServicesResourceName
apiProperties: {
//staticsEnabled: false
}
networkAcls: {
defaultAction: 'Allow'
virtualNetworkRules: []
ipRules: []
bypass: 'AzureServices'
}
managedIdentities: { userAssignedResourceIds: [userAssignedIdentity!.outputs.resourceId] } //To create accounts or projects, you must enable a managed identity on your resource
roleAssignments: [
{
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Azure AI User
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Azure AI User
principalId: backendUserAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '64702f94-c441-49e6-a78b-ef80e0188fee' // Azure AI Developer
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd' // Cognitive Services OpenAI User
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '64702f94-c441-49e6-a78b-ef80e0188fee' // Azure AI Developer
principalId: backendUserAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd' // Cognitive Services OpenAI User
principalId: backendUserAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
]
// WAF aligned configuration for Monitoring
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
privateEndpoints: []
deployments: [
for aiModelDeployment in aiModelDeployments: {
name: aiModelDeployment.name
model: {
format: aiModelDeployment.format
name: aiModelDeployment.model
version: aiModelDeployment.version
}
raiPolicyName: aiModelDeployment.raiPolicyName
sku: {
name: aiModelDeployment.sku.name
capacity: aiModelDeployment.sku.capacity
}
}
]
}
}
// ========== AI Foundry: Separate Private Endpoint ========== //
module aiFoundryPrivateEndpoint 'br/public:avm/res/network/private-endpoint:0.8.1' = if (enablePrivateNetworking && !useExistingAiFoundryAiProject) {
name: take('pep-${aiFoundryAiServicesResourceName}-deployment', 64)
params: {
name: 'pep-${aiFoundryAiServicesResourceName}'
customNetworkInterfaceName: 'nic-${aiFoundryAiServicesResourceName}'
location: location
tags: tags
privateLinkServiceConnections: [
{
name: 'pep-${aiFoundryAiServicesResourceName}-connection'
properties: {
privateLinkServiceId: aiFoundryAiServices!.outputs.resourceId
groupIds: ['account']
}
}
]
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{
name: 'ai-services-dns-zone-cognitiveservices'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cognitiveServices]!.outputs.resourceId
}
{
name: 'ai-services-dns-zone-openai'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.openAI]!.outputs.resourceId
}
{
name: 'ai-services-dns-zone-aiservices'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.aiServices]!.outputs.resourceId
}
]
}
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
}
}
// AI Foundry: AI Services Content Understanding
var aiFoundryAiServicesCUResourceName = 'aif-${solutionSuffix}-cu'
var aiServicesNameCu = 'aisa-${solutionSuffix}-cu'
module cognitiveServicesCu 'br/public:avm/res/cognitive-services/account:0.14.1' = {
name: take('avm.res.cognitive-services.account.${aiFoundryAiServicesCUResourceName}', 64)
params: {
name: aiServicesNameCu
location: contentUnderstandingLocation
tags: tags
enableTelemetry: enableTelemetry
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
sku: 'S0'
kind: 'AIServices'
networkAcls: {
defaultAction: 'Allow'
virtualNetworkRules: []
ipRules: []
}
managedIdentities: { userAssignedResourceIds: [userAssignedIdentity!.outputs.resourceId] } //To create accounts or projects, you must enable a managed identity on your resource
disableLocalAuth: true
customSubDomainName: aiServicesNameCu
apiProperties: {
// staticsEnabled: false
}
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
privateEndpoints: []
roleAssignments: [
{
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Azure AI User
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
]
}
}
// ========== AI Services CU: Separate Private Endpoint ========== //
module cognitiveServicesCuPrivateEndpoint 'br/public:avm/res/network/private-endpoint:0.8.1' = if (enablePrivateNetworking) {
name: take('pep-${aiFoundryAiServicesCUResourceName}-deployment', 64)
params: {
name: 'pep-${aiFoundryAiServicesCUResourceName}'
customNetworkInterfaceName: 'nic-${aiFoundryAiServicesCUResourceName}'
location: location
tags: tags
privateLinkServiceConnections: [
{
name: 'pep-${aiFoundryAiServicesCUResourceName}-connection'
properties: {
privateLinkServiceId: cognitiveServicesCu.outputs.resourceId
groupIds: ['account']
}
}
]
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{
name: 'ai-services-cu-dns-zone-cognitiveservices'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cognitiveServices]!.outputs.resourceId
}
{
name: 'ai-services-cu-dns-zone-openai'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.openAI]!.outputs.resourceId
}
{
name: 'ai-services-cu-dns-zone-aiservices'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.aiServices]!.outputs.resourceId
}
]
}
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
}
}
// ========== AVM WAF ========== //
// ========== AI Foundry: AI Search ========== //
var aiSearchName = 'srch-${solutionSuffix}'
var aiSearchConnectionName = 'foundry-search-connection-${solutionSuffix}'
resource searchService 'Microsoft.Search/searchServices@2024-06-01-preview' = {
name: aiSearchName
location: location
sku: {
name: 'standard'
}
}
// Separate module for Search Service to enable managed identity and update other properties, as this reduces deployment time
module searchServiceUpdate 'br/public:avm/res/search/search-service:0.12.0' = {
name: take('avm.res.search.enable-identity.${aiSearchName}', 64)
params: {
// Required parameters
name: aiSearchName
location: location
enableTelemetry: enableTelemetry
diagnosticSettings: enableMonitoring ? [
{
workspaceResourceId: logAnalyticsWorkspaceResourceId
}
] : null
disableLocalAuth: true
hostingMode: 'Default'
managedIdentities: {
systemAssigned: true
}
networkRuleSet: {
bypass: 'AzureServices'
ipRules: []
}
roleAssignments: [
{
roleDefinitionIdOrName: '7ca78c08-252a-4471-8644-bb5ff32d4ba0'
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '8ebe5a00-799e-43f5-93ac-243d3dce84a7' //'Search Index Data Contributor'
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '1407120a-92aa-4202-b7e9-c0e197c71c8f'
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '1407120a-92aa-4202-b7e9-c0e197c71c8f'
principalId: backendUserAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '1407120a-92aa-4202-b7e9-c0e197c71c8f' // Search Index Data Reader
principalId: !useExistingAiFoundryAiProject ? aiFoundryAiServices.outputs.aiProjectInfo.aiprojectSystemAssignedMIPrincipalId : existingAiFoundryAiServicesProject!.identity.principalId
principalType: 'ServicePrincipal'
}
{
roleDefinitionIdOrName: '7ca78c08-252a-4471-8644-bb5ff32d4ba0' // Search Service Contributor
principalId: !useExistingAiFoundryAiProject ? aiFoundryAiServices.outputs.aiProjectInfo.aiprojectSystemAssignedMIPrincipalId : existingAiFoundryAiServicesProject!.identity.principalId
principalType: 'ServicePrincipal'
}
]
partitionCount: 1
replicaCount: 1
sku: 'standard'
semanticSearch: 'free'
// Use the deployment tags provided to the template
tags: tags
publicNetworkAccess: 'Enabled' //enablePrivateNetworking ? 'Disabled' : 'Enabled'
privateEndpoints: false //enablePrivateNetworking
? [
{
name: 'pep-${aiSearchName}'
customNetworkInterfaceName: 'nic-${aiSearchName}'
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{ privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.search]!.outputs.resourceId }
]
}
service: 'searchService'
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
}
]
: []
}
}
// ========== Search Service to AI Services Role Assignment ========== //
resource searchServiceToAiServicesRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (!useExistingAiFoundryAiProject) {
name: guid(aiSearchName, '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd', aiFoundryAiServicesResourceName)
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd') // Cognitive Services OpenAI User
principalId: searchServiceUpdate.outputs.systemAssignedMIPrincipalId!
principalType: 'ServicePrincipal'
}
}
resource projectAISearchConnection 'Microsoft.CognitiveServices/accounts/projects/connections@2025-10-01-preview' = if (!useExistingAiFoundryAiProject) {
name: '${aiFoundryAiServicesResourceName}/${aiFoundryAiServicesAiProjectResourceName}/${aiSearchConnectionName}'
properties: {
category: 'CognitiveSearch'
target: 'https://${aiSearchName}.search.windows.net'
authType: 'AAD'
isSharedToAll: true
metadata: {
ApiType: 'Azure'
ResourceId: searchService.id
location: searchService.location
}
}
dependsOn: [
aiFoundryAiServices
]
}
module existing_AIProject_SearchConnectionModule 'modules/deploy_aifp_aisearch_connection.bicep' = if (useExistingAiFoundryAiProject) {
name: 'aiProjectSearchConnectionDeployment'
scope: resourceGroup(aiFoundryAiServicesSubscriptionId, aiFoundryAiServicesResourceGroupName)
params: {
existingAIProjectName: aiFoundryAiProjectResourceName
existingAIFoundryName: aiFoundryAiServicesResourceName
aiSearchName: aiSearchName
aiSearchResourceId: searchService.id
aiSearchLocation: searchService.location
aiSearchConnectionName: aiSearchConnectionName
}
}
// Role assignment for existing AI Services scenario
module searchServiceToExistingAiServicesRoleAssignment 'modules/role-assignment.bicep' = if (useExistingAiFoundryAiProject) {
name: 'searchToExistingAiServices-roleAssignment'
scope: resourceGroup(aiFoundryAiServicesSubscriptionId, aiFoundryAiServicesResourceGroupName)
params: {
principalId: searchServiceUpdate.outputs.systemAssignedMIPrincipalId!
roleDefinitionId: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd' // Cognitive Services OpenAI User
targetResourceName: aiFoundryAiServices.outputs.name
}
}
// ========== Storage account module ========== //
var storageAccountName = 'st${solutionSuffix}'
module storageAccount 'br/public:avm/res/storage/storage-account:0.31.0' = {
name: take('avm.res.storage.storage-account.${storageAccountName}', 64)
params: {
name: storageAccountName
location: location
managedIdentities: {
systemAssigned: true
userAssignedResourceIds: [ userAssignedIdentity!.outputs.resourceId ]
}
minimumTlsVersion: 'TLS1_2'
supportsHttpsTrafficOnly: true
accessTier: 'Hot'
enableTelemetry: enableTelemetry
tags: tags
enableHierarchicalNamespace: true
roleAssignments: [
{
principalId: userAssignedIdentity.outputs.principalId
roleDefinitionIdOrName: 'Storage Blob Data Contributor'
principalType: 'ServicePrincipal'
}
{
principalId: userAssignedIdentity.outputs.principalId
roleDefinitionIdOrName: 'Storage Account Contributor'
principalType: 'ServicePrincipal'
}
{
principalId: userAssignedIdentity.outputs.principalId
roleDefinitionIdOrName: 'Storage File Data Privileged Contributor'
principalType: 'ServicePrincipal'
}
]
networkAcls: {
bypass: 'AzureServices, Logging, Metrics'
defaultAction: enablePrivateNetworking ? 'Deny' : 'Allow'
virtualNetworkRules: []
}
allowSharedKeyAccess: true
allowBlobPublicAccess: false
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
privateEndpoints: enablePrivateNetworking
? [
{
name: 'pep-blob-${solutionSuffix}'
service: 'blob'
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{
name: 'storage-dns-zone-group-blob'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageBlob]!.outputs.resourceId
}
]
}
}
{
name: 'pep-queue-${solutionSuffix}'
service: 'queue'
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{
name: 'storage-dns-zone-group-queue'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageQueue]!.outputs.resourceId
}
]
}
}
{
name: 'pep-file-${solutionSuffix}'
service: 'file'
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{
name: 'storage-dns-zone-group-file'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageFile]!.outputs.resourceId
}
]
}
}
{
name: 'pep-dfs-${solutionSuffix}'
service: 'dfs'
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId