@@ -20,6 +20,11 @@ param existingLogAnalyticsWorkspaceId string = ''
2020
2121param azureopenaiVersion string = '2025-01-01-preview'
2222
23+ // ADD AFTER LINE 22 - Get the current deployer's information
24+ var deployerInfo = deployer ()
25+ var deployingUserPrincipalId = deployerInfo .objectId
26+ var enableUserRoleAssignment = !empty (deployingUserPrincipalId )
27+
2328// Restricting deployment to only supported Azure OpenAI regions validated with GPT-4o model
2429@metadata ({
2530 azd : {
@@ -812,6 +817,37 @@ module cogServiceRoleAssignmentsExisting './modules/role.bicep' = if(useExisting
812817 scope : resourceGroup ( split (existingFoundryProjectResourceId , '/' )[2 ], split (existingFoundryProjectResourceId , '/' )[4 ])
813818}
814819
820+ // ADD AFTER LINE 700 - User Role Assignment for Azure OpenAI
821+ // User Role Assignment for Azure OpenAI - New Resources
822+ module userOpenAiRoleAssignment './modules/role.bicep' = if (enableUserRoleAssignment && aiFoundryAIservicesEnabled && !useExistingResourceId ) {
823+ name : take ('user-openai-${uniqueString (deployingUserPrincipalId , aiFoundryAiServicesResourceName )}' , 64 )
824+ params : {
825+ name : 'user-openai-${uniqueString (deployingUserPrincipalId , aiFoundryAiServicesResourceName )}'
826+ principalId : deployingUserPrincipalId
827+ aiServiceName : aiFoundryAiServices .outputs .name
828+ principalType : 'User'
829+ }
830+ scope : resourceGroup (subscription ().subscriptionId , resourceGroup ().name )
831+ dependsOn : [
832+ aiFoundryAiServices
833+ ]
834+ }
835+
836+ // User Role Assignment for Azure OpenAI - Existing Resources
837+ module userOpenAiRoleAssignmentExisting './modules/role.bicep' = if (enableUserRoleAssignment && aiFoundryAIservicesEnabled && useExistingResourceId ) {
838+ name : take ('user-openai-existing-${uniqueString (deployingUserPrincipalId , aiFoundryAiServicesResourceName )}' , 64 )
839+ params : {
840+ name : 'user-openai-existing-${uniqueString (deployingUserPrincipalId , aiFoundryAiServicesResourceName )}'
841+ principalId : deployingUserPrincipalId
842+ aiServiceName : aiFoundryAiServices .outputs .name
843+ principalType : 'User'
844+ }
845+ scope : resourceGroup (split (existingFoundryProjectResourceId , '/' )[2 ], split (existingFoundryProjectResourceId , '/' )[4 ])
846+ dependsOn : [
847+ aiFoundryAiServices
848+ ]
849+ }
850+
815851// ========== Cosmos DB ========== //
816852// WAF best practices for Cosmos DB: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/cosmos-db
817853module privateDnsZonesCosmosDb 'br/public:avm/res/network/private-dns-zone:0.7.0' = if (virtualNetworkEnabled ) {
@@ -886,9 +922,11 @@ module cosmosDb 'br/public:avm/res/document-db/database-account:0.12.0' = if (co
886922 capabilitiesToAdd : [
887923 'EnableServerless'
888924 ]
889- sqlRoleAssignmentsPrincipalIds : [
890- containerApp .outputs .?systemAssignedMIPrincipalId
891- ]
925+ // REPLACE LINE 773
926+ sqlRoleAssignmentsPrincipalIds : concat (
927+ [containerApp .outputs .?systemAssignedMIPrincipalId ],
928+ enableUserRoleAssignment ? [deployingUserPrincipalId ] : []
929+ )
892930 sqlRoleDefinitions : [
893931 {
894932 // Replace this with built-in role definition Cosmos DB Built-in Data Contributor: https://docs.azure.cn/en-us/cosmos-db/nosql/security/reference-data-plane-roles#cosmos-db-built-in-data-contributor
@@ -1739,3 +1777,7 @@ output AZURE_AI_MODEL_DEPLOYMENT_NAME string = aiFoundryAiServicesModelDeploymen
17391777output AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME string = aiFoundryAiServicesModelDeployment .name
17401778output AZURE_AI_AGENT_ENDPOINT string = aiFoundryAiServices .outputs .aiProjectInfo .apiEndpoint
17411779output APP_ENV string = 'Prod'
1780+
1781+ // ADD AFTER LINE 941
1782+ output deployerInfo object = deployerInfo
1783+ output userRoleAssignmentStatus string = enableUserRoleAssignment ? 'User ${deployingUserPrincipalId } (${deployerInfo .?userPrincipalName ?? 'N/A' }) has been granted access to Cosmos DB and Azure OpenAI' : 'No user role assignment configured.'
0 commit comments