-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathmain.bicep
More file actions
1154 lines (1050 loc) · 39.5 KB
/
Copy pathmain.bicep
File metadata and controls
1154 lines (1050 loc) · 39.5 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'
metadata name = 'Intelligent Content Generation Accelerator'
metadata description = '''Solution Accelerator for multimodal marketing content generation using Microsoft Agent Framework.
'''
@minLength(3)
@maxLength(15)
@description('Optional. A unique application/solution name for all resources in this deployment.')
param solutionName string = 'contentgen'
@maxLength(5)
@description('Optional. A unique text value for the solution.')
param solutionUniqueText string = substring(uniqueString(subscription().id, resourceGroup().name, solutionName), 0, 5)
@allowed([
'australiaeast'
'centralus'
'eastasia'
'eastus'
'eastus2'
'japaneast'
'northeurope'
'southeastasia'
'swedencentral'
'uksouth'
'westus'
'westus3'
])
@metadata({ azd: { type: 'location' } })
@description('Required. Azure region for all services.')
param location string
@minLength(3)
@description('Optional. Secondary location for databases creation.')
param secondaryLocation string = 'uksouth'
// NOTE: Metadata must be compile-time constants. Update usageName manually if you change model parameters.
// Format: 'OpenAI.<DeploymentType>.<ModelName>,<Capacity>'
// Allowed regions: Union of GPT-5.1, gpt-image-1-mini, and gpt-image-1.5 GlobalStandard availability
@allowed([
'australiaeast'
'canadaeast'
'eastus2'
'japaneast'
'koreacentral'
'polandcentral'
'swedencentral'
'switzerlandnorth'
'uaenorth'
'uksouth'
'westus3'
])
@metadata({
azd: {
type: 'location'
usageName: [
'OpenAI.GlobalStandard.gpt-5.1,150'
'OpenAI.GlobalStandard.gpt-image-1-mini,1'
]
}
})
@description('Required. Location for AI deployments.')
param azureAiServiceLocation string
@minLength(1)
@allowed([
'Standard'
'GlobalStandard'
])
@description('Optional. GPT model deployment type.')
param gptModelDeploymentType string = 'GlobalStandard'
@minLength(1)
@description('Optional. Name of the GPT model to deploy.')
param gptModelName string = 'gpt-5.1'
@description('Optional. Version of the GPT model to deploy.')
param gptModelVersion string = '2025-11-13'
@description('Optional. Image model to deploy: gpt-image-1-mini, gpt-image-1.5, or none to skip.')
@allowed([
'gpt-image-1-mini'
'gpt-image-1.5'
'none'
])
param imageModelChoice string = 'gpt-image-1-mini'
@description('Optional. API version for Azure OpenAI service.')
param azureOpenaiAPIVersion string = '2025-01-01-preview'
@minValue(10)
@description('Optional. AI model deployment token capacity.')
param gptModelCapacity int = 150
@minValue(1)
@description('Optional. Image model deployment capacity (RPM).')
param imageModelCapacity int = 1
@description('Optional. Existing Log Analytics Workspace Resource ID.')
param existingLogAnalyticsWorkspaceId string = ''
@description('Optional. Resource ID of an existing Foundry project.')
param azureExistingAIProjectResourceId string = ''
@description('Optional. Deploy Azure Bastion and Jumpbox resources for private network administration.')
param deployBastionAndJumpbox bool = false
@description('Optional. Jumpbox VM size. Must support accelerated networking and Premium SSD.')
param vmSize string = ''
@description('Optional. Jumpbox VM admin username.')
param vmAdminUsername string = ''
@description('Optional. Jumpbox VM admin password.')
@secure()
param vmAdminPassword string = ''
@description('Optional. The tags to apply to all deployed Azure resources.')
param tags object = {}
@description('Optional. Enable monitoring for applicable resources (WAF-aligned).')
param enableMonitoring bool = false
@description('Optional. Enable Azure AI Foundry mode for multi-agent orchestration.')
param useFoundryMode bool = true
@description('Optional. Enable scalability for applicable resources (WAF-aligned).')
param enableScalability bool = false
@description('Optional. Enable redundancy for applicable resources (WAF-aligned).')
param enableRedundancy bool = false
@description('Optional. Enable private networking for applicable resources (WAF-aligned).')
param enablePrivateNetworking bool = false
@description('Optional. The existing Container Registry name (without .azurecr.io). Must contain pre-built images: content-gen-app and content-gen-api.')
param acrName string = 'contentgencontainerreg'
@description('Optional. Image Tag.')
param imageTag string = 'latest'
@description('Optional. Enable/Disable usage telemetry for module.')
param enableTelemetry bool = true
@description('Optional. Created by user name.')
param createdBy string = contains(deployer(), 'userPrincipalName')? split(deployer().userPrincipalName, '@')[0]: deployer().objectId
// ============== //
// Variables //
// ============== //
var solutionLocation = empty(location) ? resourceGroup().location : location
// acrName is required - points to existing ACR with pre-built images
var acrResourceName = acrName
var solutionSuffix = toLower(trim(replace(
replace(
replace(replace(replace(replace('${solutionName}${solutionUniqueText}', '-', ''), '_', ''), '.', ''), '/', ''),
' ',
''
),
'*',
''
)))
var cosmosDbZoneRedundantHaRegionPairs = {
australiaeast: 'uksouth'
centralus: 'eastus2'
eastasia: 'southeastasia'
eastus: 'centralus'
eastus2: 'centralus'
japaneast: 'australiaeast'
northeurope: 'westeurope'
southeastasia: 'eastasia'
uksouth: 'westeurope'
westus: 'westus3'
westus3: 'westus'
}
var cosmosDbHaLocation = cosmosDbZoneRedundantHaRegionPairs[?resourceGroup().location] ?? secondaryLocation
var replicaRegionPairs = {
australiaeast: 'australiasoutheast'
centralus: 'westus'
eastasia: 'japaneast'
eastus: 'centralus'
eastus2: 'centralus'
japaneast: 'eastasia'
northeurope: 'westeurope'
southeastasia: 'eastasia'
uksouth: 'westeurope'
westus: 'westus3'
westus3: 'westus'
}
var replicaLocation = replicaRegionPairs[?resourceGroup().location] ?? secondaryLocation
var azureSearchIndex = 'products'
var aiSearchName = 'srch-${solutionSuffix}'
// Extracts subscription, resource group, and workspace name from the resource ID
var useExistingLogAnalytics = !empty(existingLogAnalyticsWorkspaceId)
var useExistingAiFoundryAiProject = !empty(azureExistingAIProjectResourceId)
var aiFoundryAiServicesResourceGroupName = useExistingAiFoundryAiProject
? split(azureExistingAIProjectResourceId, '/')[4]
: 'rg-${solutionSuffix}'
var aiFoundryAiServicesSubscriptionId = useExistingAiFoundryAiProject
? split(azureExistingAIProjectResourceId, '/')[2]
: subscription().subscriptionId
var aiFoundryAiServicesResourceName = useExistingAiFoundryAiProject
? split(azureExistingAIProjectResourceId, '/')[8]
: 'aif-${solutionSuffix}'
var aiFoundryAiProjectResourceName = useExistingAiFoundryAiProject
? split(azureExistingAIProjectResourceId, '/')[10]
: 'proj-${solutionSuffix}'
// Base model deployments (GPT only - no embeddings needed for content generation)
var baseModelDeployments = [
{
format: 'OpenAI'
name: gptModelName
model: gptModelName
sku: {
name: gptModelDeploymentType
capacity: gptModelCapacity
}
version: gptModelVersion
raiPolicyName: 'Microsoft.Default'
}
]
// Image model configuration based on choice
var imageModelConfig = {
'gpt-image-1-mini': {
name: 'gpt-image-1-mini'
version: '2025-10-06'
sku: 'GlobalStandard'
}
'gpt-image-1.5': {
name: 'gpt-image-1.5'
version: '2025-12-16'
sku: 'GlobalStandard'
}
none: {
name: ''
version: ''
sku: ''
}
}
// Image model deployment (optional)
var imageModelDeployment = imageModelChoice != 'none' ? [
{
format: 'OpenAI'
name: imageModelConfig[imageModelChoice].name
model: imageModelConfig[imageModelChoice].name
sku: {
name: imageModelConfig[imageModelChoice].sku
capacity: imageModelCapacity
}
version: imageModelConfig[imageModelChoice].version
raiPolicyName: 'Microsoft.Default'
}
] : []
// Combine deployments based on imageModelChoice
var aiFoundryAiServicesModelDeployment = concat(baseModelDeployments, imageModelDeployment)
var aiFoundryAiProjectDescription = 'Content Generation AI Foundry Project'
// Reference existing resource group to access current tags
resource existingResourceGroup 'Microsoft.Resources/resourceGroups@2024-03-01' existing = {
scope: subscription()
name: resourceGroup().name
}
var existingTags = existingResourceGroup.tags ?? {}
// ============== //
// Resources //
// ============== //
#disable-next-line no-deployments-resources
resource avmTelemetry 'Microsoft.Resources/deployments@2025-04-01' = if (enableTelemetry) {
name: '46d3xbcp.ptn.sa-contentgeneration.${replace('-..--..-', '.', '-')}.${substring(uniqueString(deployment().name, solutionLocation), 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'
}
}
}
}
}
// ========== Resource Group Tag ========== //
resource resourceGroupTags 'Microsoft.Resources/tags@2025-04-01' = {
name: 'default'
properties: {
tags: union(
existingTags,
tags,
{
TemplateName: 'ContentGen'
Type: enablePrivateNetworking ? 'WAF' : 'Non-WAF'
CreatedBy: createdBy
}
)
}
}
// ========== Log Analytics Workspace ========== //
var logAnalyticsWorkspaceResourceName = 'log-${solutionSuffix}'
module logAnalyticsWorkspace 'br/public:avm/res/operational-insights/workspace:0.15.0' = if (enableMonitoring && !useExistingLogAnalytics) {
name: take('avm.res.operational-insights.workspace.${logAnalyticsWorkspaceResourceName}', 64)
params: {
name: logAnalyticsWorkspaceResourceName
tags: tags
location: solutionLocation
enableTelemetry: enableTelemetry
skuName: 'PerGB2018'
dataRetention: 365
features: { enableLogAccessUsingOnlyResourcePermissions: true }
diagnosticSettings: [{ useThisWorkspace: true }]
dailyQuotaGb: enableRedundancy ? '10' : null
replication: enableRedundancy
? {
enabled: true
location: replicaLocation
}
: null
publicNetworkAccessForIngestion: enablePrivateNetworking ? 'Disabled' : 'Enabled'
publicNetworkAccessForQuery: enablePrivateNetworking ? 'Disabled' : 'Enabled'
}
}
var logAnalyticsWorkspaceResourceId = useExistingLogAnalytics
? existingLogAnalyticsWorkspaceId
: (enableMonitoring ? logAnalyticsWorkspace!.outputs.resourceId : '')
// ========== 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: solutionLocation
enableTelemetry: enableTelemetry
retentionInDays: 365
kind: 'web'
disableIpMasking: false
flowType: 'Bluefield'
workspaceResourceId: logAnalyticsWorkspaceResourceId
}
}
// ========== User Assigned Identity ========== //
var userAssignedIdentityResourceName = 'id-${solutionSuffix}'
module userAssignedIdentity 'br/public:avm/res/managed-identity/user-assigned-identity:0.5.0' = {
name: take('avm.res.managed-identity.user-assigned-identity.${userAssignedIdentityResourceName}', 64)
params: {
name: userAssignedIdentityResourceName
location: solutionLocation
tags: tags
enableTelemetry: enableTelemetry
}
}
// ========== Virtual Network and Networking Components ========== //
var deployAdminAccessResources = enablePrivateNetworking && deployBastionAndJumpbox && !empty(vmAdminPassword)
module virtualNetwork 'modules/virtualNetwork.bicep' = if (enablePrivateNetworking) {
name: take('module.virtualNetwork.${solutionSuffix}', 64)
params: {
vnetName: 'vnet-${solutionSuffix}'
addressPrefixes: ['10.0.0.0/20'] // 4096 addresses (enough for 8 /23 subnets or 16 /24)
location: solutionLocation
deployBastionAndJumpbox: deployAdminAccessResources
tags: tags
logAnalyticsWorkspaceId: logAnalyticsWorkspaceResourceId
resourceSuffix: solutionSuffix
enableTelemetry: enableTelemetry
}
}
// Azure Bastion Host
var bastionHostName = 'bas-${solutionSuffix}'
var zoneSupportedJumpboxLocations = [
'australiaeast'
'centralus'
'eastus'
'eastus2'
'japaneast'
'northeurope'
'southeastasia'
'swedencentral'
'uksouth'
'westus3'
]
module bastionHost 'br/public:avm/res/network/bastion-host:0.8.2' = if (deployAdminAccessResources) {
name: take('avm.res.network.bastion-host.${bastionHostName}', 64)
params: {
name: bastionHostName
skuName: 'Standard'
location: solutionLocation
virtualNetworkResourceId: virtualNetwork!.outputs.resourceId
diagnosticSettings: !empty(logAnalyticsWorkspaceResourceId)
? [
{
name: 'bastionDiagnostics'
workspaceResourceId: logAnalyticsWorkspaceResourceId
logCategoriesAndGroups: [
{
categoryGroup: 'allLogs'
enabled: true
}
]
}
]
: []
tags: tags
enableTelemetry: enableTelemetry
publicIPAddressObject: {
name: 'pip-${bastionHostName}'
}
}
}
// Jumpbox Virtual Machine
var jumpboxUniqueToken = take(uniqueString(resourceGroup().id, solutionSuffix), 10)
var jumpboxVmName = take('vm-${jumpboxUniqueToken}', 15)
module jumpboxVM 'br/public:avm/res/compute/virtual-machine:0.21.0' = if (deployAdminAccessResources) {
name: take('avm.res.compute.virtual-machine.${jumpboxVmName}', 64)
params: {
name: take(jumpboxVmName, 15)
enableTelemetry: enableTelemetry
computerName: take(jumpboxVmName, 15)
osType: 'Windows'
vmSize: empty(vmSize) ? 'Standard_D2s_v5' : vmSize
adminUsername: empty(vmAdminUsername) ? 'JumpboxAdminUser' : vmAdminUsername
adminPassword: vmAdminPassword
managedIdentities: {
userAssignedResourceIds: [
userAssignedIdentity.outputs.resourceId
]
}
availabilityZone: contains(zoneSupportedJumpboxLocations, solutionLocation) ? 1 : -1
imageReference: {
publisher: 'microsoft-dsvm'
offer: 'dsvm-win-2022'
sku: 'winserver-2022'
version: 'latest'
}
nicConfigurations: [
{
name: 'nic-${jumpboxVmName}'
enableAcceleratedNetworking: true
ipConfigurations: [
{
name: 'ipconfig01'
subnetResourceId: virtualNetwork!.outputs.jumpboxSubnetResourceId
}
]
}
]
osDisk: {
caching: 'ReadWrite'
diskSizeGB: 128
managedDisk: {
storageAccountType: 'Premium_LRS'
}
}
encryptionAtHost: false // Some Azure subscriptions do not support encryption at host
extensionMonitoringAgentConfig: {
enabled: enableMonitoring
dataCollectionRuleAssociations: enableMonitoring ? [
{
name: 'dcra-${jumpboxVmName}'
dataCollectionRuleResourceId: jumpboxDcr!.outputs.resourceId
description: 'Associates the Windows security event DCR with the jumpbox VM.'
}
] : []
}
location: solutionLocation
tags: tags
}
dependsOn: (enableMonitoring && !useExistingLogAnalytics) ? [logAnalyticsWorkspace, jumpboxDcr] : (enableMonitoring ? [jumpboxDcr] : [])
}
// ========== Data Collection Rule for Jumpbox Security Event Logs (SFI-AzTBv17) ========== //
var jumpboxDcrName = take('dcr-${jumpboxVmName}', 64)
var dcrLogAnalyticsDestinationName = 'la-${logAnalyticsWorkspaceResourceName}-destination'
module jumpboxDcr 'br/public:avm/res/insights/data-collection-rule:0.11.0' = if (deployAdminAccessResources && enableMonitoring) {
name: take('avm.res.insights.data-collection-rule.${jumpboxDcrName}', 64)
params: {
name: jumpboxDcrName
location: solutionLocation
tags: tags
enableTelemetry: enableTelemetry
dataCollectionRuleProperties: {
kind: 'Windows'
description: 'Collects Windows Security audit success/failure events from jumpbox VM (SFI-AzTBv17 compliance).'
dataSources: {
windowsEventLogs: [
{
name: 'securityEventLogsDataSource'
streams: [
'Microsoft-SecurityEvent'
]
xPathQueries: [
'Security!*[System[(band(Keywords,13510798882111488)) and (EventID != 4624)]]'
]
}
]
}
destinations: {
logAnalytics: [
{
name: dcrLogAnalyticsDestinationName
workspaceResourceId: logAnalyticsWorkspaceResourceId
}
]
}
dataFlows: [
{
streams: [
'Microsoft-SecurityEvent'
]
destinations: [
dcrLogAnalyticsDestinationName
]
}
]
}
}
}
// ========== Private DNS Zones ========== //
// Only create DNS zones for resources that need private endpoints:
// - Cognitive Services (for AI Services)
// - OpenAI (for Azure OpenAI endpoints)
// - Blob Storage
// - Cosmos DB (Documents)
var privateDnsZones = [
'privatelink.cognitiveservices.azure.com'
'privatelink.openai.azure.com'
'privatelink.blob.${environment().suffixes.storage}'
'privatelink.documents.azure.com'
]
var dnsZoneIndex = {
cognitiveServices: 0
openAI: 1
storageBlob: 2
cosmosDB: 3
}
@batchSize(5)
module avmPrivateDnsZones 'br/public:avm/res/network/private-dns-zone:0.8.1' = [
for (zone, i) in privateDnsZones: if (enablePrivateNetworking) {
name: take('avm.res.network.private-dns-zone.${replace(zone, '.', '-')}', 64)
params: {
name: zone
tags: tags
enableTelemetry: enableTelemetry
virtualNetworkLinks: [
{
virtualNetworkResourceId: enablePrivateNetworking ? virtualNetwork!.outputs.resourceId : ''
registrationEnabled: false
}
]
}
}
]
// ========== AI Foundry: AI Services ========== //
module aiFoundryAiServices 'br/public:avm/res/cognitive-services/account:0.14.2' = if (!useExistingAiFoundryAiProject) {
name: take('avm.res.cognitive-services.account.${aiFoundryAiServicesResourceName}', 64)
params: {
name: aiFoundryAiServicesResourceName
location: azureAiServiceLocation
tags: tags
enableTelemetry: enableTelemetry
sku: 'S0'
kind: 'AIServices'
disableLocalAuth: true
allowProjectManagement: true
customSubDomainName: aiFoundryAiServicesResourceName
restrictOutboundNetworkAccess: false
deployments: [
for deployment in aiFoundryAiServicesModelDeployment: {
name: deployment.name
model: {
format: deployment.format
name: deployment.name
version: deployment.version
}
raiPolicyName: deployment.raiPolicyName
sku: {
name: deployment.sku.name
capacity: deployment.sku.capacity
}
}
]
networkAcls: {
defaultAction: 'Allow'
virtualNetworkRules: []
ipRules: []
}
managedIdentities: {
userAssignedResourceIds: [userAssignedIdentity!.outputs.resourceId]
}
roleAssignments: [
{
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Foundry User
principalId: userAssignedIdentity.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: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Foundry User for deployer
principalId: deployer().objectId
}
]
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
// Note: Private endpoint is created separately to avoid timing issues with model deployments
}
}
// Create private endpoint for AI Services AFTER the account is fully provisioned
module aiServicesPrivateEndpoint 'br/public:avm/res/network/private-endpoint:0.12.0' = if (!useExistingAiFoundryAiProject && enablePrivateNetworking) {
name: take('pep-ai-services-${aiFoundryAiServicesResourceName}', 64)
params: {
name: 'pep-${aiFoundryAiServicesResourceName}'
location: solutionLocation
tags: tags
enableTelemetry: enableTelemetry
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
privateLinkServiceConnections: [
{
name: 'pep-${aiFoundryAiServicesResourceName}'
properties: {
privateLinkServiceId: aiFoundryAiServices!.outputs.resourceId
groupIds: ['account']
}
}
]
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{
name: 'cognitiveservices'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cognitiveServices]!.outputs.resourceId
}
{
name: 'openai'
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.openAI]!.outputs.resourceId
}
]
}
}
}
module aiFoundryAiServicesProject 'modules/ai-project.bicep' = if (!useExistingAiFoundryAiProject) {
name: take('module.ai-project.${aiFoundryAiProjectResourceName}', 64)
params: {
name: aiFoundryAiProjectResourceName
location: azureAiServiceLocation
tags: tags
desc: aiFoundryAiProjectDescription
aiServicesName: aiFoundryAiServicesResourceName
azureExistingAIProjectResourceId: azureExistingAIProjectResourceId
}
dependsOn: [
aiFoundryAiServices
]
}
var aiFoundryAiProjectEndpoint = useExistingAiFoundryAiProject
? 'https://${aiFoundryAiServicesResourceName}.services.ai.azure.com/api/projects/${aiFoundryAiProjectResourceName}'
: aiFoundryAiServicesProject!.outputs.apiEndpoint
// ========== Role Assignments for Existing AI Services ========== //
module existingAiServicesRoleAssignments 'modules/deploy_foundry_role_assignment.bicep' = if (useExistingAiFoundryAiProject) {
name: take('module.foundry-role-assignment.${aiFoundryAiServicesResourceName}', 64)
scope: resourceGroup(aiFoundryAiServicesSubscriptionId, aiFoundryAiServicesResourceGroupName)
params: {
aiServicesName: aiFoundryAiServicesResourceName
principalId: userAssignedIdentity.outputs.principalId
principalType: 'ServicePrincipal'
}
}
// ========== Model Deployments for Existing AI Services ========== //
module existingAiServicesModelDeployments 'modules/deploy_ai_model.bicep' = if (useExistingAiFoundryAiProject) {
name: take('module.model-deployments-existing.${aiFoundryAiServicesResourceName}', 64)
scope: resourceGroup(aiFoundryAiServicesSubscriptionId, aiFoundryAiServicesResourceGroupName)
params: {
aiServicesName: aiFoundryAiServicesResourceName
deployments: [
for deployment in aiFoundryAiServicesModelDeployment: {
name: deployment.name
format: deployment.format
model: deployment.model
sku: {
name: deployment.sku.name
capacity: deployment.sku.capacity
}
version: deployment.version
raiPolicyName: deployment.raiPolicyName
}
]
}
dependsOn: [
existingAiServicesRoleAssignments
]
}
// ========== AI Search ========== //
module aiSearch 'br/public:avm/res/search/search-service:0.12.0' = {
name: take('avm.res.search.search-service.${aiSearchName}', 64)
params: {
name: aiSearchName
location: solutionLocation
tags: tags
enableTelemetry: enableTelemetry
sku: enableScalability ? 'standard' : 'basic'
replicaCount: enableRedundancy ? 3 : 1
partitionCount: 1
hostingMode: 'Default'
semanticSearch: 'free'
managedIdentities: { systemAssigned: true }
disableLocalAuth: true
roleAssignments: [
{
principalId: userAssignedIdentity.outputs.principalId
roleDefinitionIdOrName: 'Search Index Data Contributor'
principalType: 'ServicePrincipal'
}
{
principalId: userAssignedIdentity.outputs.principalId
roleDefinitionIdOrName: 'Search Service Contributor'
principalType: 'ServicePrincipal'
}
]
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
// AI Search remains publicly accessible - accessed from ACI via managed identity
publicNetworkAccess: 'Enabled'
}
}
// ========== Storage Account ========== //
var storageAccountName = 'st${solutionSuffix}'
var productImagesContainer = 'product-images'
var generatedImagesContainer = 'generated-images'
module storageAccount 'br/public:avm/res/storage/storage-account:0.32.0' = {
name: take('avm.res.storage.storage-account.${storageAccountName}', 64)
params: {
name: storageAccountName
location: solutionLocation
skuName: enableRedundancy ? 'Standard_ZRS' : 'Standard_LRS'
managedIdentities: { systemAssigned: true }
minimumTlsVersion: 'TLS1_2'
requireInfrastructureEncryption: true
enableTelemetry: enableTelemetry
tags: tags
accessTier: 'Hot'
supportsHttpsTrafficOnly: true
blobServices: {
containerDeleteRetentionPolicyEnabled: true
containerDeleteRetentionPolicyDays: 7
deleteRetentionPolicyEnabled: true
deleteRetentionPolicyDays: 7
containers: [
{
name: productImagesContainer
publicAccess: 'None'
}
{
name: generatedImagesContainer
publicAccess: 'None'
}
]
}
roleAssignments: [
{
principalId: userAssignedIdentity.outputs.principalId
roleDefinitionIdOrName: 'Storage Blob Data Contributor'
principalType: 'ServicePrincipal'
}
]
networkAcls: {
bypass: 'AzureServices'
defaultAction: enablePrivateNetworking ? 'Deny' : 'Allow'
}
allowBlobPublicAccess: false
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
privateEndpoints: enablePrivateNetworking
? [
{
service: 'blob'
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{ privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageBlob]!.outputs.resourceId }
]
}
}
]
: null
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
}
}
// ========== Cosmos DB ========== //
var cosmosDBResourceName = 'cosmos-${solutionSuffix}'
var cosmosDBDatabaseName = 'content_generation_db'
var cosmosDBConversationsContainer = 'conversations'
var cosmosDBProductsContainer = 'products'
module cosmosDB 'br/public:avm/res/document-db/database-account:0.19.0' = {
name: take('avm.res.document-db.database-account.${cosmosDBResourceName}', 64)
params: {
name: 'cosmos-${solutionSuffix}'
location: secondaryLocation
tags: tags
enableTelemetry: enableTelemetry
sqlDatabases: [
{
name: cosmosDBDatabaseName
containers: [
{
name: cosmosDBConversationsContainer
paths: [
'/userId'
]
}
{
name: cosmosDBProductsContainer
paths: [
'/category'
]
}
]
}
]
sqlRoleDefinitions: [
{
roleName: 'contentgen-data-contributor'
dataActions: [
'Microsoft.DocumentDB/databaseAccounts/readMetadata'
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*'
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*'
]
}
]
sqlRoleAssignments: [
{
principalId: userAssignedIdentity.outputs.principalId
roleDefinitionId: '00000000-0000-0000-0000-000000000002' // Built-in Cosmos DB Data Contributor
}
{
principalId: deployer().objectId
roleDefinitionId: '00000000-0000-0000-0000-000000000002' // Built-in Cosmos DB Data Contributor to the deployer
}
]
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
networkRestrictions: {
networkAclBypass: 'AzureServices'
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
}
zoneRedundant: enableRedundancy
capabilitiesToAdd: enableRedundancy ? null : ['EnableServerless']
enableAutomaticFailover: enableRedundancy
failoverLocations: enableRedundancy
? [
{
failoverPriority: 0
isZoneRedundant: true
locationName: secondaryLocation
}
{
failoverPriority: 1
isZoneRedundant: true
locationName: cosmosDbHaLocation
}
]
: [
{
locationName: secondaryLocation
failoverPriority: 0
isZoneRedundant: false
}
]
privateEndpoints: enablePrivateNetworking
? [
{
service: 'Sql'
subnetResourceId: virtualNetwork!.outputs.pepsSubnetResourceId
privateDnsZoneGroup: {
privateDnsZoneGroupConfigs: [
{ privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cosmosDB]!.outputs.resourceId }
]
}
}
]
: null
}
}
// ========== App Service Plan ========== //
var webServerFarmResourceName = 'asp-${solutionSuffix}'
module webServerFarm 'br/public:avm/res/web/serverfarm:0.7.0' = {
name: take('avm.res.web.serverfarm.${webServerFarmResourceName}', 64)
params: {
name: webServerFarmResourceName
tags: tags
enableTelemetry: enableTelemetry
location: solutionLocation
reserved: true
kind: 'linux'
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
skuName: enableScalability || enableRedundancy ? 'P1v3' : 'B1'
skuCapacity: enableRedundancy ? 2 : 1
zoneRedundant: enableRedundancy ? true : false
}
scope: resourceGroup(resourceGroup().name)
}
// ========== Web App ========== //
var webSiteResourceName = 'app-${solutionSuffix}'
// Backend URL: Use actual ACI IP/FQDN from deployment outputs
// This also creates an implicit dependency ensuring ACI deploys before the web app
var aciBackendUrl = enablePrivateNetworking
? 'http://${containerInstance.outputs.ipAddress}:8000'
: 'http://${containerInstance.outputs.fqdn}:8000'
module webSite 'modules/web-sites.bicep' = {
name: take('module.web-sites.${webSiteResourceName}', 64)
params: {
name: webSiteResourceName
tags: tags
location: solutionLocation
kind: 'app,linux,container'
serverFarmResourceId: webServerFarm.outputs.resourceId
managedIdentities: { userAssignedResourceIds: [userAssignedIdentity!.outputs.resourceId] }
siteConfig: {
// Frontend container - same for both modes
linuxFxVersion: 'DOCKER|${acrResourceName}.azurecr.io/content-gen-app:${imageTag}'
minTlsVersion: '1.2'
alwaysOn: true
ftpsState: 'FtpsOnly'
}
virtualNetworkSubnetId: enablePrivateNetworking ? virtualNetwork!.outputs.webSubnetResourceId : null
configs: concat(
[
{
// Frontend container proxies to ACI backend (both modes)
name: 'appsettings'
properties: {
DOCKER_REGISTRY_SERVER_URL: 'https://${acrResourceName}.azurecr.io'
BACKEND_URL: aciBackendUrl
AZURE_CLIENT_ID: userAssignedIdentity.outputs.clientId
}
applicationInsightResourceId: enableMonitoring ? applicationInsights!.outputs.resourceId : null
}
],
enableMonitoring
? [
{
name: 'logs'
properties: {}
}
]
: []
)
enableMonitoring: enableMonitoring
enableTelemetry: enableTelemetry
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
vnetRouteAllEnabled: enablePrivateNetworking
vnetImagePullEnabled: enablePrivateNetworking
e2eEncryptionEnabled: true
publicNetworkAccess: 'Enabled'
}