-
Notifications
You must be signed in to change notification settings - Fork 563
Expand file tree
/
Copy pathmain.bicep
More file actions
1871 lines (1765 loc) · 70.7 KB
/
main.bicep
File metadata and controls
1871 lines (1765 loc) · 70.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
// // ========== main.bicep ========== //
targetScope = 'resourceGroup'
metadata name = 'Multi-Agent Custom Automation Engine'
metadata description = '''This module contains the resources required to deploy the [Multi-Agent Custom Automation Engine solution accelerator](https://github.com/microsoft/Multi-Agent-Custom-Automation-Engine-Solution-Accelerator) for both Sandbox environments and WAF aligned environments.
> **Note:** This module is not intended for broad, generic use, as it was designed by the Commercial Solution Areas CTO team, as a Microsoft Solution Accelerator. Feature requests and bug fix requests are welcome if they support the needs of this organization but may not be incorporated if they aim to make this module more generic than what it needs to be for its primary use case. This module will likely be updated to leverage AVM resource modules in the future. This may result in breaking changes in upcoming versions when these features are implemented.
'''
@description('Optional. A unique application/solution name for all resources in this deployment. This should be 3-16 characters long.')
@minLength(3)
@maxLength(16)
param solutionName string = 'macae'
@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 = take(uniqueString(subscription().id, resourceGroup().name, solutionName), 5)
@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
//Get the current deployer's information
var deployerInfo = deployer()
var deployingUserPrincipalId = deployerInfo.objectId
// Restricting deployment to only supported Azure OpenAI regions validated with GPT-4o model
@allowed(['australiaeast', 'eastus2', 'francecentral', 'japaneast', 'norwayeast', 'swedencentral', 'uksouth', 'westus'])
@metadata({
azd: {
type: 'location'
usageName: [
'OpenAI.GlobalStandard.gpt4.1, 150'
'OpenAI.GlobalStandard.o4-mini, 50'
'OpenAI.GlobalStandard.gpt4.1-mini, 50'
]
}
})
@description('Required. Location for all AI service resources. This should be one of the supported Azure AI Service locations.')
param azureAiServiceLocation string
@minLength(1)
@description('Optional. Name of the GPT model to deploy:')
param gptModelName string = 'gpt-4.1-mini'
@description('Optional. Version of the GPT model to deploy. Defaults to 2025-04-14.')
param gptModelVersion string = '2025-04-14'
@minLength(1)
@description('Optional. Name of the GPT model to deploy:')
param gpt4_1ModelName string = 'gpt-4.1'
@description('Optional. Version of the GPT model to deploy. Defaults to 2025-04-14.')
param gpt4_1ModelVersion string = '2025-04-14'
@minLength(1)
@description('Optional. Name of the GPT Reasoning model to deploy:')
param gptReasoningModelName string = 'o4-mini'
@description('Optional. Version of the GPT Reasoning model to deploy. Defaults to 2025-04-16.')
param gptReasoningModelVersion string = '2025-04-16'
@description('Optional. Version of the Azure OpenAI service to deploy. Defaults to 2024-12-01-preview.')
param azureopenaiVersion string = '2024-12-01-preview'
@description('Optional. Version of the Azure AI Agent API version. Defaults to 2025-01-01-preview.')
param azureAiAgentAPIVersion string = '2025-01-01-preview'
@minLength(1)
@allowed([
'Standard'
'GlobalStandard'
])
@description('Optional. GPT model deployment type. Defaults to GlobalStandard.')
param gpt4_1ModelDeploymentType string = 'GlobalStandard'
@minLength(1)
@allowed([
'Standard'
'GlobalStandard'
])
@description('Optional. GPT model deployment type. Defaults to GlobalStandard.')
param gptModelDeploymentType string = 'GlobalStandard'
@minLength(1)
@allowed([
'Standard'
'GlobalStandard'
])
@description('Optional. GPT model deployment type. Defaults to GlobalStandard.')
param gptReasoningModelDeploymentType string = 'GlobalStandard'
@description('Optional. AI model deployment token capacity. Defaults to 50 for optimal performance.')
param gptModelCapacity int = 50
@description('Optional. AI model deployment token capacity. Defaults to 150 for optimal performance.')
param gpt4_1ModelCapacity int = 150
@description('Optional. AI model deployment token capacity. Defaults to 50 for optimal performance.')
param gptReasoningModelCapacity int = 50
@description('Optional. The tags to apply to all deployed Azure resources.')
param tags resourceInput<'Microsoft.Resources/resourceGroups@2025-04-01'>.tags = {}
@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. Enable redundancy for applicable resources, aligned with the Well Architected Framework recommendations. Defaults to false.')
param enableRedundancy bool = false
@description('Optional. Enable private networking for applicable resources, aligned with the Well Architected Framework recommendations. Defaults to false.')
param enablePrivateNetworking bool = false
@secure()
@description('Optional. The user name for the administrator account of the virtual machine. Allows to customize credentials if `enablePrivateNetworking` is set to true.')
param virtualMachineAdminUsername string?
@description('Optional. The password for the administrator account of the virtual machine. Allows to customize credentials if `enablePrivateNetworking` is set to true.')
@secure()
param virtualMachineAdminPassword string?
@description('Optional. The size of the virtual machine. Defaults to Standard_D2s_v5.')
param virtualMachineSize string = 'Standard_D2s_v5'
// These parameters are changed for testing - please reset as part of publication
@description('Optional. The Container Registry hostname where the docker images for the backend are located.')
param backendContainerRegistryHostname string = 'biabcontainerreg.azurecr.io'
@description('Optional. The Container Image Name to deploy on the backend.')
param backendContainerImageName string = 'macaebackend'
@description('Optional. The Container Image Tag to deploy on the backend.')
param backendContainerImageTag string = 'latest_v4'
@description('Optional. The Container Registry hostname where the docker images for the frontend are located.')
param frontendContainerRegistryHostname string = 'biabcontainerreg.azurecr.io'
@description('Optional. The Container Image Name to deploy on the frontend.')
param frontendContainerImageName string = 'macaefrontend'
@description('Optional. The Container Image Tag to deploy on the frontend.')
param frontendContainerImageTag string = 'latest_v4'
@description('Optional. The Container Registry hostname where the docker images for the MCP are located.')
param MCPContainerRegistryHostname string = 'biabcontainerreg.azurecr.io'
@description('Optional. The Container Image Name to deploy on the MCP.')
param MCPContainerImageName string = 'macaemcp'
@description('Optional. The Container Image Tag to deploy on the MCP.')
param MCPContainerImageTag string = 'latest_v4'
@description('Optional. Enable/Disable usage telemetry for module.')
param enableTelemetry bool = true
@description('Optional. Resource ID of an existing Log Analytics Workspace.')
param existingLogAnalyticsWorkspaceId string = ''
@description('Optional. Resource ID of an existing Ai Foundry AI Services resource.')
param existingAiFoundryAiProjectResourceId string = ''
// ============== //
// Variables //
// ============== //
var solutionSuffix = toLower(trim(replace(
replace(
replace(replace(replace(replace('${solutionName}${solutionUniqueText}', '-', ''), '_', ''), '.', ''), '/', ''),
' ',
''
),
'*',
''
)))
// 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'
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[location]
// 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[location]
// ============== //
// Resources //
// ============== //
var allTags = union(
{
'azd-env-name': solutionName
},
tags
)
var existingTags = resourceGroup().tags ?? {}
@description('Tag, Created by user name')
param createdBy string = contains(deployer(), 'userPrincipalName')
? split(deployer().userPrincipalName, '@')[0]
: deployer().objectId
var deployerPrincipalType = contains(deployer(), 'userPrincipalName') ? 'User' : 'ServicePrincipal'
resource resourceGroupTags 'Microsoft.Resources/tags@2021-04-01' = {
name: 'default'
properties: {
tags: union(
existingTags,
allTags,
{
TemplateName: 'MACAE'
Type: enablePrivateNetworking ? 'WAF' : 'Non-WAF'
CreatedBy: createdBy
DeploymentName: deployment().name
SolutionSuffix: solutionSuffix
}
)
}
}
#disable-next-line no-deployments-resources
resource avmTelemetry 'Microsoft.Resources/deployments@2024-03-01' = if (enableTelemetry) {
name: '46d3xbcp.ptn.sa-multiagentcustauteng.${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'
}
}
}
}
}
// 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)
}
// ========== 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 && !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 ? 150 : null //WAF recommendation: 150 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
}
}
// Log Analytics Name, workspace ID, customer ID, and shared key (existing or new)
var logAnalyticsWorkspaceName = useExistingLogAnalytics
? existingLogAnalyticsWorkspace!.name
: logAnalyticsWorkspace!.outputs.name
var logAnalyticsWorkspaceResourceId = useExistingLogAnalytics
? existingLogAnalyticsWorkspaceId
: logAnalyticsWorkspace!.outputs.resourceId
var logAnalyticsPrimarySharedKey = useExistingLogAnalytics
? existingLogAnalyticsWorkspace!.listKeys().primarySharedKey
: logAnalyticsWorkspace!.outputs!.primarySharedKey
var logAnalyticsWorkspaceId = useExistingLogAnalytics
? existingLogAnalyticsWorkspace!.properties.customerId
: logAnalyticsWorkspace!.outputs.logAnalyticsWorkspaceId
// ========== 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)
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 : ''
}
}
// ========== 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 userAssignedIdentity '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: location
tags: tags
enableTelemetry: enableTelemetry
}
}
// ========== Virtual Network ========== //
// WAF best practices for virtual networks: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/virtual-network
// WAF recommendations for networking and connectivity: https://learn.microsoft.com/en-us/azure/well-architected/security/networking
var virtualNetworkResourceName = 'vnet-${solutionSuffix}'
module virtualNetwork 'modules/virtualNetwork.bicep' = if (enablePrivateNetworking) {
name: take('module.virtualNetwork.${solutionSuffix}', 64)
params: {
name: 'vnet-${solutionSuffix}'
location: location
tags: tags
enableTelemetry: enableTelemetry
addressPrefixes: ['10.0.0.0/8']
logAnalyticsWorkspaceId: logAnalyticsWorkspaceResourceId
resourceSuffix: solutionSuffix
}
}
var bastionResourceName = 'bas-${solutionSuffix}'
// ========== Bastion host ========== //
// WAF best practices for virtual networks: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/virtual-network
// WAF recommendations for networking and connectivity: https://learn.microsoft.com/en-us/azure/well-architected/security/networking
module bastionHost 'br/public:avm/res/network/bastion-host:0.7.0' = if (enablePrivateNetworking) {
name: take('avm.res.network.bastion-host.${bastionResourceName}', 64)
params: {
name: bastionResourceName
location: location
skuName: 'Standard'
enableTelemetry: enableTelemetry
tags: tags
virtualNetworkResourceId: virtualNetwork!.?outputs.?resourceId
availabilityZones: []
publicIPAddressObject: {
name: 'pip-bas${solutionSuffix}'
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
tags: tags
}
disableCopyPaste: true
enableFileCopy: false
enableIpConnect: false
enableShareableLink: false
scaleUnits: 4
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
}
}
// ========== Virtual machine ========== //
// WAF best practices for virtual machines: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/virtual-machines
var maintenanceConfigurationResourceName = 'mc-${solutionSuffix}'
module maintenanceConfiguration 'br/public:avm/res/maintenance/maintenance-configuration:0.3.1' = if (enablePrivateNetworking) {
name: take('avm.res.compute.virtual-machine.${maintenanceConfigurationResourceName}', 64)
params: {
name: maintenanceConfigurationResourceName
location: location
tags: tags
enableTelemetry: enableTelemetry
extensionProperties: {
InGuestPatchMode: 'User'
}
maintenanceScope: 'InGuestPatch'
maintenanceWindow: {
startDateTime: '2024-06-16 00:00'
duration: '03:55'
timeZone: 'W. Europe Standard Time'
recurEvery: '1Day'
}
visibility: 'Custom'
installPatches: {
rebootSetting: 'IfRequired'
windowsParameters: {
classificationsToInclude: [
'Critical'
'Security'
]
}
linuxParameters: {
classificationsToInclude: [
'Critical'
'Security'
]
}
}
}
}
var dataCollectionRulesResourceName = 'dcr-${solutionSuffix}'
var dataCollectionRulesLocation = useExistingLogAnalytics
? existingLogAnalyticsWorkspace!.location
: logAnalyticsWorkspace!.outputs.location
module windowsVmDataCollectionRules 'br/public:avm/res/insights/data-collection-rule:0.6.1' = if (enablePrivateNetworking && enableMonitoring) {
name: take('avm.res.insights.data-collection-rule.${dataCollectionRulesResourceName}', 64)
params: {
name: dataCollectionRulesResourceName
tags: tags
enableTelemetry: enableTelemetry
location: dataCollectionRulesLocation
dataCollectionRuleProperties: {
kind: 'Windows'
dataSources: {
performanceCounters: [
{
streams: [
'Microsoft-Perf'
]
samplingFrequencyInSeconds: 60
counterSpecifiers: [
'\\Processor Information(_Total)\\% Processor Time'
'\\Processor Information(_Total)\\% Privileged Time'
'\\Processor Information(_Total)\\% User Time'
'\\Processor Information(_Total)\\Processor Frequency'
'\\System\\Processes'
'\\Process(_Total)\\Thread Count'
'\\Process(_Total)\\Handle Count'
'\\System\\System Up Time'
'\\System\\Context Switches/sec'
'\\System\\Processor Queue Length'
'\\Memory\\% Committed Bytes In Use'
'\\Memory\\Available Bytes'
'\\Memory\\Committed Bytes'
'\\Memory\\Cache Bytes'
'\\Memory\\Pool Paged Bytes'
'\\Memory\\Pool Nonpaged Bytes'
'\\Memory\\Pages/sec'
'\\Memory\\Page Faults/sec'
'\\Process(_Total)\\Working Set'
'\\Process(_Total)\\Working Set - Private'
'\\LogicalDisk(_Total)\\% Disk Time'
'\\LogicalDisk(_Total)\\% Disk Read Time'
'\\LogicalDisk(_Total)\\% Disk Write Time'
'\\LogicalDisk(_Total)\\% Idle Time'
'\\LogicalDisk(_Total)\\Disk Bytes/sec'
'\\LogicalDisk(_Total)\\Disk Read Bytes/sec'
'\\LogicalDisk(_Total)\\Disk Write Bytes/sec'
'\\LogicalDisk(_Total)\\Disk Transfers/sec'
'\\LogicalDisk(_Total)\\Disk Reads/sec'
'\\LogicalDisk(_Total)\\Disk Writes/sec'
'\\LogicalDisk(_Total)\\Avg. Disk sec/Transfer'
'\\LogicalDisk(_Total)\\Avg. Disk sec/Read'
'\\LogicalDisk(_Total)\\Avg. Disk sec/Write'
'\\LogicalDisk(_Total)\\Avg. Disk Queue Length'
'\\LogicalDisk(_Total)\\Avg. Disk Read Queue Length'
'\\LogicalDisk(_Total)\\Avg. Disk Write Queue Length'
'\\LogicalDisk(_Total)\\% Free Space'
'\\LogicalDisk(_Total)\\Free Megabytes'
'\\Network Interface(*)\\Bytes Total/sec'
'\\Network Interface(*)\\Bytes Sent/sec'
'\\Network Interface(*)\\Bytes Received/sec'
'\\Network Interface(*)\\Packets/sec'
'\\Network Interface(*)\\Packets Sent/sec'
'\\Network Interface(*)\\Packets Received/sec'
'\\Network Interface(*)\\Packets Outbound Errors'
'\\Network Interface(*)\\Packets Received Errors'
]
name: 'perfCounterDataSource60'
}
]
windowsEventLogs: [
{
name: 'SecurityAuditEvents'
streams: [
'Microsoft-WindowsEvent'
]
eventLogName: 'Security'
eventTypes: [
{
eventType: 'Audit Success'
}
{
eventType: 'Audit Failure'
}
]
xPathQueries: [
'Security!*[System[(EventID=4624 or EventID=4625)]]'
]
}
]
}
destinations: {
logAnalytics: [
{
workspaceResourceId: logAnalyticsWorkspaceResourceId
name: 'la--1264800308'
}
]
}
dataFlows: [
{
streams: [
'Microsoft-Perf'
]
destinations: [
'la--1264800308'
]
transformKql: 'source'
outputStream: 'Microsoft-Perf'
}
]
}
}
}
var proximityPlacementGroupResourceName = 'ppg-${solutionSuffix}'
module proximityPlacementGroup 'br/public:avm/res/compute/proximity-placement-group:0.4.0' = if (enablePrivateNetworking) {
name: take('avm.res.compute.proximity-placement-group.${proximityPlacementGroupResourceName}', 64)
params: {
name: proximityPlacementGroupResourceName
location: location
tags: tags
enableTelemetry: enableTelemetry
availabilityZone: virtualMachineAvailabilityZone
intent: { vmSizes: [virtualMachineSize] }
}
}
var virtualMachineResourceName = 'vm-${solutionSuffix}'
var virtualMachineAvailabilityZone = 1
module virtualMachine 'br/public:avm/res/compute/virtual-machine:0.17.0' = if (enablePrivateNetworking) {
name: take('avm.res.compute.virtual-machine.${virtualMachineResourceName}', 64)
params: {
name: virtualMachineResourceName
location: location
tags: tags
enableTelemetry: enableTelemetry
computerName: take(virtualMachineResourceName, 15)
osType: 'Windows'
vmSize: virtualMachineSize
adminUsername: virtualMachineAdminUsername ?? 'JumpboxAdminUser'
adminPassword: virtualMachineAdminPassword ?? 'JumpboxAdminP@ssw0rd1234!'
patchMode: 'AutomaticByPlatform'
bypassPlatformSafetyChecksOnUserSchedule: true
maintenanceConfigurationResourceId: maintenanceConfiguration!.outputs.resourceId
enableAutomaticUpdates: true
encryptionAtHost: true
availabilityZone: virtualMachineAvailabilityZone
proximityPlacementGroupResourceId: proximityPlacementGroup!.outputs.resourceId
imageReference: {
publisher: 'microsoft-dsvm'
offer: 'dsvm-win-2022'
sku: 'winserver-2022'
version: 'latest'
}
osDisk: {
name: 'osdisk-${virtualMachineResourceName}'
caching: 'ReadWrite'
createOption: 'FromImage'
deleteOption: 'Delete'
diskSizeGB: 128
managedDisk: { storageAccountType: 'Premium_LRS' }
}
nicConfigurations: [
{
name: 'nic-${virtualMachineResourceName}'
//networkSecurityGroupResourceId: virtualMachineConfiguration.?nicConfigurationConfiguration.networkSecurityGroupResourceId
//nicSuffix: 'nic-${virtualMachineResourceName}'
tags: tags
deleteOption: 'Delete'
diagnosticSettings: enableMonitoring //WAF aligned configuration for Monitoring
? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }]
: null
ipConfigurations: [
{
name: '${virtualMachineResourceName}-nic01-ipconfig01'
subnetResourceId: virtualNetwork!.outputs.administrationSubnetResourceId
diagnosticSettings: enableMonitoring //WAF aligned configuration for Monitoring
? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }]
: null
}
]
}
]
extensionAadJoinConfig: {
enabled: true
tags: tags
typeHandlerVersion: '1.0'
}
extensionAntiMalwareConfig: {
enabled: true
settings: {
AntimalwareEnabled: 'true'
Exclusions: {}
RealtimeProtectionEnabled: 'true'
ScheduledScanSettings: {
day: '7'
isEnabled: 'true'
scanType: 'Quick'
time: '120'
}
}
tags: tags
}
//WAF aligned configuration for Monitoring
extensionMonitoringAgentConfig: enableMonitoring
? {
dataCollectionRuleAssociations: [
{
dataCollectionRuleResourceId: windowsVmDataCollectionRules!.outputs.resourceId
name: 'send-${logAnalyticsWorkspaceName}'
}
]
enabled: true
tags: tags
}
: null
extensionNetworkWatcherAgentConfig: {
enabled: true
tags: tags
}
}
}
// ========== Private DNS Zones ========== //
var keyVaultPrivateDNSZone = 'privatelink.${toLower(environment().name) == 'azureusgovernment' ? 'vaultcore.usgovcloudapi.net' : 'vaultcore.azure.net'}'
var privateDnsZones = [
'privatelink.cognitiveservices.azure.com'
'privatelink.openai.azure.com'
'privatelink.services.ai.azure.com'
'privatelink.documents.azure.com'
'privatelink.blob.core.windows.net'
'privatelink.search.windows.net'
keyVaultPrivateDNSZone
]
// DNS Zone Index Constants
var dnsZoneIndex = {
cognitiveServices: 0
openAI: 1
aiServices: 2
cosmosDb: 3
blob: 4
search: 5
keyVault: 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 && (!useExistingAiFoundryAiProject || !contains(
aiRelatedDnsZoneIndices,
i
))) {
name: 'avm.res.network.private-dns-zone.${contains(zone, 'azurecontainerapps.io') ? 'containerappenv' : split(zone, '.')[1]}'
params: {
name: zone
tags: tags
enableTelemetry: enableTelemetry
virtualNetworkLinks: [
{
name: take('vnetlink-${virtualNetworkResourceName}-${split(zone, '.')[1]}', 80)
virtualNetworkResourceId: virtualNetwork!.outputs.resourceId
}
]
}
}
]
// ========== AI Foundry: AI Services ========== //
// WAF best practices for Open AI: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/azure-openai
var useExistingAiFoundryAiProject = !empty(existingAiFoundryAiProjectResourceId)
var aiFoundryAiServicesResourceGroupName = useExistingAiFoundryAiProject
? split(existingAiFoundryAiProjectResourceId, '/')[4]
: resourceGroup().name
var aiFoundryAiServicesSubscriptionId = useExistingAiFoundryAiProject
? split(existingAiFoundryAiProjectResourceId, '/')[2]
: subscription().subscriptionId
var aiFoundryAiServicesResourceName = useExistingAiFoundryAiProject
? split(existingAiFoundryAiProjectResourceId, '/')[8]
: 'aif-${solutionSuffix}'
var aiFoundryAiProjectResourceName = useExistingAiFoundryAiProject
? split(existingAiFoundryAiProjectResourceId, '/')[10]
: 'proj-${solutionSuffix}' // AI Project resource id: /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.CognitiveServices/accounts/<ai-services-name>/projects/<project-name>
var aiFoundryAiServicesModelDeployment = {
format: 'OpenAI'
name: gptModelName
version: gptModelVersion
sku: {
name: gptModelDeploymentType
capacity: gptModelCapacity
}
raiPolicyName: 'Microsoft.Default'
}
var aiFoundryAiServices4_1ModelDeployment = {
format: 'OpenAI'
name: gpt4_1ModelName
version: gpt4_1ModelVersion
sku: {
name: gpt4_1ModelDeploymentType
capacity: gpt4_1ModelCapacity
}
raiPolicyName: 'Microsoft.Default'
}
var aiFoundryAiServicesReasoningModelDeployment = {
format: 'OpenAI'
name: gptReasoningModelName
version: gptReasoningModelVersion
sku: {
name: gptReasoningModelDeploymentType
capacity: gptReasoningModelCapacity
}
raiPolicyName: 'Microsoft.Default'
}
var aiFoundryAiProjectDescription = 'AI Foundry Project'
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: existingAiFoundryAiServices.name
deployments: [
{
name: aiFoundryAiServicesModelDeployment.name
model: {
format: aiFoundryAiServicesModelDeployment.format
name: aiFoundryAiServicesModelDeployment.name
version: aiFoundryAiServicesModelDeployment.version
}
raiPolicyName: aiFoundryAiServicesModelDeployment.raiPolicyName
sku: {
name: aiFoundryAiServicesModelDeployment.sku.name
capacity: aiFoundryAiServicesModelDeployment.sku.capacity
}
}
{
name: aiFoundryAiServices4_1ModelDeployment.name
model: {
format: aiFoundryAiServices4_1ModelDeployment.format
name: aiFoundryAiServices4_1ModelDeployment.name
version: aiFoundryAiServices4_1ModelDeployment.version
}
raiPolicyName: aiFoundryAiServices4_1ModelDeployment.raiPolicyName
sku: {
name: aiFoundryAiServices4_1ModelDeployment.sku.name
capacity: aiFoundryAiServices4_1ModelDeployment.sku.capacity
}
}
{
name: aiFoundryAiServicesReasoningModelDeployment.name
model: {
format: aiFoundryAiServicesReasoningModelDeployment.format
name: aiFoundryAiServicesReasoningModelDeployment.name
version: aiFoundryAiServicesReasoningModelDeployment.version
}
raiPolicyName: aiFoundryAiServicesReasoningModelDeployment.raiPolicyName
sku: {
name: aiFoundryAiServicesReasoningModelDeployment.sku.name
capacity: aiFoundryAiServicesReasoningModelDeployment.sku.capacity
}
}
]
roleAssignments: [
{
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Azure AI 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'
}
]
}
}
module aiFoundryAiServices 'br:mcr.microsoft.com/bicep/avm/res/cognitive-services/account:0.13.2' = if (!useExistingAiFoundryAiProject) {
name: take('avm.res.cognitive-services.account.${aiFoundryAiServicesResourceName}', 64)
params: {
name: aiFoundryAiServicesResourceName
location: azureAiServiceLocation
tags: tags
sku: 'S0'
kind: 'AIServices'
disableLocalAuth: true
allowProjectManagement: true
customSubDomainName: aiFoundryAiServicesResourceName
apiProperties: {
//staticsEnabled: false
}
deployments: [
{
name: aiFoundryAiServicesModelDeployment.name
model: {
format: aiFoundryAiServicesModelDeployment.format
name: aiFoundryAiServicesModelDeployment.name
version: aiFoundryAiServicesModelDeployment.version
}
raiPolicyName: aiFoundryAiServicesModelDeployment.raiPolicyName
sku: {
name: aiFoundryAiServicesModelDeployment.sku.name
capacity: aiFoundryAiServicesModelDeployment.sku.capacity
}
}
{
name: aiFoundryAiServices4_1ModelDeployment.name
model: {
format: aiFoundryAiServices4_1ModelDeployment.format
name: aiFoundryAiServices4_1ModelDeployment.name
version: aiFoundryAiServices4_1ModelDeployment.version
}
raiPolicyName: aiFoundryAiServices4_1ModelDeployment.raiPolicyName
sku: {
name: aiFoundryAiServices4_1ModelDeployment.sku.name
capacity: aiFoundryAiServices4_1ModelDeployment.sku.capacity
}
}
{
name: aiFoundryAiServicesReasoningModelDeployment.name
model: {
format: aiFoundryAiServicesReasoningModelDeployment.format
name: aiFoundryAiServicesReasoningModelDeployment.name
version: aiFoundryAiServicesReasoningModelDeployment.version
}
raiPolicyName: aiFoundryAiServicesReasoningModelDeployment.raiPolicyName
sku: {
name: aiFoundryAiServicesReasoningModelDeployment.sku.name
capacity: aiFoundryAiServicesReasoningModelDeployment.sku.capacity
}
}
]
networkAcls: {
defaultAction: 'Allow'
virtualNetworkRules: []
ipRules: []
}
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: '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' // Azure AI User
principalId: deployingUserPrincipalId
principalType: deployerPrincipalType
}
{
roleDefinitionIdOrName: '64702f94-c441-49e6-a78b-ef80e0188fee' // Azure AI Developer
principalId: deployingUserPrincipalId
principalType: deployerPrincipalType
}
]
// WAF aligned configuration for Monitoring
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
privateEndpoints: (enablePrivateNetworking)
? ([
{
name: 'pep-${aiFoundryAiServicesResourceName}'
customNetworkInterfaceName: 'nic-${aiFoundryAiServicesResourceName}'
subnetResourceId: virtualNetwork!.outputs.backendSubnetResourceId
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
}
]
}
}
])
: []
}
}
resource existingAiFoundryAiServicesProject 'Microsoft.CognitiveServices/accounts/projects@2025-06-01' existing = if (useExistingAiFoundryAiProject) {
name: aiFoundryAiProjectResourceName
parent: existingAiFoundryAiServices
}