Skip to content

Commit d3a313c

Browse files
Merge pull request #395 from microsoft/psl-avmwfchanges-alguadam
refactor: consolidate AI Foundry AVM + custom code
2 parents b30dc15 + 70cc0e7 commit d3a313c

10 files changed

+380
-1057
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,7 @@ __pycache__/
458458
*.whl
459459
.azure
460460
.github/copilot-instructions.md
461+
462+
# Bicep local files
463+
*.local*.bicepparam
464+
*.local*.parameters.json

infra/main.bicep

Lines changed: 135 additions & 61 deletions
Large diffs are not rendered by default.

infra/main.parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"existingLogAnalyticsWorkspaceId": {
3636
"value": "${AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID}"
3737
},
38-
"existingFoundryProjectResourceId": {
38+
"existingAiFoundryAiProjectResourceId": {
3939
"value": "${AZURE_ENV_FOUNDRY_PROJECT_ID}"
4040
}
4141
}

infra/main.waf.parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"existingLogAnalyticsWorkspaceId": {
5151
"value": "${AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID}"
5252
},
53-
"existingFoundryProjectResourceId": {
53+
"existingAiFoundryAiProjectResourceId": {
5454
"value": "${AZURE_ENV_FOUNDRY_PROJECT_ID}"
5555
}
5656
}

infra/modules/ai-project.bicep

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@description('Required. Name of the AI Services project.')
2+
param name string
3+
4+
@description('Required. The location of the Project resource.')
5+
param location string = resourceGroup().location
6+
7+
@description('Optional. The description of the AI Foundry project to create. Defaults to the project name.')
8+
param desc string = name
9+
10+
@description('Required. Name of the existing Cognitive Services resource to create the AI Foundry project in.')
11+
param aiServicesName string
12+
13+
@description('Optional. Tags to be applied to the resources.')
14+
param tags object = {}
15+
16+
// Reference to cognitive service in current resource group for new projects
17+
resource cogServiceReference 'Microsoft.CognitiveServices/accounts@2025-06-01' existing = {
18+
name: aiServicesName
19+
}
20+
21+
resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-06-01' = {
22+
parent: cogServiceReference
23+
name: name
24+
tags: tags
25+
location: location
26+
identity: {
27+
type: 'SystemAssigned'
28+
}
29+
properties: {
30+
description: desc
31+
displayName: name
32+
}
33+
}
34+
35+
@description('Required. Name of the AI project.')
36+
output name string = aiProject.name
37+
38+
@description('Required. Resource ID of the AI project.')
39+
output resourceId string = aiProject.id
40+
41+
@description('Required. API endpoint for the AI project.')
42+
output apiEndpoint string = aiProject!.properties.endpoints['AI Foundry API']
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
@description('Required. The name of Cognitive Services account.')
2+
param name string
3+
4+
@description('Optional. SKU of the Cognitive Services account. Use \'Get-AzCognitiveServicesAccountSku\' to determine a valid combinations of \'kind\' and \'SKU\' for your Azure region.')
5+
@allowed([
6+
'C2'
7+
'C3'
8+
'C4'
9+
'F0'
10+
'F1'
11+
'S'
12+
'S0'
13+
'S1'
14+
'S10'
15+
'S2'
16+
'S3'
17+
'S4'
18+
'S5'
19+
'S6'
20+
'S7'
21+
'S8'
22+
'S9'
23+
])
24+
param sku string = 'S0'
25+
26+
import { deploymentType } from 'br:mcr.microsoft.com/bicep/avm/res/cognitive-services/account:0.13.2'
27+
@description('Optional. Array of deployments about cognitive service accounts to create.')
28+
param deployments deploymentType[]?
29+
30+
import { roleAssignmentType } from 'br/public:avm/utl/types/avm-common-types:0.5.1'
31+
@description('Optional. Array of role assignments to create.')
32+
param roleAssignments roleAssignmentType[]?
33+
34+
var builtInRoleNames = {
35+
'Cognitive Services Contributor': subscriptionResourceId(
36+
'Microsoft.Authorization/roleDefinitions',
37+
'25fbc0a9-bd7c-42a3-aa1a-3b75d497ee68'
38+
)
39+
'Cognitive Services Custom Vision Contributor': subscriptionResourceId(
40+
'Microsoft.Authorization/roleDefinitions',
41+
'c1ff6cc2-c111-46fe-8896-e0ef812ad9f3'
42+
)
43+
'Cognitive Services Custom Vision Deployment': subscriptionResourceId(
44+
'Microsoft.Authorization/roleDefinitions',
45+
'5c4089e1-6d96-4d2f-b296-c1bc7137275f'
46+
)
47+
'Cognitive Services Custom Vision Labeler': subscriptionResourceId(
48+
'Microsoft.Authorization/roleDefinitions',
49+
'88424f51-ebe7-446f-bc41-7fa16989e96c'
50+
)
51+
'Cognitive Services Custom Vision Reader': subscriptionResourceId(
52+
'Microsoft.Authorization/roleDefinitions',
53+
'93586559-c37d-4a6b-ba08-b9f0940c2d73'
54+
)
55+
'Cognitive Services Custom Vision Trainer': subscriptionResourceId(
56+
'Microsoft.Authorization/roleDefinitions',
57+
'0a5ae4ab-0d65-4eeb-be61-29fc9b54394b'
58+
)
59+
'Cognitive Services Data Reader (Preview)': subscriptionResourceId(
60+
'Microsoft.Authorization/roleDefinitions',
61+
'b59867f0-fa02-499b-be73-45a86b5b3e1c'
62+
)
63+
'Cognitive Services Face Recognizer': subscriptionResourceId(
64+
'Microsoft.Authorization/roleDefinitions',
65+
'9894cab4-e18a-44aa-828b-cb588cd6f2d7'
66+
)
67+
'Cognitive Services Immersive Reader User': subscriptionResourceId(
68+
'Microsoft.Authorization/roleDefinitions',
69+
'b2de6794-95db-4659-8781-7e080d3f2b9d'
70+
)
71+
'Cognitive Services Language Owner': subscriptionResourceId(
72+
'Microsoft.Authorization/roleDefinitions',
73+
'f07febfe-79bc-46b1-8b37-790e26e6e498'
74+
)
75+
'Cognitive Services Language Reader': subscriptionResourceId(
76+
'Microsoft.Authorization/roleDefinitions',
77+
'7628b7b8-a8b2-4cdc-b46f-e9b35248918e'
78+
)
79+
'Cognitive Services Language Writer': subscriptionResourceId(
80+
'Microsoft.Authorization/roleDefinitions',
81+
'f2310ca1-dc64-4889-bb49-c8e0fa3d47a8'
82+
)
83+
'Cognitive Services LUIS Owner': subscriptionResourceId(
84+
'Microsoft.Authorization/roleDefinitions',
85+
'f72c8140-2111-481c-87ff-72b910f6e3f8'
86+
)
87+
'Cognitive Services LUIS Reader': subscriptionResourceId(
88+
'Microsoft.Authorization/roleDefinitions',
89+
'18e81cdc-4e98-4e29-a639-e7d10c5a6226'
90+
)
91+
'Cognitive Services LUIS Writer': subscriptionResourceId(
92+
'Microsoft.Authorization/roleDefinitions',
93+
'6322a993-d5c9-4bed-b113-e49bbea25b27'
94+
)
95+
'Cognitive Services Metrics Advisor Administrator': subscriptionResourceId(
96+
'Microsoft.Authorization/roleDefinitions',
97+
'cb43c632-a144-4ec5-977c-e80c4affc34a'
98+
)
99+
'Cognitive Services Metrics Advisor User': subscriptionResourceId(
100+
'Microsoft.Authorization/roleDefinitions',
101+
'3b20f47b-3825-43cb-8114-4bd2201156a8'
102+
)
103+
'Cognitive Services OpenAI Contributor': subscriptionResourceId(
104+
'Microsoft.Authorization/roleDefinitions',
105+
'a001fd3d-188f-4b5d-821b-7da978bf7442'
106+
)
107+
'Cognitive Services OpenAI User': subscriptionResourceId(
108+
'Microsoft.Authorization/roleDefinitions',
109+
'5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
110+
)
111+
'Cognitive Services QnA Maker Editor': subscriptionResourceId(
112+
'Microsoft.Authorization/roleDefinitions',
113+
'f4cc2bf9-21be-47a1-bdf1-5c5804381025'
114+
)
115+
'Cognitive Services QnA Maker Reader': subscriptionResourceId(
116+
'Microsoft.Authorization/roleDefinitions',
117+
'466ccd10-b268-4a11-b098-b4849f024126'
118+
)
119+
'Cognitive Services Speech Contributor': subscriptionResourceId(
120+
'Microsoft.Authorization/roleDefinitions',
121+
'0e75ca1e-0464-4b4d-8b93-68208a576181'
122+
)
123+
'Cognitive Services Speech User': subscriptionResourceId(
124+
'Microsoft.Authorization/roleDefinitions',
125+
'f2dc8367-1007-4938-bd23-fe263f013447'
126+
)
127+
'Cognitive Services User': subscriptionResourceId(
128+
'Microsoft.Authorization/roleDefinitions',
129+
'a97b65f3-24c7-4388-baec-2e87135dc908'
130+
)
131+
'Azure AI Developer': subscriptionResourceId(
132+
'Microsoft.Authorization/roleDefinitions',
133+
'64702f94-c441-49e6-a78b-ef80e0188fee'
134+
)
135+
Contributor: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
136+
Owner: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '8e3af657-a8ff-443c-a75c-2fe8c4bcb635')
137+
Reader: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7')
138+
'Role Based Access Control Administrator': subscriptionResourceId(
139+
'Microsoft.Authorization/roleDefinitions',
140+
'f58310d9-a9f6-439a-9e8d-f62e7b41a168'
141+
)
142+
'User Access Administrator': subscriptionResourceId(
143+
'Microsoft.Authorization/roleDefinitions',
144+
'18d7d88d-d35e-4fb5-a5c3-7773c20a72d9'
145+
)
146+
}
147+
148+
var formattedRoleAssignments = [
149+
for (roleAssignment, index) in (roleAssignments ?? []): union(roleAssignment, {
150+
roleDefinitionId: builtInRoleNames[?roleAssignment.roleDefinitionIdOrName] ?? (contains(
151+
roleAssignment.roleDefinitionIdOrName,
152+
'/providers/Microsoft.Authorization/roleDefinitions/'
153+
)
154+
? roleAssignment.roleDefinitionIdOrName
155+
: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleAssignment.roleDefinitionIdOrName))
156+
})
157+
]
158+
159+
resource cognitiveService 'Microsoft.CognitiveServices/accounts@2025-06-01' existing = {
160+
name: name
161+
}
162+
163+
@batchSize(1)
164+
resource cognitiveService_deployments 'Microsoft.CognitiveServices/accounts/deployments@2024-10-01' = [
165+
for (deployment, index) in (deployments ?? []): {
166+
parent: cognitiveService
167+
name: deployment.?name ?? '${name}-deployments'
168+
properties: {
169+
model: deployment.model
170+
raiPolicyName: deployment.?raiPolicyName
171+
versionUpgradeOption: deployment.?versionUpgradeOption
172+
}
173+
sku: deployment.?sku ?? {
174+
name: sku
175+
capacity: sku.?capacity
176+
tier: sku.?tier
177+
size: sku.?size
178+
family: sku.?family
179+
}
180+
}
181+
]
182+
183+
resource cognitiveService_roleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = [
184+
for (roleAssignment, index) in (formattedRoleAssignments ?? []): {
185+
name: roleAssignment.?name ?? guid(cognitiveService.id, roleAssignment.principalId, roleAssignment.roleDefinitionId)
186+
properties: {
187+
roleDefinitionId: roleAssignment.roleDefinitionId
188+
principalId: roleAssignment.principalId
189+
description: roleAssignment.?description
190+
principalType: roleAssignment.?principalType
191+
condition: roleAssignment.?condition
192+
conditionVersion: !empty(roleAssignment.?condition) ? (roleAssignment.?conditionVersion ?? '2.0') : null // Must only be set if condtion is set
193+
delegatedManagedIdentityResourceId: roleAssignment.?delegatedManagedIdentityResourceId
194+
}
195+
scope: cognitiveService
196+
}
197+
]

0 commit comments

Comments
 (0)