Skip to content

Commit 65126ac

Browse files
author
Shreyas-Microsoft
committed
Use Existing ai project
1 parent 40b870a commit 65126ac

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

infra/main.bicep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ param gptModelVersion string = '2024-08-06'
9595

9696
param existingLogAnalyticsWorkspaceId string = ''
9797

98+
@description('Use this parameter to use an existing AI project resource ID')
99+
param azureExistingAIProjectResourceId string = ''
100+
98101
var allTags = union(
99102
{
100103
'azd-env-name': solutionName
@@ -225,6 +228,7 @@ module aiServices 'modules/ai-foundry/main.bicep' = {
225228
deployments: [modelDeployment]
226229
projectName: 'proj-${resourcesName}'
227230
logAnalyticsWorkspaceResourceId: enableMonitoring ? logAnalyticsWorkspaceResourceId : ''
231+
azureExistingAIProjectResourceId: azureExistingAIProjectResourceId
228232
privateNetworking: enablePrivateNetworking
229233
? {
230234
virtualNetworkResourceId: network.outputs.vnetResourceId

infra/main.parameters.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"existingLogAnalyticsWorkspaceId": {
2727
"value": "${AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID}"
2828
},
29+
"azureExistingAIProjectResourceId": {
30+
"value": "AZURE_EXISTING_AI_PROJECT_RESOURCE_ID"
31+
},
2932
"secondaryLocation": {
3033
"value": "${AZURE_ENV_COSMOS_SECONDARY_LOCATION}"
3134
},

infra/modules/ai-foundry/main.bicep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ param projectDescription string = projectName
6060
@description('Optional. The resource ID of the Log Analytics workspace to use for diagnostic settings.')
6161
param logAnalyticsWorkspaceResourceId string?
6262

63+
@description('Optional. Use this parameter to use an existing AI project resource ID')
64+
param azureExistingAIProjectResourceId string?
65+
6366
import { deploymentType } from 'br/public:avm/res/cognitive-services/account:0.10.2'
6467
@description('Optional. Specifies the OpenAI deployments to create.')
6568
param deployments deploymentType[] = []
@@ -188,6 +191,7 @@ module aiProject 'project.bicep' = {
188191
roleAssignments: roleAssignments
189192
tags: tags
190193
enableTelemetry: enableTelemetry
194+
azureExistingAIProjectResourceId: azureExistingAIProjectResourceId
191195
}
192196
}
193197

infra/modules/ai-foundry/project.bicep

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ param tags object = {}
2020
@description('Optional. Enable/Disable usage telemetry for module.')
2121
param enableTelemetry bool = true
2222

23+
@description('Optional. Use this parameter to use an existing AI project resource ID')
24+
param azureExistingAIProjectResourceId string?
25+
26+
// Endpoint from existing AI Project Resource ID if provided
27+
var existingProjEndpoint = !empty(azureExistingAIProjectResourceId) ?
28+
format('https://{0}.services.ai.azure.com/api/projects/{1}',
29+
split(azureExistingAIProjectResourceId, '/')[8], split(azureExistingAIProjectResourceId, '/')
30+
[10]) : ''
31+
2332
// using a few built-in roles here that makes sense for Foundry projects only
2433
var builtInRoleNames = {
2534
'Cognitive Services OpenAI Contributor': subscriptionResourceId(
@@ -55,7 +64,7 @@ resource cogServiceReference 'Microsoft.CognitiveServices/accounts@2024-10-01' e
5564
name: aiServicesName
5665
}
5766

58-
resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' = {
67+
resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' = if (empty(azureExistingAIProjectResourceId)) {
5968
parent: cogServiceReference
6069
name: name
6170
tags: tags
@@ -89,7 +98,7 @@ output name string = aiProject.name
8998
output resourceId string = aiProject.id
9099

91100
@description('API endpoint for the AI Foundry project.')
92-
output apiEndpoint string = aiProject.properties.endpoints['AI Foundry API']
101+
output apiEndpoint string = !empty(existingProjEndpoint) ? existingProjEndpoint : aiProject.properties.endpoints['AI Foundry API']
93102

94103
@export()
95104
@description('Output type representing AI project information.')

0 commit comments

Comments
 (0)