Skip to content

Commit caa5533

Browse files
Merge pull request #151 from microsoft/hb-psl-us-37902
refactor: replace ai foundry avm pattern with cognitive service account avm resource module
2 parents deafc47 + a57d922 commit caa5533

File tree

4 files changed

+3319
-21314
lines changed

4 files changed

+3319
-21314
lines changed

infra/main.bicep

Lines changed: 108 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ var aiFoundryAiServicesResourceName = useExistingAiFoundryAiProject
734734
? split(existingFoundryProjectResourceId, '/')[8]
735735
: 'aif-${solutionSuffix}'
736736

737+
var aiFoundryAiProjectResourceName = 'proj-${solutionSuffix}'
738+
var aiFoundryAiProjectDescription = 'AI Foundry project for ${solutionName}'
737739

738740
resource existingAiFoundryAiServices 'Microsoft.CognitiveServices/accounts@2025-06-01' existing = if (useExistingAiFoundryAiProject) {
739741
name: aiFoundryAiServicesResourceName
@@ -791,57 +793,19 @@ module existingAiFoundryAiServicesDeployments 'modules/ai-services-deployments.b
791793
}
792794
}
793795

794-
// Temporarily disabled AI Foundry due to AML workspace creation issues
795-
module aiFoundry 'br/public:avm/ptn/ai-ml/ai-foundry:0.4.0' = if(!useExistingAiFoundryAiProject) {
796-
name: take('avm.ptn.ai-ml.ai-foundry.${solutionSuffix}', 64)
796+
// ========== AI Foundry AI Services ========== //
797+
module aiFoundryAiServices 'br/public:avm/res/cognitive-services/account:0.13.2' = if (!useExistingAiFoundryAiProject) {
798+
name: take('avm.res.cognitive-services.account.${aiFoundryAiServicesResourceName}', 64)
797799
params: {
798-
#disable-next-line BCP334
799-
baseName: take(aiFoundryAiServicesResourceName, 12)
800-
baseUniqueName: null
800+
name: aiFoundryAiServicesResourceName
801801
location: empty(azureAiServiceLocation) ? location : azureAiServiceLocation
802-
aiFoundryConfiguration: {
803-
accountName:aiFoundryAiServicesResourceName
804-
allowProjectManagement: true
805-
roleAssignments: [
806-
// Service Principal permissions
807-
{
808-
principalId: appIdentity.outputs.principalId
809-
principalType: 'ServicePrincipal'
810-
roleDefinitionIdOrName: 'Cognitive Services OpenAI Contributor'
811-
}
812-
{
813-
principalId: appIdentity.outputs.principalId
814-
principalType: 'ServicePrincipal'
815-
roleDefinitionIdOrName: '64702f94-c441-49e6-a78b-ef80e0188fee' // Azure AI Developer
816-
}
817-
{
818-
principalId: appIdentity.outputs.principalId
819-
principalType: 'ServicePrincipal'
820-
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Azure AI User
821-
}
822-
// Deployer permissions for local debugging
823-
{
824-
principalId: deployingUserPrincipalId
825-
principalType: deployingUserType
826-
roleDefinitionIdOrName: 'Cognitive Services OpenAI Contributor'
827-
}
828-
{
829-
principalId: deployingUserPrincipalId
830-
principalType: deployingUserType
831-
roleDefinitionIdOrName: 'Cognitive Services User'
832-
}
833-
]
834-
// Remove networking configuration to avoid AML workspace creation issues
835-
networking: enablePrivateNetworking? {
836-
aiServicesPrivateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.aiServices]!.outputs.resourceId
837-
openAiPrivateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.openAI]!.outputs.resourceId
838-
cognitiveServicesPrivateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cognitiveServices]!.outputs.resourceId
839-
} : null
840-
}
841-
// Disable private endpoints temporarily to fix AML workspace issue
842-
privateEndpointSubnetResourceId: enablePrivateNetworking ? virtualNetwork!.outputs.backendSubnetResourceId : null
843-
// Only attempt model deployment when explicitly enabled to avoid AccountIsNotSucceeded failures due to quota or model availability.
844-
aiModelDeployments: [
802+
tags: allTags
803+
sku: 'S0'
804+
kind: 'AIServices'
805+
disableLocalAuth: true
806+
allowProjectManagement: true
807+
customSubDomainName: aiFoundryAiServicesResourceName
808+
deployments: [
845809
{
846810
name: aiModelDeploymentName
847811
model: {
@@ -855,8 +819,102 @@ module aiFoundry 'br/public:avm/ptn/ai-ml/ai-foundry:0.4.0' = if(!useExistingAiF
855819
}
856820
}
857821
]
822+
networkAcls: {
823+
defaultAction: 'Allow'
824+
virtualNetworkRules: []
825+
ipRules: []
826+
}
827+
managedIdentities: {
828+
systemAssigned: true
829+
userAssignedResourceIds: [appIdentity.outputs.resourceId]
830+
}
831+
roleAssignments: [
832+
// Service Principal permissions
833+
{
834+
roleDefinitionIdOrName: 'Cognitive Services OpenAI Contributor'
835+
principalId: appIdentity.outputs.principalId
836+
principalType: 'ServicePrincipal'
837+
}
838+
{
839+
roleDefinitionIdOrName: '64702f94-c441-49e6-a78b-ef80e0188fee' // Azure AI Developer
840+
principalId: appIdentity.outputs.principalId
841+
principalType: 'ServicePrincipal'
842+
}
843+
{
844+
roleDefinitionIdOrName: '53ca6127-db72-4b80-b1b0-d745d6d5456d' // Azure AI User
845+
principalId: appIdentity.outputs.principalId
846+
principalType: 'ServicePrincipal'
847+
}
848+
// Deployer permissions for local debugging
849+
{
850+
roleDefinitionIdOrName: 'Cognitive Services OpenAI Contributor'
851+
principalId: deployingUserPrincipalId
852+
principalType: deployingUserType
853+
}
854+
{
855+
roleDefinitionIdOrName: 'Cognitive Services User'
856+
principalId: deployingUserPrincipalId
857+
principalType: deployingUserType
858+
}
859+
]
860+
// WAF aligned configuration for Monitoring
861+
diagnosticSettings: enableMonitoring ? [{ workspaceResourceId: logAnalyticsWorkspaceResourceId }] : null
862+
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
863+
// Private endpoints are deployed separately via the aiFoundryPrivateEndpoint module below
864+
privateEndpoints: []
865+
enableTelemetry: enableTelemetry
866+
}
867+
}
868+
869+
// ========== AI Foundry Private Endpoint ========== //
870+
module aiFoundryPrivateEndpoint 'br/public:avm/res/network/private-endpoint:0.8.1' = if (enablePrivateNetworking && !useExistingAiFoundryAiProject) {
871+
name: take('pep-${aiFoundryAiServicesResourceName}-deployment', 64)
872+
params: {
873+
name: 'pep-${aiFoundryAiServicesResourceName}'
874+
customNetworkInterfaceName: 'nic-${aiFoundryAiServicesResourceName}'
875+
location: solutionLocation
858876
tags: allTags
859877
enableTelemetry: enableTelemetry
878+
privateLinkServiceConnections: [
879+
{
880+
name: 'pep-${aiFoundryAiServicesResourceName}-connection'
881+
properties: {
882+
privateLinkServiceId: aiFoundryAiServices!.outputs.resourceId
883+
groupIds: ['account']
884+
}
885+
}
886+
]
887+
privateDnsZoneGroup: {
888+
privateDnsZoneGroupConfigs: [
889+
{
890+
name: 'ai-services-dns-zone-cognitiveservices'
891+
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cognitiveServices]!.outputs.resourceId
892+
}
893+
{
894+
name: 'ai-services-dns-zone-openai'
895+
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.openAI]!.outputs.resourceId
896+
}
897+
{
898+
name: 'ai-services-dns-zone-aiservices'
899+
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.aiServices]!.outputs.resourceId
900+
}
901+
]
902+
}
903+
subnetResourceId: virtualNetwork!.outputs.backendSubnetResourceId
904+
}
905+
}
906+
907+
// ========== AI Foundry Project ========== //
908+
module aiFoundryProject 'modules/ai-project.bicep' = if (!useExistingAiFoundryAiProject) {
909+
name: take('module.ai-project.${aiFoundryAiProjectResourceName}', 64)
910+
dependsOn: enablePrivateNetworking ? [aiFoundryPrivateEndpoint] : []
911+
params: {
912+
name: aiFoundryAiProjectResourceName
913+
location: azureAiServiceLocation
914+
tags: tags
915+
desc: aiFoundryAiProjectDescription
916+
//Implicit dependencies below
917+
aiServicesName: aiFoundryAiServices!.outputs.name
860918
}
861919
}
862920

@@ -976,7 +1034,7 @@ module appConfiguration 'br/public:avm/res/app-configuration/configuration-store
9761034
publicNetworkAccess: 'Enabled'
9771035
}
9781036
// Add explicit dependency
979-
dependsOn: useExistingAiFoundryAiProject ? [] : [aiFoundry]
1037+
dependsOn: useExistingAiFoundryAiProject ? [] : [aiFoundryAiServices]
9801038
}
9811039

9821040
module avmAppConfigUpdated 'br/public:avm/res/app-configuration/configuration-store:0.6.3' = if (enablePrivateNetworking) {

0 commit comments

Comments
 (0)