@@ -12,6 +12,7 @@ param embeddingModel string
1212param embeddingDeploymentCapacity int
1313param managedIdentityObjectId string
1414param existingLogAnalyticsWorkspaceId string = ''
15+ param azureExistingAIProjectResourceId string = ''
1516
1617var abbrs = loadJsonContent ('./abbreviations.json' )
1718var aiServicesName = '${abbrs .ai .aiServices }${solutionName }'
@@ -21,7 +22,7 @@ var workspaceName = '${abbrs.managementGovernance.logAnalyticsWorkspace}${soluti
2122var applicationInsightsName = '${abbrs .managementGovernance .applicationInsights }${solutionName }'
2223var keyvaultName = '${abbrs .security .keyVault }${solutionName }'
2324var location = solutionLocation //'eastus2'
24- var aiProjectName = '${abbrs .ai .aiHubProject }${solutionName }'
25+ var aiProjectName = '${abbrs .ai .aiFoundryProject }${solutionName }'
2526var aiSearchName = '${abbrs .ai .aiSearch }${solutionName }'
2627
2728var aiModelDeployments = [
@@ -51,6 +52,13 @@ var existingLawSubscription = useExisting ? split(existingLogAnalyticsWorkspaceI
5152var existingLawResourceGroup = useExisting ? split (existingLogAnalyticsWorkspaceId , '/' )[4 ] : ''
5253var existingLawName = useExisting ? split (existingLogAnalyticsWorkspaceId , '/' )[8 ] : ''
5354
55+ var existingOpenAIEndpoint = !empty (azureExistingAIProjectResourceId ) ? format ('https://{0}.openai.azure.com/' , split (azureExistingAIProjectResourceId , '/' )[8 ]) : ''
56+ var existingProjEndpoint = !empty (azureExistingAIProjectResourceId ) ? format ('https://{0}.services.ai.azure.com/api/projects/{1}' , split (azureExistingAIProjectResourceId , '/' )[8 ], split (azureExistingAIProjectResourceId , '/' )[10 ]) : ''
57+ var existingAIServicesName = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[8 ] : ''
58+ var existingAIProjectName = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[10 ] : ''
59+ var existingAIServiceSubscription = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[2 ] : ''
60+ var existingAIServiceResourceGroup = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[4 ] : ''
61+
5462resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
5563 name : keyVaultName
5664}
@@ -84,7 +92,7 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
8492 }
8593}
8694
87- resource aiServices 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' = {
95+ resource aiServices 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' = if ( empty ( azureExistingAIProjectResourceId )) {
8896 name : aiServicesName
8997 location : location
9098 sku : {
@@ -131,7 +139,7 @@ resource aiServices_CU 'Microsoft.CognitiveServices/accounts@2025-04-01-preview'
131139}
132140
133141@batchSize (1 )
134- resource aiServicesDeployments 'Microsoft.CognitiveServices/accounts/deployments@2025-04-01-preview' = [for aiModeldeployment in aiModelDeployments : {
142+ resource aiServicesDeployments 'Microsoft.CognitiveServices/accounts/deployments@2025-04-01-preview' = [for aiModeldeployment in aiModelDeployments : if ( empty ( azureExistingAIProjectResourceId )) {
135143 parent : aiServices //aiServices_m
136144 name : aiModeldeployment .name
137145 properties : {
@@ -172,7 +180,7 @@ resource aiSearch 'Microsoft.Search/searchServices@2024-06-01-preview' = {
172180 }
173181}
174182
175- resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' = {
183+ resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' = if ( empty ( azureExistingAIProjectResourceId )) {
176184 parent : aiServices
177185 name : aiProjectName
178186 location : solutionLocation
@@ -183,14 +191,13 @@ resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-pre
183191 properties : {}
184192}
185193
186- resource project_connection_azureai_search 'Microsoft.CognitiveServices/accounts/projects/connections@2025-04-01-preview' = {
187- name : 'myVectorStoreProjectConnectionName'
194+ resource aiproject_aisearch_connection_new 'Microsoft.CognitiveServices/accounts/projects/connections@2025-04-01-preview' = if ( empty ( azureExistingAIProjectResourceId )) {
195+ name : 'myVectorStoreProjectConnectionName-${ solutionName } '
188196 parent : aiProject
189197 properties : {
190198 category : 'CognitiveSearch'
191199 target : 'https://${aiSearchName }.search.windows.net'
192200 authType : 'AAD'
193- //useWorkspaceManagedIdentity: false
194201 isSharedToAll : true
195202 metadata : {
196203 ApiType : 'Azure'
@@ -200,6 +207,19 @@ resource project_connection_azureai_search 'Microsoft.CognitiveServices/accounts
200207 }
201208}
202209
210+ module existing_AIProject_SearchConnectionModule 'deploy_aifp_aisearch_connection.bicep' = if (!empty (azureExistingAIProjectResourceId )) {
211+ name : 'aiProjectSearchConnectionDeployment'
212+ scope : resourceGroup (existingAIServiceSubscription , existingAIServiceResourceGroup )
213+ params : {
214+ existingAIProjectName : existingAIProjectName
215+ existingAIServicesName : existingAIServicesName
216+ aiSearchName : aiSearchName
217+ aiSearchResourceId : aiSearch .id
218+ aiSearchLocation : aiSearch .location
219+ solutionName : solutionName
220+ }
221+ }
222+
203223resource aiUser 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
204224 name : '53ca6127-db72-4b80-b1b0-d745d6d5456d'
205225}
@@ -213,6 +233,17 @@ resource aiUserAccessFoundry 'Microsoft.Authorization/roleAssignments@2022-04-01
213233 }
214234}
215235
236+ module assignAiUserRoleToManagedIdentity 'deploy_foundry_role_assignment.bicep' = if (!empty (azureExistingAIProjectResourceId )) {
237+ name : 'assignAiUserRoleToManagedIdentity'
238+ scope : resourceGroup (existingAIServiceSubscription , existingAIServiceResourceGroup )
239+ params : {
240+ roleDefinitionId : aiUser .id
241+ roleAssignmentName : guid (managedIdentityObjectId , aiServices .id , aiUser .id )
242+ aiServicesName : !empty (azureExistingAIProjectResourceId ) ? existingAIServicesName : aiServicesName
243+ userassignedIdentityId : managedIdentityObjectId
244+ }
245+ }
246+
216247resource tenantIdEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
217248 parent : keyVault
218249 name : 'TENANT-ID'
@@ -237,14 +268,6 @@ resource azureOpenAIInferenceKey 'Microsoft.KeyVault/vaults/secrets@2021-11-01-p
237268 }
238269}
239270
240- resource azureOpenAIApiKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
241- parent : keyVault
242- name : 'AZURE-OPENAI-KEY'
243- properties : {
244- value : aiServices .listKeys ().key1 //aiServices_m.listKeys().key1
245- }
246- }
247-
248271resource azureOpenAIDeploymentModel 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
249272 parent : keyVault
250273 name : 'AZURE-OPENAI-DEPLOYMENT-MODEL'
@@ -265,15 +288,7 @@ resource azureOpenAIEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-
265288 parent : keyVault
266289 name : 'AZURE-OPENAI-ENDPOINT'
267290 properties : {
268- value : aiServices .properties .endpoints ['OpenAI Language Model Instance API' ] //aiServices_m.properties.endpoint
269- }
270- }
271-
272- resource azureAIProjectConnectionStringEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
273- parent : keyVault
274- name : 'AZURE-AI-PROJECT-CONN-STRING'
275- properties : {
276- value : '${aiProjectName };${subscription ().subscriptionId };${resourceGroup ().name };${aiProject .name }'
291+ value : !empty (existingOpenAIEndpoint ) ? existingOpenAIEndpoint : aiServices .properties .endpoints ['OpenAI Language Model Instance API' ] //aiServices_m.properties.endpoint
277292 }
278293}
279294
@@ -337,15 +352,7 @@ resource cogServiceEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-p
337352 parent : keyVault
338353 name : 'COG-SERVICES-ENDPOINT'
339354 properties : {
340- value : aiServices .properties .endpoint
341- }
342- }
343-
344- resource cogServiceKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
345- parent : keyVault
346- name : 'COG-SERVICES-KEY'
347- properties : {
348- value : aiServices .listKeys ().key1
355+ value : !empty (existingOpenAIEndpoint ) ? existingOpenAIEndpoint : aiServices .properties .endpoints ['OpenAI Language Model Instance API' ]
349356 }
350357}
351358
@@ -383,22 +390,19 @@ resource azureLocatioEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview
383390
384391output keyvaultName string = keyvaultName
385392output keyvaultId string = keyVault .id
386- output aiServicesTarget string = aiServices .properties .endpoints ['OpenAI Language Model Instance API' ] //aiServices_m.properties.endpoint
387- output aiServicesName string = aiServicesName //aiServicesName_m
388- output aiServicesId string = aiServices .id //aiServices_m.id
393+ output aiServicesTarget string = !empty (existingOpenAIEndpoint ) ? existingOpenAIEndpoint : aiServices .properties .endpoints ['OpenAI Language Model Instance API' ] //aiServices_m.properties.endpoint
394+ output aiServicesName string = !empty (existingAIServicesName ) ? existingAIServicesName : aiServicesName
389395
390396output aiSearchName string = aiSearchName
391397output aiSearchId string = aiSearch .id
392398output aiSearchTarget string = 'https://${aiSearch .name }.search.windows.net'
393399output aiSearchService string = aiSearch .name
394- output aiProjectName string = aiProject .name
400+ output aiProjectName string = ! empty ( existingAIProjectName ) ? existingAIProjectName : aiProject .name
395401
396402output applicationInsightsId string = applicationInsights .id
397403output logAnalyticsWorkspaceResourceName string = useExisting ? existingLogAnalyticsWorkspace .name : logAnalytics .name
398404output logAnalyticsWorkspaceResourceGroup string = useExisting ? existingLawResourceGroup : resourceGroup ().name
399405output logAnalyticsWorkspaceSubscription string = useExisting ? existingLawSubscription : subscription ().subscriptionId
400406
401- output azureOpenAIKeyName string = azureOpenAIApiKeyEntry .name
402-
403- output projectEndpoint string = aiProject .properties .endpoints ['AI Foundry API' ]
407+ output projectEndpoint string = !empty (existingProjEndpoint ) ? existingProjEndpoint : aiProject .properties .endpoints ['AI Foundry API' ]
404408output applicationInsightsConnectionString string = applicationInsights .properties .ConnectionString
0 commit comments