-
Notifications
You must be signed in to change notification settings - Fork 126
/
main.bicep
860 lines (768 loc) · 23.4 KB
/
main.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
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
@description('List of Mock webapp names used to simulate OpenAI behavior.')
param mockWebApps array = []
@description('The name of the OpenAI mock backend pool')
param mockBackendPoolName string = 'openai-backend-pool'
@description('The description of the OpenAI mock backend pool')
param mockBackendPoolDescription string = 'Load balancer for multiple OpenAI Mocking endpoints'
@description('List of OpenAI resources to create. Add pairs of name and location.')
param openAIConfig array = []
@description('Deployment Name')
param openAIDeploymentName string
@description('Azure OpenAI Sku')
@allowed([
'S0'
])
param openAISku string = 'S0'
@description('Model Name')
param openAIModelName string
@description('Model Version')
param openAIModelVersion string
@description('Model Capacity')
param openAIModelCapacity int = 20
@description('The name of the API Management resource')
param apimResourceName string
@description('Location for the APIM resource')
param apimResourceLocation string = resourceGroup().location
@description('The pricing tier of this API Management service')
@allowed([
'Consumption'
'Developer'
'Basic'
'Basicv2'
'Standard'
'Standardv2'
'Premium'
])
param apimSku string = 'Consumption'
@description('The instance size of this API Management service.')
@allowed([
0
1
2
])
param apimSkuCount int = 1
@description('The email address of the owner of the service')
param apimPublisherEmail string = '[email protected]'
@description('The name of the owner of the service')
param apimPublisherName string = 'Microsoft'
@description('The name of the APIM API for OpenAI API')
param openAIAPIName string = 'openai'
@description('The relative path of the APIM API for OpenAI API')
param openAIAPIPath string = 'openai'
@description('The display name of the APIM API for OpenAI API')
param openAIAPIDisplayName string = 'OpenAI'
@description('The description of the APIM API for OpenAI API')
param openAIAPIDescription string = 'Azure OpenAI API inferencing API'
@description('Full URL for the OpenAI API spec')
param openAIAPISpecURL string = 'https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/stable/2024-02-01/inference.json'
@description('The name of the APIM Subscription for OpenAI API')
param openAISubscriptionName string = 'openai-subscription'
@description('The description of the APIM Subscription for OpenAI API')
param openAISubscriptionDescription string = 'OpenAI Subscription'
@description('The name of the OpenAI backend pool')
param openAIBackendPoolName string = 'openai-backend-pool'
@description('The description of the OpenAI backend pool')
param openAIBackendPoolDescription string = 'Load balancer for multiple OpenAI endpoints'
// buult-in logging: additions BEGIN
@description('Name of the Log Analytics resource')
param logAnalyticsName string = 'workspace'
@description('Location of the Log Analytics resource')
param logAnalyticsLocation string = resourceGroup().location
@description('Name of the Application Insights resource')
param applicationInsightsName string = 'insights'
@description('Location of the Application Insights resource')
param applicationInsightsLocation string = resourceGroup().location
@description('Name of the APIM Logger')
param apimLoggerName string = 'apim-logger'
@description('Description of the APIM Logger')
param apimLoggerDescription string = 'APIM Logger for OpenAI API'
@description('Number of bytes to log for API diagnostics')
param apiDiagnosticsLogBytes int = 8192
// built-in logging: additions END
// prompt flow: additions BEGIN
@description('The AI Studio Hub Resource name')
param aiStudioHubName string
@description('The AI Studio Hub Resource location')
param aiStudioHubLocation string = resourceGroup().location
@description('The SKU name to use for the AI Studio Hub Resource')
param aiStudioSKUName string = 'Basic'
@description('The SKU tier to use for the AI Studio Hub Resource')
@allowed(['Basic', 'Free', 'Premium', 'Standard'])
param aiStudioSKUTier string = 'Basic'
@description('The name of the AI Studio Hub Project')
param aiStudioProjectName string
@description('The storage account ID to use for the AI Studio Hub Resource')
param storageAccountName string = 'storage'
@description('The storage account location')
param storageAccountLocation string = resourceGroup().location
@description('The key vault ID to use for the AI Studio Hub Resource')
param keyVaultName string = 'akv'
@description('The key vault location')
param keyVaultLocation string = resourceGroup().location
@description('The container registry ID to use for the AI Studio Hub Resource')
param containerRegistryName string = 'acr'
@description('The container registry location')
param containerRegistryLocation string = resourceGroup().location
@description('The name of the Container App image')
param flowName string
@description('The prompt flow API Name')
param promptFlowAPIName string = flowName
@description('The prompt flow API Description')
param promptFlowAPIDescription string = 'Prompt flow API'
@description('The prompt flow API Display Name')
param promptFlowDisplayName string = flowName
@description('The prompt flow API Path')
param promptFlowAPIPath string = flowName
@description('The name of the Container App Environment')
param containerAppEnvName string
@description('The location of the Container App Environment')
param containerAppEnvLocation string = resourceGroup().location
@description('The name of the Container App')
param containerAppName string
// prompt flow: additions END
var resourceSuffix = uniqueString(subscription().id, resourceGroup().id)
resource cognitiveServices 'Microsoft.CognitiveServices/accounts@2021-10-01' = [for config in openAIConfig: if(length(openAIConfig) > 0) {
name: '${config.name}-${resourceSuffix}'
location: config.location
sku: {
name: openAISku
}
kind: 'OpenAI'
properties: {
apiProperties: {
statisticsEnabled: false
}
customSubDomainName: toLower('${config.name}-${resourceSuffix}')
}
}]
resource deployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = [for (config, i) in openAIConfig: if(length(openAIConfig) > 0) {
name: openAIDeploymentName
parent: cognitiveServices[i]
properties: {
model: {
format: 'OpenAI'
name: openAIModelName
version: openAIModelVersion
}
}
sku: {
name: 'Standard'
capacity: openAIModelCapacity
}
}]
resource apimService 'Microsoft.ApiManagement/service@2023-05-01-preview' = {
name: '${apimResourceName}-${resourceSuffix}'
location: apimResourceLocation
sku: {
name: apimSku
capacity: (apimSku == 'Consumption') ? 0 : ((apimSku == 'Developer') ? 1 : apimSkuCount)
}
properties: {
publisherEmail: apimPublisherEmail
publisherName: apimPublisherName
}
identity: {
type: 'SystemAssigned'
}
}
var roleDefinitionID = resourceId('Microsoft.Authorization/roleDefinitions', '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd')
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = [for (config, i) in openAIConfig: if(length(openAIConfig) > 0) {
scope: cognitiveServices[i]
name: guid(subscription().id, resourceGroup().id, config.name, roleDefinitionID)
properties: {
roleDefinitionId: roleDefinitionID
principalId: apimService.identity.principalId
principalType: 'ServicePrincipal'
}
}]
resource api 'Microsoft.ApiManagement/service/apis@2023-05-01-preview' = {
name: openAIAPIName
parent: apimService
properties: {
apiType: 'http'
description: openAIAPIDescription
displayName: openAIAPIDisplayName
format: 'openapi-link'
path: openAIAPIPath
protocols: [
'https'
]
subscriptionKeyParameterNames: {
header: 'api-key'
query: 'api-key'
}
subscriptionRequired: true
type: 'http'
value: openAIAPISpecURL
}
}
resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-12-01-preview' = {
name: 'policy'
parent: api
properties: {
format: 'rawxml'
value: loadTextContent('policy.xml')
}
}
resource backendOpenAI 'Microsoft.ApiManagement/service/backends@2023-05-01-preview' = [for (config, i) in openAIConfig: if(length(openAIConfig) > 0) {
name: config.name
parent: apimService
properties: {
description: 'backend description'
url: '${cognitiveServices[i].properties.endpoint}/openai'
protocol: 'http'
circuitBreaker: {
rules: [
{
failureCondition: {
count: 3
errorReasons: [
'Server errors'
]
interval: 'PT5M'
statusCodeRanges: [
{
min: 429
max: 429
}
]
}
name: 'openAIBreakerRule'
tripDuration: 'PT1M'
}
]
}
}
}]
resource backendMock 'Microsoft.ApiManagement/service/backends@2023-05-01-preview' = [for (mock, i) in mockWebApps: if(length(openAIConfig) == 0 && length(mockWebApps) > 0) {
name: mock.name
parent: apimService
properties: {
description: 'backend description'
url: '${mock.endpoint}/openai'
protocol: 'http'
circuitBreaker: {
rules: [
{
failureCondition: {
count: 3
errorReasons: [
'Server errors'
]
interval: 'PT5M'
statusCodeRanges: [
{
min: 429
max: 429
}
]
}
name: 'mockBreakerRule'
tripDuration: 'PT1M'
}
]
}
}
}]
resource backendPoolOpenAI 'Microsoft.ApiManagement/service/backends@2023-05-01-preview' = if(length(openAIConfig) > 1) {
name: openAIBackendPoolName
parent: apimService
properties: {
description: openAIBackendPoolDescription
type: 'Pool'
// protocol: 'http' // the protocol is not needed in the Pool type
// url: '${cognitiveServices[0].properties.endpoint}/openai' // the url is not needed in the Pool type
pool: {
services: [for (config, i) in openAIConfig: {
id: '/backends/${backendOpenAI[i].name}'
}
]
}
}
}
resource backendPoolMock 'Microsoft.ApiManagement/service/backends@2023-05-01-preview' = if(length(openAIConfig) == 0 && length(mockWebApps) > 1) {
name: mockBackendPoolName
parent: apimService
properties: {
description: mockBackendPoolDescription
type: 'Pool'
// protocol: 'http' // the protocol is not needed in the Pool type
// url: '${mockWebApps[0].endpoint}/openai' // the url is not needed in the Pool type
pool: {
services: [for (webApp, i) in mockWebApps: {
id: '/backends/${backendMock[i].name}'
}
]
}
}
}
resource apimSubscription 'Microsoft.ApiManagement/service/subscriptions@2023-05-01-preview' = {
name: openAISubscriptionName
parent: apimService
properties: {
allowTracing: true
displayName: openAISubscriptionDescription
scope: '/apis'
state: 'active'
}
}
// buult-in logging: additions BEGIN
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
name: '${logAnalyticsName}-${resourceSuffix}'
location: logAnalyticsLocation
properties: any({
retentionInDays: 30
features: {
searchVersion: 1
}
sku: {
name: 'PerGB2018'
}
})
}
/*
resource diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = [for (config, i) in openAIConfig: if(length(openAIConfig) > 0) {
name: '${cognitiveServices[i].name}-diagnostics'
scope: cognitiveServices[i]
properties: {
workspaceId: logAnalytics.id
logs: []
metrics: [
{
category: 'AllMetrics'
enabled: true
}
]
}
}]
*/
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: '${applicationInsightsName}-${resourceSuffix}'
location: applicationInsightsLocation
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalytics.id
CustomMetricsOptedInType: 'WithDimensions'
}
}
resource apimLogger 'Microsoft.ApiManagement/service/loggers@2021-12-01-preview' = {
name: apimLoggerName
parent: apimService
properties: {
credentials: {
instrumentationKey: applicationInsights.properties.InstrumentationKey
}
description: apimLoggerDescription
isBuffered: false
loggerType: 'applicationInsights'
resourceId: applicationInsights.id
}
}
var logSettings = {
headers: [ 'Content-type', 'User-agent', 'x-ms-region', 'x-ratelimit-remaining-tokens' , 'x-ratelimit-remaining-requests' ]
body: { bytes: apiDiagnosticsLogBytes }
}
resource apiDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2022-08-01' = if (!empty(apimLogger.name)) {
name: 'applicationinsights'
parent: api
properties: {
alwaysLog: 'allErrors'
httpCorrelationProtocol: 'W3C'
logClientIp: true
loggerId: apimLogger.id
metrics: true
verbosity: 'verbose'
sampling: {
samplingType: 'fixed'
percentage: 100
}
frontend: {
request: logSettings
response: logSettings
}
backend: {
request: logSettings
response: logSettings
}
}
}
output applicationInsightsAppId string = applicationInsights.properties.AppId
output logAnalyticsWorkspaceId string = logAnalytics.properties.customerId
// buult-in logging: additions END
// prompt flow: additions BEGIN
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
name: '${keyVaultName}-${resourceSuffix}'
location: keyVaultLocation
properties: {
tenantId: subscription().tenantId
sku: { family: 'A', name: 'standard' }
accessPolicies: []
}
}
resource keyVaultAccessPolicies 'Microsoft.KeyVault/vaults/accessPolicies@2022-07-01' = {
parent: keyVault
name: 'add'
properties: {
accessPolicies: [ {
objectId: hub.identity.principalId
tenantId: subscription().tenantId
permissions: { secrets: [ 'get', 'list' ] }
} ]
}
}
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-11-01-preview' = {
name: '${containerRegistryName}${resourceSuffix}'
location: containerRegistryLocation
sku: {
name: 'Basic'
}
properties: {
adminUserEnabled: true
anonymousPullEnabled: false
dataEndpointEnabled: false
encryption: {
status: 'disabled'
}
metadataSearch: 'Disabled'
networkRuleBypassOptions: 'AzureServices'
policies:{
quarantinePolicy: {
status: 'disabled'
}
trustPolicy: {
type: 'Notary'
status: 'disabled'
}
retentionPolicy: {
days: 7
status: 'disabled'
}
exportPolicy: {
status: 'enabled'
}
azureADAuthenticationAsArmPolicy: {
status: 'enabled'
}
softDeletePolicy: {
retentionDays: 7
status: 'disabled'
}
}
publicNetworkAccess: 'Enabled'
zoneRedundancy: 'Disabled'
}
}
resource storage 'Microsoft.Storage/storageAccounts@2023-01-01' = {
name: '${storageAccountName}${resourceSuffix}'
location: storageAccountLocation
kind: 'StorageV2'
sku: { name: 'Standard_LRS' }
properties: {
accessTier: 'Hot'
allowBlobPublicAccess: true
allowCrossTenantReplication: true
allowSharedKeyAccess: true
defaultToOAuthAuthentication: false
dnsEndpointType: 'Standard'
minimumTlsVersion: 'TLS1_2'
networkAcls: {
bypass: 'AzureServices'
defaultAction: 'Allow'
}
publicNetworkAccess: 'Enabled'
supportsHttpsTrafficOnly: true
}
resource blobServices 'blobServices' = {
name: 'default'
properties: {
cors: {
corsRules: [
{
allowedOrigins: [
'https://mlworkspace.azure.ai'
'https://ml.azure.com'
'https://*.ml.azure.com'
'https://ai.azure.com'
'https://*.ai.azure.com'
'https://mlworkspacecanary.azure.ai'
'https://mlworkspace.azureml-test.net'
]
allowedMethods: [
'GET'
'HEAD'
'POST'
'PUT'
'DELETE'
'OPTIONS'
'PATCH'
]
maxAgeInSeconds: 1800
exposedHeaders: [
'*'
]
allowedHeaders: [
'*'
]
}
]
}
deleteRetentionPolicy: {
allowPermanentDelete: false
enabled: false
}
}
resource container 'containers' = {
name: 'default'
properties: {
publicAccess: 'None'
}
}
}
resource fileServices 'fileServices' = {
name: 'default'
properties: {
cors: {
corsRules: [
{
allowedOrigins: [
'https://mlworkspace.azure.ai'
'https://ml.azure.com'
'https://*.ml.azure.com'
'https://ai.azure.com'
'https://*.ai.azure.com'
'https://mlworkspacecanary.azure.ai'
'https://mlworkspace.azureml-test.net'
]
allowedMethods: [
'GET'
'HEAD'
'POST'
'PUT'
'DELETE'
'OPTIONS'
'PATCH'
]
maxAgeInSeconds: 1800
exposedHeaders: [
'*'
]
allowedHeaders: [
'*'
]
}
]
}
shareDeleteRetentionPolicy: {
enabled: true
days: 7
}
}
}
resource queueServices 'queueServices' = {
name: 'default'
properties: {
}
resource queue 'queues' = {
name: 'default'
properties: {
metadata: {}
}
}
}
resource tableServices 'tableServices' = {
name: 'default'
properties: {}
}
}
resource hub 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' = {
name: '${aiStudioHubName}-${resourceSuffix}'
location: aiStudioHubLocation
sku: {
name: aiStudioSKUName
tier: aiStudioSKUTier
}
kind: 'Hub'
identity: {
type: 'SystemAssigned'
}
properties: {
friendlyName: aiStudioHubName
storageAccount: storage.id
keyVault: keyVault.id
applicationInsights: applicationInsights.id
containerRegistry: containerRegistry.id
hbiWorkspace: false
managedNetwork: {
isolationMode: 'Disabled'
}
v1LegacyMode: false
publicNetworkAccess: 'Enabled'
discoveryUrl: 'https://${aiStudioHubLocation}.api.azureml.ms/discovery'
}
resource openAiConnection 'connections@2024-04-01-preview' = {
name: 'open_ai_connection'
properties: {
category: 'AzureOpenAI'
authType: 'ApiKey'
isSharedToAll: true
target: apimService.properties.gatewayUrl
enforceAccessToDefaultSecretStores: true
metadata: {
ApiVersion: '2024-02-01'
ApiType: 'azure'
}
credentials: {
key: apimSubscription.listSecrets().primaryKey
}
}
}
}
resource project 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' = {
name: '${aiStudioProjectName}-${resourceSuffix}'
location: aiStudioHubLocation
sku: {
name: 'Basic'
tier: 'Basic'
}
kind: 'Project'
identity: {
type: 'SystemAssigned'
}
properties: {
friendlyName: aiStudioProjectName
hbiWorkspace: false
v1LegacyMode: false
publicNetworkAccess: 'Enabled'
discoveryUrl: 'https://${aiStudioHubLocation}.api.azureml.ms/discovery'
hubResourceId: hub.id
}
}
resource promptFlowAPI 'Microsoft.ApiManagement/service/apis@2023-05-01-preview' = {
name: promptFlowAPIName
parent: apimService
properties: {
apiType: 'http'
description: promptFlowAPIDescription
displayName: promptFlowDisplayName
format: 'openapi+json'
path: promptFlowAPIPath
serviceUrl: 'https://${containerApp.properties.configuration.ingress.fqdn}/'
protocols: [
'https'
]
subscriptionKeyParameterNames: {
header: 'api-key'
query: 'api-key'
}
subscriptionRequired: true
type: 'http'
value: loadJsonContent('basic-chat/openapi.json')
}
}
resource promptFlowAPIDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2022-08-01' = if (!empty(apimLogger.name)) {
name: 'applicationinsights'
parent: promptFlowAPI
properties: {
alwaysLog: 'allErrors'
httpCorrelationProtocol: 'W3C'
logClientIp: true
loggerId: apimLogger.id
metrics: true
verbosity: 'verbose'
sampling: {
samplingType: 'fixed'
percentage: 100
}
frontend: {
request: logSettings
response: logSettings
}
backend: {
request: logSettings
response: logSettings
}
}
}
resource containerAppEnv 'Microsoft.App/managedEnvironments@2023-11-02-preview' = {
name: '${containerAppEnvName}-${resourceSuffix}'
location: containerAppEnvLocation
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalytics.properties.customerId
sharedKey: logAnalytics.listKeys().primarySharedKey
}
}
}
}
resource containerAppUAI 'Microsoft.ManagedIdentity/userAssignedIdentities@2022-01-31-preview' = {
name: '${containerAppName}-mi-${resourceSuffix}'
location: containerAppEnvLocation
}
var acrPullRole = resourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')
@description('This allows the managed identity of the container app to access the registry, note scope is applied to the wider ResourceGroup not the ACR')
resource containerAppUAIRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(resourceGroup().id, containerAppUAI.id, acrPullRole)
properties: {
roleDefinitionId: acrPullRole
principalId: containerAppUAI.properties.principalId
principalType: 'ServicePrincipal'
}
}
resource containerApp 'Microsoft.App/containerApps@2023-11-02-preview' = {
name: '${containerAppName}-${resourceSuffix}'
location: containerAppEnvLocation
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${containerAppUAI.id}': {}
}
}
properties: {
managedEnvironmentId: containerAppEnv.id
configuration: {
ingress: {
external: true
targetPort: 8080
allowInsecure: false
}
}
template: {
containers: [
{
name: '${containerAppName}-${resourceSuffix}'
image: 'docker.io/jfxs/hello-world:latest'
env: [
{
name: 'OPEN_AI_CONNECTION_API_KEY'
value: apimSubscription.listSecrets().primaryKey
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: applicationInsights.properties.ConnectionString
}
]
resources: {
cpu: json('.5')
memory: '1Gi'
}
}
]
scale: {
minReplicas: 1
maxReplicas: 3
}
}
}
}
output containerAppResourceName string = containerApp.name
output containerAppFQDN string = containerApp.properties.configuration.ingress.fqdn
output projectName string = project.name
output projectId string = project.id
// prompt flow: additions END
output apimServiceId string = apimService.id
output apimResourceGatewayURL string = apimService.properties.gatewayUrl
#disable-next-line outputs-should-not-contain-secrets
output apimSubscriptionKey string = apimSubscription.listSecrets().primaryKey