@@ -22,22 +22,16 @@ var existingLawName = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[
2222var abbrs = loadJsonContent ('./abbreviations.json' )
2323
2424var storageName = '${abbrs .storage .storageAccount }${solutionName }'
25-
2625var storageSkuName = 'Standard_LRS'
2726var aiServicesName = '${abbrs .ai .aiServices }${solutionName }'
2827var workspaceName = '${abbrs .managementGovernance .logAnalyticsWorkspace }${solutionName }'
2928var keyvaultName = '${abbrs .security .keyVault }${solutionName }'
3029var location = solutionLocation
31- var azureAiHubName = '${abbrs .ai .aiHub }${solutionName }'
32- var aiHubFriendlyName = azureAiHubName
33- var aiHubDescription = 'AI Hub for KM template'
3430var aiProjectName = '${abbrs .ai .aiHubProject }${solutionName }'
3531var aiProjectFriendlyName = aiProjectName
3632var aiSearchName = '${solutionName }-search'
3733var applicationInsightsName = '${solutionName }-appi'
3834
39-
40-
4135resource 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
7468var storageNameCleaned = replace (replace (replace (replace ('${storageName }cast' , '-' , '' ), '_' , '' ), '.' , '' ),'/' , '' )
7569
76-
77-
78-
7970resource 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.' )
132147resource 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
251308resource 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
283340resource 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
324381output keyvaultId string = keyVault .id
325382
326383output aiServicesName string = aiServicesName
384+ output aiServicesTarget string = aiServices .properties .endpoints ['OpenAI Language Model Instance API' ]
385+ output aiServicesId string = aiServices .id
327386output aiSearchName string = aiSearchName
328- output aiProjectName string = aiHubProject .name
387+ output aiProjectName string = aiProject .name
329388
330389output storageAccountName string = storageNameCleaned
331390
332391output logAnalyticsId string = useExisting ? existingLogAnalyticsWorkspace .id : logAnalytics .id
333392output storageAccountId string = storage .id
334393output 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' ]
0 commit comments