Skip to content

Commit 03cd5f1

Browse files
foundry role assignment
1 parent e56056c commit 03cd5f1

File tree

5 files changed

+253
-82
lines changed

5 files changed

+253
-82
lines changed

infra/deploy_ai_foundry.bicep

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ resource aiUserAccessFoundry 'Microsoft.Authorization/roleAssignments@2022-04-01
233233
}
234234
}
235235

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+
236247
resource tenantIdEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
237248
parent: keyVault
238249
name: 'TENANT-ID'
@@ -289,6 +300,14 @@ resource azureOpenAICUEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-0
289300
}
290301
}
291302

303+
resource azureOpenAICUApiKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
304+
parent: keyVault
305+
name: 'AZURE-OPENAI-CU-KEY'
306+
properties: {
307+
value: aiServices_CU.listKeys().key1
308+
}
309+
}
310+
292311
resource azureOpenAICUApiVersionEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
293312
parent: keyVault
294313
name: 'AZURE-OPENAI-CU-VERSION'

infra/deploy_backend_docker.bicep

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ param solutionLocation string
99
param appSettings object = {}
1010
param appServicePlanId string
1111
param userassignedIdentityId string
12-
param aiProjectName string
1312
param keyVaultName string
1413
param aiServicesName string
1514
param useLocalBuild string
15+
param azureExistingAIProjectResourceId string = ''
16+
var existingAIServiceSubscription = !empty(azureExistingAIProjectResourceId) ? split(azureExistingAIProjectResourceId, '/')[2] : subscription().subscriptionId
17+
var existingAIServiceResourceGroup = !empty(azureExistingAIProjectResourceId) ? split(azureExistingAIProjectResourceId, '/')[4] : resourceGroup().name
18+
var existingAIServicesName = !empty(azureExistingAIProjectResourceId) ? split(azureExistingAIProjectResourceId, '/')[8] : ''
1619

1720
var imageName = 'DOCKER|${acrName}.azurecr.io/km-api:${imageTag}'
18-
//var name = '${solutionName}-api'
1921
param name string
2022
var reactAppLayoutConfig ='''{
2123
"appConfig": {
@@ -121,24 +123,7 @@ resource role 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2022-05-
121123

122124
resource aiServices 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = {
123125
name: aiServicesName
124-
}
125-
126-
resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' existing = {
127-
parent: aiServices
128-
name: aiProjectName
129-
}
130-
131-
resource aiDeveloper 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
132-
name: '64702f94-c441-49e6-a78b-ef80e0188fee'
133-
}
134-
135-
resource aiDeveloperAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
136-
name: guid(appService.name, aiProject.id, aiDeveloper.id)
137-
scope: aiProject
138-
properties: {
139-
roleDefinitionId: aiDeveloper.id
140-
principalId: appService.outputs.identityPrincipalId
141-
}
126+
scope: resourceGroup(existingAIServiceSubscription, existingAIServiceResourceGroup)
142127
}
143128

144129
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
@@ -162,21 +147,14 @@ resource aiUser 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing =
162147
name: '53ca6127-db72-4b80-b1b0-d745d6d5456d'
163148
}
164149

165-
resource aiUserAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
166-
name: guid(appService.name, aiProject.id, aiUser.id)
167-
scope: aiProject
168-
properties: {
169-
roleDefinitionId: aiUser.id
150+
module assignAiUserRoleToAiProject 'deploy_foundry_role_assignment.bicep' = if (!empty(azureExistingAIProjectResourceId)){
151+
name: 'assignAiUserRoleToAiProject'
152+
scope: resourceGroup(existingAIServiceSubscription, existingAIServiceResourceGroup)
153+
params: {
170154
principalId: appService.outputs.identityPrincipalId
171-
}
172-
}
173-
174-
resource aiUserAccessFoundry 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
175-
name: guid(appService.name, aiServices.id, aiUser.id)
176-
scope: aiServices
177-
properties: {
178155
roleDefinitionId: aiUser.id
179-
principalId: appService.outputs.identityPrincipalId
156+
roleAssignmentName: guid(appService.name, aiServices.id, aiUser.id)
157+
aiServicesName: !empty(azureExistingAIProjectResourceId) ? existingAIServicesName : aiServicesName
180158
}
181159
}
182160

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
param principalId string = ''
2+
param roleDefinitionId string
3+
param roleAssignmentName string = ''
4+
param aiServicesName string
5+
param userassignedIdentityId string = ''
6+
7+
resource aiServices 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = {
8+
name: aiServicesName
9+
}
10+
11+
resource roleAssignmentToFoundry 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (!empty(aiServicesName) && !empty(principalId)) {
12+
name: roleAssignmentName
13+
scope: aiServices
14+
properties: {
15+
roleDefinitionId: roleDefinitionId
16+
principalId: principalId
17+
}
18+
}
19+
20+
resource roleAssignmentToManagedIdentity 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (!empty(userassignedIdentityId)) {
21+
name: roleAssignmentName
22+
scope: aiServices
23+
properties: {
24+
roleDefinitionId: roleDefinitionId
25+
principalId: userassignedIdentityId
26+
principalType: 'ServicePrincipal'
27+
}
28+
}

infra/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ module backend_docker 'deploy_backend_docker.bicep' = {
209209
appServicePlanId: hostingplan.outputs.name
210210
applicationInsightsId: aifoundry.outputs.applicationInsightsId
211211
userassignedIdentityId: managedIdentityModule.outputs.managedIdentityBackendAppOutput.id
212-
aiProjectName: aifoundry.outputs.aiProjectName
213212
keyVaultName: kvault.outputs.keyvaultName
214213
aiServicesName: aifoundry.outputs.aiServicesName
215214
useLocalBuild: useLocalBuildLower
215+
azureExistingAIProjectResourceId: azureExistingAIProjectResourceId
216216
appSettings: {
217217
AZURE_OPENAI_DEPLOYMENT_MODEL: gptModelName
218218
AZURE_OPENAI_ENDPOINT: aifoundry.outputs.aiServicesTarget

0 commit comments

Comments
 (0)