Skip to content

Commit cb062a9

Browse files
fix: Fixing of EXP Deployment - Bug#33406
2 parents 6273f66 + a0a1602 commit cb062a9

2 files changed

Lines changed: 98 additions & 3 deletions

File tree

content-gen/infra/main.bicep

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ var useExistingAiFoundryAiProject = !empty(azureExistingAIProjectResourceId)
240240
var aiFoundryAiServicesResourceGroupName = useExistingAiFoundryAiProject
241241
? split(azureExistingAIProjectResourceId, '/')[4]
242242
: 'rg-${solutionSuffix}'
243-
// var aiFoundryAiServicesSubscriptionId = useExistingAiFoundryAiProject
244-
// ? split(azureExistingAIProjectResourceId, '/')[2]
245-
// : subscription().id
243+
var aiFoundryAiServicesSubscriptionId = useExistingAiFoundryAiProject
244+
? split(azureExistingAIProjectResourceId, '/')[2]
245+
: subscription().subscriptionId
246246
var aiFoundryAiServicesResourceName = useExistingAiFoundryAiProject
247247
? split(azureExistingAIProjectResourceId, '/')[8]
248248
: 'aif-${solutionSuffix}'
@@ -572,6 +572,17 @@ var aiFoundryAiProjectEndpoint = useExistingAiFoundryAiProject
572572
? 'https://${aiFoundryAiServicesResourceName}.services.ai.azure.com/api/projects/${aiFoundryAiProjectResourceName}'
573573
: aiFoundryAiServicesProject!.outputs.apiEndpoint
574574

575+
// ========== Role Assignments for Existing AI Services ========== //
576+
module existingAiServicesRoleAssignments 'modules/deploy_foundry_role_assignment.bicep' = if (useExistingAiFoundryAiProject) {
577+
name: take('module.foundry-role-assignment.${aiFoundryAiServicesResourceName}', 64)
578+
scope: resourceGroup(aiFoundryAiServicesSubscriptionId, aiFoundryAiServicesResourceGroupName)
579+
params: {
580+
aiServicesName: aiFoundryAiServicesResourceName
581+
principalId: userAssignedIdentity.outputs.principalId
582+
principalType: 'ServicePrincipal'
583+
}
584+
}
585+
575586
// ========== AI Search ========== //
576587
module aiSearch 'br/public:avm/res/search/search-service:0.11.1' = {
577588
name: take('avm.res.search.search-service.${aiSearchName}', 64)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// ========== existing-ai-services-roles.bicep ========== //
2+
// Module to assign RBAC roles to managed identity on an existing AI Services account
3+
// This is required when reusing an existing AI Foundry project from a different resource group
4+
5+
@description('Required. The principal ID of the managed identity to grant access.')
6+
param principalId string
7+
8+
@description('Required. The name of the existing AI Services account.')
9+
param aiServicesName string
10+
11+
@description('Optional. The name of the existing AI Project.')
12+
param aiProjectName string = ''
13+
14+
@description('Optional. The principal type of the identity.')
15+
@allowed([
16+
'Device'
17+
'ForeignGroup'
18+
'Group'
19+
'ServicePrincipal'
20+
'User'
21+
])
22+
param principalType string = 'ServicePrincipal'
23+
24+
// ========== Role Definitions ========== //
25+
26+
// Azure AI User role - for AI Foundry project access (used by AIProjectClient for image generation)
27+
resource azureAiUserRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
28+
name: '53ca6127-db72-4b80-b1b0-d745d6d5456d'
29+
}
30+
31+
// Cognitive Services OpenAI User role - for chat completions (used by AzureOpenAIChatClient)
32+
resource cognitiveServicesOpenAiUserRole 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
33+
name: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
34+
}
35+
36+
// ========== Existing Resources ========== //
37+
38+
// Reference the existing AI Services account
39+
resource existingAiServices 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = {
40+
name: aiServicesName
41+
}
42+
43+
// Reference the existing AI Project (if provided)
44+
resource existingAiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' existing = if (!empty(aiProjectName)) {
45+
name: aiProjectName
46+
parent: existingAiServices
47+
}
48+
49+
// ========== Role Assignments ========== //
50+
51+
// Azure AI User role assignment - same as reference accelerator
52+
// Required for AIProjectClient (used for image generation in Foundry mode)
53+
resource assignAzureAiUserRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
54+
name: guid(existingAiServices.id, principalId, azureAiUserRole.id)
55+
scope: existingAiServices
56+
properties: {
57+
roleDefinitionId: azureAiUserRole.id
58+
principalId: principalId
59+
principalType: principalType
60+
}
61+
}
62+
63+
// Cognitive Services OpenAI User role assignment
64+
// Required for AzureOpenAIChatClient (used for chat completions)
65+
resource assignCognitiveServicesOpenAiUserRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
66+
name: guid(existingAiServices.id, principalId, cognitiveServicesOpenAiUserRole.id)
67+
scope: existingAiServices
68+
properties: {
69+
roleDefinitionId: cognitiveServicesOpenAiUserRole.id
70+
principalId: principalId
71+
principalType: principalType
72+
}
73+
}
74+
75+
// ========== Outputs ========== //
76+
77+
@description('The resource ID of the existing AI Services account.')
78+
output aiServicesResourceId string = existingAiServices.id
79+
80+
@description('The endpoint of the existing AI Services account.')
81+
output aiServicesEndpoint string = existingAiServices.properties.endpoint
82+
83+
@description('The principal ID of the existing AI Project (if provided).')
84+
output aiProjectPrincipalId string = !empty(aiProjectName) ? existingAiProject.identity.principalId : ''

0 commit comments

Comments
 (0)