@@ -28,8 +28,17 @@ param existingBingAccountName string
2828@minLength (1 )
2929param existingWebApplicationInsightsResourceName string
3030
31+ @description ('The existing User Managed Identity for the AI Foundry project.' )
32+ @minLength (1 )
33+ param existingAgentUserManagedIdentityName string
34+
3135// ---- Existing resources ----
3236
37+ @description ('Existing Agent User Managed Identity for the AI Foundry Project.' )
38+ resource agentUserManagedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2025-01-31-preview' existing = {
39+ name : existingAgentUserManagedIdentityName
40+ }
41+
3342@description ('The internal ID of the project is used in the Azure Storage blob containers and in the Cosmos DB collections.' )
3443#disable-next-line BCP053
3544var workspaceId = aiFoundry ::project .properties .internalId
@@ -57,33 +66,12 @@ resource azureAISearchService 'Microsoft.Search/searchServices@2025-02-01-previe
5766 name : existingAISearchAccountName
5867}
5968
60- resource azureAISearchServiceContributorRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
61- name : '7ca78c08-252a-4471-8644-bb5ff32d4ba0'
62- scope : subscription ()
63- }
64-
65- resource azureAISearchIndexDataContributorRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
66- name : '8ebe5a00-799e-43f5-93ac-243d3dce84a7'
67- scope : subscription ()
68- }
69-
70- // Storage Blob Data Contributor
71- resource storageBlobDataContributorRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
72- name : 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
73- scope : subscription ()
74- }
75-
7669// Storage Blob Data Owner Role
7770resource storageBlobDataOwnerRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
7871 name : 'b7e6dc6d-f1e8-4753-8033-0f276bb0955b'
7972 scope : subscription ()
8073}
8174
82- resource cosmosDbOperatorRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
83- name : '230815da-be43-4aae-9cb4-875f7bd000aa'
84- scope : subscription ()
85- }
86-
8775#disable-next-line BCP081
8876resource bingAccount 'Microsoft.Bing/accounts@2025-05-01-preview' existing = {
8977 name : existingBingAccountName
@@ -103,7 +91,10 @@ resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-06-01' existing =
10391 name : 'projchat'
10492 location : location
10593 identity : {
106- type : 'SystemAssigned'
94+ type : 'UserAssigned'
95+ userAssignedIdentities : {
96+ '${agentUserManagedIdentity .id }' : {}
97+ }
10798 }
10899 properties : {
109100 description : 'Chat using internet data in your Azure AI Foundry Agent.'
@@ -123,9 +114,7 @@ resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-06-01' existing =
123114 location : cosmosDbAccount .location
124115 }
125116 }
126- dependsOn : [
127- projectDbCosmosDbOperatorAssignment
128- ]
117+ dependsOn : []
129118 }
130119
131120 @description ('Create project connection to the Azure Storage account; dependency for Azure AI Foundry Agent Service.' )
@@ -142,7 +131,6 @@ resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-06-01' existing =
142131 }
143132 }
144133 dependsOn : [
145- projectBlobDataContributorAssignment
146134 projectBlobDataOwnerConditionalAssignment
147135 threadStorageConnection // Single thread these connections, else conflict errors tend to happen
148136 ]
@@ -162,8 +150,6 @@ resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-06-01' existing =
162150 }
163151 }
164152 dependsOn : [
165- projectAISearchIndexDataContributorAssignment
166- projectAISearchContributorAssignment
167153 storageConnection // Single thread these connections, else conflict errors tend to happen
168154 ]
169155 }
@@ -190,7 +176,6 @@ resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-06-01' existing =
190176 ]
191177 }
192178
193-
194179 @description ('Create the Azure AI Foundry Agent Service capability.' )
195180 resource aiAgentService 'capabilityHosts' = {
196181 name : 'projectagents'
@@ -232,72 +217,26 @@ resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-06-01' existing =
232217
233218// Role assignments
234219
235- @description ('Grant the AI Foundry Project managed identity Cosmos Db Db Operator user role permissions.' )
236- module projectDbCosmosDbOperatorAssignment './modules/cosmosdbRoleAssignment.bicep' = {
237- name : 'projectDbCosmosDbOperatorAssignmentDeploy'
238- params : {
239- roleDefinitionId : cosmosDbOperatorRole .id
240- principalId : aiFoundry ::project .identity .principalId
241- existingAiFoundryProjectId : aiFoundry ::project .id
242- existingCosmosDbAccountName : existingCosmosDbAccountName
243- }
244- }
245-
246- @description ('Grant the AI Foundry Project managed identity Storage Account Blob Data Contributor user role permissions.' )
247- module projectBlobDataContributorAssignment './modules/storageAccountRoleAssignment.bicep' = {
248- name : 'projectBlobDataContributorAssignmentDeploy'
249- params : {
250- roleDefinitionId : storageBlobDataContributorRole .id
251- principalId : aiFoundry ::project .identity .principalId
252- existingAiFoundryProjectId : aiFoundry ::project .id
253- existingStorageAccountName : existingStorageAccountName
254- }
255- }
256-
257220@description ('Grant the AI Foundry Project managed identity Storage Account Blob Data Owner user role permissions.' )
258221module projectBlobDataOwnerConditionalAssignment './modules/storageAccountRoleAssignment.bicep' = {
259222 name : 'projectBlobDataOwnerConditionalAssignmentDeploy'
260223 params : {
261224 roleDefinitionId : storageBlobDataOwnerRole .id
262- principalId : aiFoundry ::project .identity .principalId
263- existingAiFoundryProjectId : aiFoundry ::project .id
225+ principalId : agentUserManagedIdentity .properties .principalId
264226 existingStorageAccountName : existingStorageAccountName
265227 conditionVersion : '2.0'
266228 condition : '((!(ActionMatches{\' Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags/read\' }) AND !(ActionMatches{\' Microsoft.Storage/storageAccounts/blobServices/containers/blobs/filter/action\' }) AND !(ActionMatches{\' Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags/write\' }) ) OR (@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:name] StringStartsWithIgnoreCase \' ${workspaceIdAsGuid }\' ))'
267229 }
268230}
269231
270- @description ('Grant the AI Foundry Project managed identity AI Search Contributor user role permissions.' )
271- module projectAISearchContributorAssignment './modules/aiSearchRoleAssignment.bicep' = {
272- name : 'projectAISearchContributorAssignmentDeploy'
273- params : {
274- roleDefinitionId : azureAISearchServiceContributorRole .id
275- principalId : aiFoundry ::project .identity .principalId
276- existingAiFoundryProjectId : aiFoundry ::project .id
277- existingAISearchAccountName : existingAISearchAccountName
278- }
279- }
280-
281- @description ('Grant the AI Foundry Project managed identity AI Search Data Contributor user role permissions.' )
282- module projectAISearchIndexDataContributorAssignment './modules/aiSearchRoleAssignment.bicep' = {
283- name : 'projectAISearchIndexDataContributorAssignmentDeploy'
284- params : {
285- roleDefinitionId : azureAISearchIndexDataContributorRole .id
286- principalId : aiFoundry ::project .identity .principalId
287- existingAiFoundryProjectId : aiFoundry ::project .id
288- existingAISearchAccountName : existingAISearchAccountName
289- }
290- }
291-
292232// Sql Role Assignments
293233
294234@description ('Assign the project\' s managed identity the ability to read and write data in this collection within enterprise_memory database.' )
295235module projectUserThreadContainerWriterSqlAssignment './modules/cosmosdbSqlRoleAssignment.bicep' = {
296236 name : 'projectUserThreadContainerWriterSqlAssignmentDeploy'
297237 params : {
298238 roleDefinitionId : cosmosDbAccount ::dataContributorRole .id
299- principalId : aiFoundry ::project .identity .principalId
300- existingAiFoundryProjectId : aiFoundry ::project .id
239+ principalId : agentUserManagedIdentity .properties .principalId
301240 existingCosmosDbAccountName : existingCosmosDbAccountName
302241 existingCosmosDbName : 'enterprise_memory'
303242 existingCosmosCollectionTypeName : 'user'
@@ -313,8 +252,7 @@ module projectSystemThreadContainerWriterSqlAssignment './modules/cosmosdbSqlRol
313252 name : 'projectSystemThreadContainerWriterSqlAssignmentDeploy'
314253 params : {
315254 roleDefinitionId : cosmosDbAccount ::dataContributorRole .id
316- principalId : aiFoundry ::project .identity .principalId
317- existingAiFoundryProjectId : aiFoundry ::project .id
255+ principalId : agentUserManagedIdentity .properties .principalId
318256 existingCosmosDbAccountName : existingCosmosDbAccountName
319257 existingCosmosDbName : 'enterprise_memory'
320258 existingCosmosCollectionTypeName : 'system'
@@ -331,8 +269,7 @@ module projectEntityContainerWriterSqlAssignment './modules/cosmosdbSqlRoleAssig
331269 name : 'projectEntityContainerWriterSqlAssignmentDeploy'
332270 params : {
333271 roleDefinitionId : cosmosDbAccount ::dataContributorRole .id
334- principalId : aiFoundry ::project .identity .principalId
335- existingAiFoundryProjectId : aiFoundry ::project .id
272+ principalId : agentUserManagedIdentity .properties .principalId
336273 existingCosmosDbAccountName : existingCosmosDbAccountName
337274 existingCosmosDbName : 'enterprise_memory'
338275 existingCosmosCollectionTypeName : 'entities'
0 commit comments