Skip to content

Commit 678d77e

Browse files
Merge pull request #304 from microsoft/psl-bug-20357
fix: Fix to avoid task creation for violent and meaning less prompts when deployment reuse existing AI Foundry Project.
2 parents 503b983 + 2c63e5b commit 678d77e

File tree

2 files changed

+21
-40
lines changed

2 files changed

+21
-40
lines changed

infra/main.bicep

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,9 @@ module privateDnsZonesAiServices 'br/public:avm/res/network/private-dns-zone:0.7
697697
]
698698

699699
// NOTE: Required version 'Microsoft.CognitiveServices/accounts@2024-04-01-preview' not available in AVM
700-
var aiFoundryAiServicesResourceName = aiFoundryAiServicesConfiguration.?name ?? 'aisa-${solutionPrefix}'
700+
var useExistingFoundryProject = !empty(existingFoundryProjectResourceId)
701+
var existingAiFoundryName = useExistingFoundryProject?split( existingFoundryProjectResourceId,'/')[8]:''
702+
var aiFoundryAiServicesResourceName = useExistingFoundryProject? existingAiFoundryName : aiFoundryAiServicesConfiguration.?name ?? 'aisa-${solutionPrefix}'
701703
var aiFoundryAIservicesEnabled = aiFoundryAiServicesConfiguration.?enabled ?? true
702704
var aiFoundryAiServicesModelDeployment = {
703705
format: 'OpenAI'
@@ -738,9 +740,7 @@ module aiFoundryAiServices 'modules/account/main.bicep' = if (aiFoundryAIservice
738740
bypass: 'AzureServices'
739741
defaultAction: (virtualNetworkEnabled) ? 'Deny' : 'Allow'
740742
}
741-
742-
743-
privateEndpoints: virtualNetworkEnabled
743+
privateEndpoints: virtualNetworkEnabled && !useExistingFoundryProject
744744
? ([
745745
{
746746
name: 'pep-${aiFoundryAiServicesResourceName}'
@@ -754,7 +754,7 @@ module aiFoundryAiServices 'modules/account/main.bicep' = if (aiFoundryAIservice
754754
}
755755
}
756756
])
757-
: []
757+
: []
758758
deployments: aiFoundryAiServicesConfiguration.?deployments ?? [
759759
{
760760
name: aiFoundryAiServicesModelDeployment.name
@@ -775,31 +775,24 @@ module aiFoundryAiServices 'modules/account/main.bicep' = if (aiFoundryAIservice
775775

776776
// AI Foundry: AI Project
777777
// WAF best practices for Open AI: https://learn.microsoft.com/en-us/azure/well-architected/service-guides/azure-openai
778-
var aiFoundryAiProjectName = aiFoundryAiProjectConfiguration.?name ?? 'aifp-${solutionPrefix}'
779-
780-
resource aiUser 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
781-
name: '53ca6127-db72-4b80-b1b0-d745d6d5456d'
782-
}
778+
var existingAiFounryProjectName = useExistingFoundryProject ? last(split( existingFoundryProjectResourceId,'/')) : ''
779+
var aiFoundryAiProjectName = useExistingFoundryProject ? existingAiFounryProjectName : aiFoundryAiProjectConfiguration.?name ?? 'aifp-${solutionPrefix}'
783780

784781
var useExistingResourceId = !empty(existingFoundryProjectResourceId)
785782

786-
module Newroles './modules/role.bicep' = if(!useExistingResourceId){
783+
module cogServiceRoleAssignmentsNew './modules/role.bicep' = if(!useExistingResourceId) {
787784
params: {
788-
name: 'new-${guid(containerApp.name, aiFoundryAiServices.outputs.resourceId, aiUser.id)}'
789-
roleDefinitionId: aiUser.id
785+
name: 'new-${guid(containerApp.name, aiFoundryAiServices.outputs.resourceId)}'
790786
principalId: containerApp.outputs.?systemAssignedMIPrincipalId!
791-
aiUserid: aiUser.id
792787
aiServiceName: aiFoundryAiServices.outputs.name
793788
}
794789
scope: resourceGroup(subscription().subscriptionId, resourceGroup().name)
795790
}
796791

797-
module Existingroles './modules/role.bicep' = if(useExistingResourceId){
792+
module cogServiceRoleAssignmentsExisting './modules/role.bicep' = if(useExistingResourceId) {
798793
params: {
799-
name: 'reuse-${guid(containerApp.name, aiFoundryAiServices.outputs.aiProjectInfo.resourceId, aiUser.id)}'
800-
roleDefinitionId: aiUser.id
794+
name: 'reuse-${guid(containerApp.name, aiFoundryAiServices.outputs.aiProjectInfo.resourceId)}'
801795
principalId: containerApp.outputs.?systemAssignedMIPrincipalId!
802-
aiUserid: aiUser.id
803796
aiServiceName: aiFoundryAiServices.outputs.name
804797
}
805798
scope: resourceGroup( split(existingFoundryProjectResourceId, '/')[2], split(existingFoundryProjectResourceId, '/')[4])

infra/modules/role.bicep

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
11
@description('The name of the role assignment resource. Typically generated using `guid()` for uniqueness.')
22
param name string
33

4-
@description('The ID of the role definition to assign. For example, a built-in role like "Cognitive Services User".')
5-
param roleDefinitionId string
6-
74
@description('The object ID of the principal (user, group, or service principal) to whom the role will be assigned.')
85
param principalId string
96

10-
@description('The object ID of the user to be granted AI access (can be used for assigning multiple roles).')
11-
param aiUserid string
12-
137
@description('The name of the existing Azure Cognitive Services account.')
148
param aiServiceName string
159

1610
resource cognitiveServiceExisting 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = {
1711
name: aiServiceName
1812
}
1913

14+
resource aiUser 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
15+
name: '53ca6127-db72-4b80-b1b0-d745d6d5456d'
16+
}
2017

21-
resource aiUserAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
22-
name: guid(name, 'aiUserAccessProj')
23-
scope: cognitiveServiceExisting
24-
properties: {
25-
roleDefinitionId: roleDefinitionId
26-
principalId: principalId
27-
}
18+
resource aiDeveloper 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
19+
name: '64702f94-c441-49e6-a78b-ef80e0188fee'
20+
}
21+
22+
resource cognitiveServiceOpenAIUser 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
23+
name: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
2824
}
2925

3026
resource aiUserAccessFoundry 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
3127
name: guid(name, 'aiUserAccessFoundry')
3228
scope: cognitiveServiceExisting
3329
properties: {
34-
roleDefinitionId: aiUserid
30+
roleDefinitionId: aiUser.id
3531
principalId: principalId
3632
}
3733
}
3834

39-
resource aiDeveloper 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
40-
name: '64702f94-c441-49e6-a78b-ef80e0188fee'
41-
}
42-
4335
resource aiDeveloperAccessFoundry 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
4436
name: guid(name, 'aiDeveloperAccessFoundry')
4537
scope: cognitiveServiceExisting
@@ -49,10 +41,6 @@ resource aiDeveloperAccessFoundry 'Microsoft.Authorization/roleAssignments@2022-
4941
}
5042
}
5143

52-
resource cognitiveServiceOpenAIUser 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
53-
name: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
54-
}
55-
5644
resource cognitiveServiceOpenAIUserAccessFoundry 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
5745
name: guid(name, 'cognitiveServiceOpenAIUserAccessFoundry')
5846
scope: cognitiveServiceExisting

0 commit comments

Comments
 (0)