Skip to content

Commit 8ec88b6

Browse files
author
Shreyas-Microsoft
committed
bicep changes
1 parent ac5ca77 commit 8ec88b6

2 files changed

Lines changed: 112 additions & 52 deletions

File tree

infra/deploy_ai_foundry.bicep

Lines changed: 111 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,16 @@ var existingLawName = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[
2222
var abbrs = loadJsonContent('./abbreviations.json')
2323

2424
var storageName = '${abbrs.storage.storageAccount}${solutionName}'
25-
2625
var storageSkuName = 'Standard_LRS'
2726
var aiServicesName = '${abbrs.ai.aiServices}${solutionName}'
2827
var workspaceName = '${abbrs.managementGovernance.logAnalyticsWorkspace}${solutionName}'
2928
var keyvaultName = '${abbrs.security.keyVault}${solutionName}'
3029
var location = solutionLocation
31-
var azureAiHubName = '${abbrs.ai.aiHub}${solutionName}'
32-
var aiHubFriendlyName = azureAiHubName
33-
var aiHubDescription = 'AI Hub for KM template'
3430
var aiProjectName = '${abbrs.ai.aiHubProject}${solutionName}'
3531
var aiProjectFriendlyName = aiProjectName
3632
var aiSearchName = '${solutionName}-search'
3733
var applicationInsightsName = '${solutionName}-appi'
3834

39-
40-
4135
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
4236
name: keyVaultName
4337
}
@@ -73,9 +67,6 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
7367

7468
var storageNameCleaned = replace(replace(replace(replace('${storageName}cast', '-', ''), '_', ''), '.', ''),'/', '')
7569

76-
77-
78-
7970
resource storage 'Microsoft.Storage/storageAccounts@2022-09-01' = {
8071
name: storageNameCleaned
8172
location: location
@@ -128,6 +119,30 @@ resource storage 'Microsoft.Storage/storageAccounts@2022-09-01' = {
128119
}
129120
}
130121

122+
// Create AI Services resource (pavan approach)
123+
resource aiServices 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' = {
124+
name: aiServicesName
125+
location: location
126+
sku: {
127+
name: 'S0'
128+
}
129+
kind: 'AIServices'
130+
identity: {
131+
type: 'SystemAssigned'
132+
}
133+
properties: {
134+
allowProjectManagement: true
135+
customSubDomainName: aiServicesName
136+
networkAcls: {
137+
defaultAction: 'Allow'
138+
virtualNetworkRules: []
139+
ipRules: []
140+
}
141+
publicNetworkAccess: 'Enabled'
142+
disableLocalAuth: false //needs to be false to access keys
143+
}
144+
}
145+
131146
@description('This is the built-in Storage Blob Data Contributor.')
132147
resource blobDataContributor 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
133148
scope: subscription()
@@ -144,51 +159,93 @@ resource storageroleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-
144159
}
145160
}
146161

147-
resource aiHub 'Microsoft.MachineLearningServices/workspaces@2023-08-01-preview' = {
148-
name: azureAiHubName
149-
location: location
150-
identity: {
151-
type: 'SystemAssigned'
162+
resource storageroleAiServiceAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
163+
name: guid(resourceGroup().id, aiServices.id, blobDataContributor.id)
164+
scope: storage
165+
properties: {
166+
principalId: aiServices.identity.principalId
167+
roleDefinitionId: blobDataContributor.id
168+
principalType: 'ServicePrincipal'
169+
}
170+
}
171+
172+
resource cognitiveServicesUserRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
173+
scope: aiServices
174+
name: 'a97b65f3-24c7-4388-baec-2e87135dc908'
175+
}
176+
177+
resource cognitiveServicesUserAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
178+
name: guid(resourceGroup().id, managedIdentityObjectId, cognitiveServicesUserRoleDefinition.id)
179+
scope: aiServices
180+
properties: {
181+
principalId: managedIdentityObjectId
182+
roleDefinitionId: cognitiveServicesUserRoleDefinition.id
183+
principalType: 'ServicePrincipal'
152184
}
185+
}
186+
187+
resource cognitiveServicesUserAiServiceAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
188+
name: guid(resourceGroup().id, aiServices.id, cognitiveServicesUserRoleDefinition.id)
189+
scope: aiServices
153190
properties: {
154-
// organization
155-
friendlyName: aiHubFriendlyName
156-
description: aiHubDescription
157-
158-
// dependent resources
159-
keyVault: keyVault.id
160-
storageAccount: storage.id
161-
}
162-
kind: 'hub'
163-
164-
resource aiServicesConnection 'connections@2024-07-01-preview' = {
165-
name: '${azureAiHubName}-connection-AzureOpenAI'
166-
properties: {
167-
category: 'AIServices'
168-
target: aiServicesEndpoint
169-
authType: 'ApiKey'
170-
isSharedToAll: true
171-
credentials: {
172-
key: aiServicesKey
173-
}
174-
metadata: {
175-
ApiType: 'Azure'
176-
ResourceId: aiServicesId
177-
}
178-
}
191+
principalId: aiServices.identity.principalId
192+
roleDefinitionId: cognitiveServicesUserRoleDefinition.id
193+
principalType: 'ServicePrincipal'
194+
}
195+
}
196+
197+
resource aiDeveloperRoleDefinition 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
198+
scope: aiServices
199+
name: '64702f94-c441-49e6-a78b-ef80e0188fee'
200+
}
201+
202+
resource aiDeveloperAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
203+
name: guid(resourceGroup().id, managedIdentityObjectId, aiDeveloperRoleDefinition.id)
204+
scope: aiServices
205+
properties: {
206+
principalId: managedIdentityObjectId
207+
roleDefinitionId: aiDeveloperRoleDefinition.id
208+
principalType: 'ServicePrincipal'
179209
}
180210
}
181211

182-
resource aiHubProject 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' = {
212+
resource aiDeveloperAiServiceAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
213+
name: guid(resourceGroup().id, aiServices.id, aiDeveloperRoleDefinition.id)
214+
scope: aiServices
215+
properties: {
216+
principalId: aiServices.identity.principalId
217+
roleDefinitionId: aiDeveloperRoleDefinition.id
218+
principalType: 'ServicePrincipal'
219+
}
220+
}
221+
222+
// Create AI Project (pavan approach)
223+
resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' = {
224+
parent: aiServices
183225
name: aiProjectName
184-
location: location
185-
kind: 'Project'
226+
location: solutionLocation
227+
kind: 'AIServices'
186228
identity: {
187229
type: 'SystemAssigned'
188230
}
231+
properties: {}
232+
}
233+
234+
// Create project-level storage connection
235+
resource project_connection_azure_storage 'Microsoft.CognitiveServices/accounts/projects/connections@2025-04-01-preview' = {
236+
name: 'myStorageProjectConnectionName'
237+
parent: aiProject
189238
properties: {
190-
friendlyName: aiProjectFriendlyName
191-
hubResourceId: aiHub.id
239+
category: 'AzureBlob'
240+
target: storage.properties.primaryEndpoints.blob
241+
authType: 'AAD'
242+
metadata: {
243+
ApiType: 'Azure'
244+
ResourceId: storage.id
245+
location: storage.location
246+
containerName: 'ai-container'
247+
accountName: storage.name
248+
}
192249
}
193250
}
194251

@@ -220,7 +277,7 @@ resource azureOpenAIApiKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-pr
220277
parent: keyVault
221278
name: 'AZURE-OPENAI-KEY'
222279
properties: {
223-
value: aiServicesKey //aiServices_m.listKeys().key1
280+
value: aiServices.listKeys().key1
224281
}
225282
}
226283

@@ -244,15 +301,15 @@ resource azureOpenAIEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-
244301
parent: keyVault
245302
name: 'AZURE-OPENAI-ENDPOINT'
246303
properties: {
247-
value: aiServicesEndpoint//aiServices_m.properties.endpoint
304+
value: aiServices.properties.endpoints['OpenAI Language Model Instance API']
248305
}
249306
}
250307

251308
resource azureAIProjectConnectionStringEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
252309
parent: keyVault
253310
name: 'AZURE-AI-PROJECT-CONN-STRING'
254311
properties: {
255-
value: '${split(aiHubProject.properties.discoveryUrl, '/')[2]};${subscription().subscriptionId};${resourceGroup().name};${aiHubProject.name}'
312+
value: '${aiProjectName};${subscription().subscriptionId};${resourceGroup().name};${aiProject.name}'
256313
}
257314
}
258315

@@ -276,15 +333,15 @@ resource cogServiceEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-p
276333
parent: keyVault
277334
name: 'COG-SERVICES-ENDPOINT'
278335
properties: {
279-
value: aiServicesEndpoint
336+
value: aiServices.properties.endpoints['OpenAI Language Model Instance API']
280337
}
281338
}
282339

283340
resource cogServiceKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
284341
parent: keyVault
285342
name: 'COG-SERVICES-KEY'
286343
properties: {
287-
value: aiServicesKey
344+
value: aiServices.listKeys().key1
288345
}
289346
}
290347

@@ -324,13 +381,16 @@ output keyvaultName string = keyvaultName
324381
output keyvaultId string = keyVault.id
325382

326383
output aiServicesName string = aiServicesName
384+
output aiServicesTarget string = aiServices.properties.endpoints['OpenAI Language Model Instance API']
385+
output aiServicesId string = aiServices.id
327386
output aiSearchName string = aiSearchName
328-
output aiProjectName string = aiHubProject.name
387+
output aiProjectName string = aiProject.name
329388

330389
output storageAccountName string = storageNameCleaned
331390

332391
output logAnalyticsId string = useExisting ? existingLogAnalyticsWorkspace.id : logAnalytics.id
333392
output storageAccountId string = storage.id
334393
output applicationInsightsConnectionString string = applicationInsights.properties.ConnectionString
335394

336-
output projectConnectionString string = '${split(aiHubProject.properties.discoveryUrl, '/')[2]};${subscription().subscriptionId};${resourceGroup().name};${aiHubProject.name}'
395+
output projectConnectionString string = '${aiProjectName};${subscription().subscriptionId};${resourceGroup().name};${aiProject.name}'
396+
output projectEndpoint string = aiProject.properties.endpoints['AI Foundry API']

src/backend/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ opentelemetry-api==1.31.1
5252
opentelemetry-semantic-conventions==0.52b1
5353
opentelemetry-instrumentation==0.52b1
5454
azure-monitor-opentelemetry==1.6.8
55-
azure-ai-projects==1.0.0b9
55+
azure-ai-projects==1.0.0b11

0 commit comments

Comments
 (0)