@@ -24,6 +24,7 @@ var keyvaultName = '${abbrs.security.keyVault}${solutionName}'
2424var location = solutionLocation //'eastus2'
2525var aiProjectName = '${abbrs .ai .aiFoundryProject }${solutionName }'
2626var aiSearchName = '${abbrs .ai .aiSearch }${solutionName }'
27+ var aiSearchConnectionName = 'myVectorStoreProjectConnectionName-${solutionName }'
2728
2829var aiModelDeployments = [
2930 {
@@ -56,8 +57,8 @@ var existingOpenAIEndpoint = !empty(azureExistingAIProjectResourceId) ? format('
5657var existingProjEndpoint = !empty (azureExistingAIProjectResourceId ) ? format ('https://{0}.services.ai.azure.com/api/projects/{1}' , split (azureExistingAIProjectResourceId , '/' )[8 ], split (azureExistingAIProjectResourceId , '/' )[10 ]) : ''
5758var existingAIServicesName = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[8 ] : ''
5859var existingAIProjectName = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[10 ] : ''
59- var existingAIServiceSubscription = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[2 ] : ''
60- var existingAIServiceResourceGroup = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[4 ] : ''
60+ var existingAIServiceSubscription = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[2 ] : subscription (). subscriptionId
61+ var existingAIServiceResourceGroup = !empty (azureExistingAIProjectResourceId ) ? split (azureExistingAIProjectResourceId , '/' )[4 ] : resourceGroup (). name
6162
6263resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
6364 name : keyVaultName
@@ -161,6 +162,9 @@ resource aiSearch 'Microsoft.Search/searchServices@2024-06-01-preview' = {
161162 sku : {
162163 name : 'basic'
163164 }
165+ identity : {
166+ type : 'SystemAssigned'
167+ }
164168 properties : {
165169 replicaCount : 1
166170 partitionCount : 1
@@ -172,10 +176,7 @@ resource aiSearch 'Microsoft.Search/searchServices@2024-06-01-preview' = {
172176 encryptionWithCmk : {
173177 enforcement : 'Unspecified'
174178 }
175- disableLocalAuth : false
176- authOptions : {
177- apiKeyOnly : {}
178- }
179+ disableLocalAuth : true
179180 semanticSearch : 'free'
180181 }
181182}
@@ -192,7 +193,7 @@ resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-pre
192193}
193194
194195resource aiproject_aisearch_connection_new 'Microsoft.CognitiveServices/accounts/projects/connections@2025-04-01-preview' = if (empty (azureExistingAIProjectResourceId )) {
195- name : 'myVectorStoreProjectConnectionName-${ solutionName }'
196+ name : aiSearchConnectionName
196197 parent : aiProject
197198 properties : {
198199 category : 'CognitiveSearch'
@@ -216,31 +217,121 @@ module existing_AIProject_SearchConnectionModule 'deploy_aifp_aisearch_connectio
216217 aiSearchName : aiSearchName
217218 aiSearchResourceId : aiSearch .id
218219 aiSearchLocation : aiSearch .location
219- solutionName : solutionName
220+ aiSearchConnectionName : aiSearchConnectionName
220221 }
221222}
222223
223224resource aiUser 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
224225 name : '53ca6127-db72-4b80-b1b0-d745d6d5456d'
225226}
226227
227- resource aiUserAccessFoundry 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
228- name : guid (resourceGroup ().id , managedIdentityObjectId , aiUser .id )
228+ resource assignFoundryRoleToMI 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (empty (azureExistingAIProjectResourceId )) {
229+ name : guid (resourceGroup ().id , aiServices .id , aiUser .id )
230+ scope : aiServices
229231 properties : {
230232 principalId : managedIdentityObjectId
231233 roleDefinitionId : aiUser .id
232- principalType : 'ServicePrincipal'
234+ principalType : 'ServicePrincipal'
233235 }
234236}
235237
236- module assignAiUserRoleToManagedIdentity 'deploy_foundry_role_assignment.bicep' = if (!empty (azureExistingAIProjectResourceId )) {
237- name : 'assignAiUserRoleToManagedIdentity '
238+ module assignFoundryRoleToMIExisting 'deploy_foundry_role_assignment.bicep' = if (!empty (azureExistingAIProjectResourceId )) {
239+ name : 'assignFoundryRoleToMI '
238240 scope : resourceGroup (existingAIServiceSubscription , existingAIServiceResourceGroup )
239241 params : {
240242 roleDefinitionId : aiUser .id
241- roleAssignmentName : guid (managedIdentityObjectId , aiServices .id , aiUser .id )
243+ roleAssignmentName : guid (resourceGroup ().id , managedIdentityObjectId , aiUser .id , 'foundry' )
244+ aiServicesName : !empty (azureExistingAIProjectResourceId ) ? existingAIServicesName : aiServicesName
245+ aiProjectName : !empty (azureExistingAIProjectResourceId ) ? existingAIProjectName : aiProjectName
246+ principalId : managedIdentityObjectId
247+ }
248+ }
249+
250+ resource assignAiUserToAiFoundryCU 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
251+ name : guid (resourceGroup ().id , aiServices_CU .id , aiUser .id )
252+ scope : aiServices_CU
253+ properties : {
254+ principalId : managedIdentityObjectId
255+ roleDefinitionId : aiUser .id
256+ principalType : 'ServicePrincipal'
257+ }
258+ }
259+
260+ resource cognitiveServicesOpenAIUser 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
261+ name : '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
262+ }
263+
264+ module assignOpenAIRoleToAISearch 'deploy_foundry_role_assignment.bicep' = {
265+ name : 'assignOpenAIRoleToAISearch'
266+ scope : resourceGroup (existingAIServiceSubscription , existingAIServiceResourceGroup )
267+ params : {
268+ roleDefinitionId : cognitiveServicesOpenAIUser .id
269+ roleAssignmentName : guid (resourceGroup ().id , aiSearch .id , cognitiveServicesOpenAIUser .id , 'openai-foundry' )
242270 aiServicesName : !empty (azureExistingAIProjectResourceId ) ? existingAIServicesName : aiServicesName
243- userassignedIdentityId : managedIdentityObjectId
271+ aiProjectName : !empty (azureExistingAIProjectResourceId ) ? existingAIProjectName : aiProjectName
272+ principalId : aiSearch .identity .principalId
273+ }
274+ }
275+
276+ resource searchIndexDataReader 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
277+ name : '1407120a-92aa-4202-b7e9-c0e197c71c8f'
278+ }
279+
280+ resource assignSearchIndexDataReaderToAiProject 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (empty (azureExistingAIProjectResourceId )) {
281+ name : guid (resourceGroup ().id , aiProject .id , searchIndexDataReader .id )
282+ scope : aiSearch
283+ properties : {
284+ principalId : aiProject .identity .principalId
285+ roleDefinitionId : searchIndexDataReader .id
286+ principalType : 'ServicePrincipal'
287+ }
288+ }
289+
290+ resource assignSearchIndexDataReaderToExistingAiProject 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (!empty (azureExistingAIProjectResourceId )) {
291+ name : guid (resourceGroup ().id , existingAIProjectName , searchIndexDataReader .id , 'Existing' )
292+ scope : aiSearch
293+ properties : {
294+ principalId : assignOpenAIRoleToAISearch .outputs .aiProjectPrincipalId
295+ roleDefinitionId : searchIndexDataReader .id
296+ principalType : 'ServicePrincipal'
297+ }
298+ }
299+
300+ resource searchServiceContributor 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
301+ name : '7ca78c08-252a-4471-8644-bb5ff32d4ba0'
302+ }
303+
304+ resource assignSearchServiceContributorToAiProject 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (empty (azureExistingAIProjectResourceId )) {
305+ name : guid (resourceGroup ().id , aiProject .id , searchServiceContributor .id )
306+ scope : aiSearch
307+ properties : {
308+ principalId : aiProject .identity .principalId
309+ roleDefinitionId : searchServiceContributor .id
310+ principalType : 'ServicePrincipal'
311+ }
312+ }
313+
314+ resource assignSearchServiceContributorToExistingAiProject 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (!empty (azureExistingAIProjectResourceId )) {
315+ name : guid (resourceGroup ().id , existingAIProjectName , searchServiceContributor .id , 'Existing' )
316+ scope : aiSearch
317+ properties : {
318+ principalId : assignOpenAIRoleToAISearch .outputs .aiProjectPrincipalId
319+ roleDefinitionId : searchServiceContributor .id
320+ principalType : 'ServicePrincipal'
321+ }
322+ }
323+
324+ resource searchIndexDataContributor 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
325+ name : '8ebe5a00-799e-43f5-93ac-243d3dce84a7'
326+ }
327+
328+ resource assignSearchIndexDataContributorToMI 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
329+ name : guid (resourceGroup ().id , aiProject .id , searchIndexDataContributor .id )
330+ scope : aiSearch
331+ properties : {
332+ principalId : managedIdentityObjectId
333+ roleDefinitionId : searchIndexDataContributor .id
334+ principalType : 'ServicePrincipal'
244335 }
245336}
246337
@@ -292,6 +383,14 @@ resource azureOpenAIEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-
292383 }
293384}
294385
386+ resource azureOpenAIEmbeddingDeploymentModel 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
387+ parent : keyVault
388+ name : 'AZURE-OPENAI-EMBEDDING-MODEL'
389+ properties : {
390+ value : embeddingModel
391+ }
392+ }
393+
295394resource azureOpenAICUEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
296395 parent : keyVault
297396 name : 'AZURE-OPENAI-CU-ENDPOINT'
@@ -308,14 +407,6 @@ resource azureOpenAICUApiVersionEntry 'Microsoft.KeyVault/vaults/secrets@2021-11
308407 }
309408}
310409
311- resource azureSearchAdminKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
312- parent : keyVault
313- name : 'AZURE-SEARCH-KEY'
314- properties : {
315- value : aiSearch .listAdminKeys ().primaryKey
316- }
317- }
318-
319410resource azureSearchServiceEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
320411 parent : keyVault
321412 name : 'AZURE-SEARCH-ENDPOINT'
@@ -390,6 +481,7 @@ output aiSearchId string = aiSearch.id
390481output aiSearchTarget string = 'https://${aiSearch .name }.search.windows.net'
391482output aiSearchService string = aiSearch .name
392483output aiProjectName string = !empty (existingAIProjectName ) ? existingAIProjectName : aiProject .name
484+ output aiSearchConnectionName string = aiSearchConnectionName
393485
394486output applicationInsightsId string = applicationInsights .id
395487output logAnalyticsWorkspaceResourceName string = useExisting ? existingLogAnalyticsWorkspace .name : logAnalytics .name
0 commit comments