Skip to content

Commit 136cbd5

Browse files
updates for existing AI Foundry in Bicep & scripts
1 parent f7efc16 commit 136cbd5

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

docs/DeploymentGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Once you've opened the project in [Codespaces](#github-codespaces), [Dev Contain
175175
```
176176
If you don't have azd env then you need to pass parameters along with the command. Then the command will look like the following:
177177
```shell
178-
bash ./infra/scripts/process_sample_data.sh <Storage-Account-name> <Storage-Account-container-name> <Key-Vault-name> <CosmosDB-Account-name> <Resource-Group-name> <aiFoundryResourceName> <aiSearchResourceName>
178+
bash ./infra/scripts/process_sample_data.sh <Storage-Account-name> <Storage-Account-container-name> <Key-Vault-name> <CosmosDB-Account-name> <Resource-Group-name> <AI-Foundry-Name> <AI-Foundry-Resource-Group-Name> <Search-Service-Name>
179179
```
180180

181181
6. Open the [Azure Portal](https://portal.azure.com/), go to the deployed resource group, find the App Service and get the app URL from `Default domain`.

infra/deploy_ai_foundry.bicep

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
112112
}
113113
}
114114

115+
resource existingAiFoundry 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = if (!empty(azureExistingAIProjectResourceId)) {
116+
name: existingAIFoundryName
117+
scope: resourceGroup(existingAIServiceSubscription, existingAIServiceResourceGroup)
118+
}
119+
115120
resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' = if (empty(azureExistingAIProjectResourceId)) {
116121
name: aiFoundryName
117122
location: location
@@ -360,23 +365,27 @@ resource cogServiceEndpointEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-p
360365
parent: keyVault
361366
name: 'COG-SERVICES-ENDPOINT'
362367
properties: {
363-
value: aiFoundry.properties.endpoint
368+
value: !empty(existingOpenAIEndpoint)
369+
? existingOpenAIEndpoint
370+
: aiFoundry.properties.endpoint
364371
}
365372
}
366373

367374
resource cogServiceKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
368375
parent: keyVault
369376
name: 'COG-SERVICES-KEY'
370377
properties: {
371-
value: aiFoundry.listKeys().key1
378+
value: !empty(existingOpenAIEndpoint)
379+
? existingAiFoundry.listKeys().key1
380+
: aiFoundry.listKeys().key1
372381
}
373382
}
374383

375384
resource cogServiceNameEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
376385
parent: keyVault
377386
name: 'COG-SERVICES-NAME'
378387
properties: {
379-
value: aiFoundryName
388+
value: !empty(existingAIFoundryName) ? existingAIFoundryName : aiFoundryName
380389
}
381390
}
382391

@@ -407,9 +416,9 @@ resource azureLocatioEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview
407416
output keyvaultName string = keyvaultName
408417
output keyvaultId string = keyVault.id
409418

410-
output aiServicesTarget string = aiFoundry.properties.endpoint //aiServices_m.properties.endpoint
411-
output aiServicesName string = aiFoundryName //aiServicesName_m
412-
output aiServicesId string = aiFoundry.id //aiServices_m.id
419+
// output aiServicesTarget string = aiFoundry.properties.endpoint //aiServices_m.properties.endpoint
420+
// output aiServicesName string = aiFoundryName //aiServicesName_m
421+
// output aiServicesId string = aiFoundry.id //aiServices_m.id
413422

414423
output aiSearchName string = aiSearchName
415424
output aiSearchId string = aiSearch.id
@@ -426,6 +435,7 @@ output aoaiEndpoint string = !empty(existingOpenAIEndpoint)
426435
? existingOpenAIEndpoint
427436
: aiFoundry.properties.endpoints['OpenAI Language Model Instance API']
428437
output aiFoundryName string = !empty(existingAIFoundryName) ? existingAIFoundryName : aiFoundryName
438+
output aiFoundryRgName string = !empty(existingAIServiceResourceGroup) ? existingAIServiceResourceGroup : resourceGroup().name
429439

430440
output applicationInsightsId string = applicationInsights.id
431441
output logAnalyticsWorkspaceResourceName string = useExisting ? existingLogAnalyticsWorkspace.name : logAnalytics.name

infra/main.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,6 @@ output KEY_VAULT_NAME string = kvault.outputs.keyvaultName
199199
output COSMOSDB_ACCOUNT_NAME string = cosmosDBModule.outputs.cosmosAccountName
200200
output RESOURCE_GROUP_NAME string = resourceGroup().name
201201
output AI_FOUNDRY_NAME string = aifoundry.outputs.aiFoundryName
202+
output AI_FOUNDRY_RG_NAME string = aifoundry.outputs.aiFoundryRgName
202203
output AI_SEARCH_SERVICE_NAME string = aifoundry.outputs.aiSearchService
203204
output AZURE_SEARCH_CONNECTION_NAME string = aifoundry.outputs.aiSearchConnectionName

infra/scripts/process_sample_data.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ keyvaultName="$3"
77
cosmosDbAccountName="$4"
88
resourceGroupName="$5"
99
aiFoundryName="$6"
10-
aiSearchName="$7"
11-
managedIdentityClientId="$8"
10+
aiFoundryRgName="$7"
11+
aiSearchName="$8"
12+
managedIdentityClientId="$9"
1213

1314
# get parameters from azd env, if not provided
1415
if [ -z "$resourceGroupName" ]; then
@@ -35,15 +36,19 @@ if [ -z "$aiFoundryName" ]; then
3536
aiFoundryName=$(azd env get-value AI_FOUNDRY_NAME)
3637
fi
3738

39+
if [ -z "$aiFoundryRgName" ]; then
40+
aiFoundryRgName=$(azd env get-value AI_FOUNDRY_RG_NAME)
41+
fi
42+
3843
if [ -z "$aiSearchName" ]; then
3944
aiSearchName=$(azd env get-value AI_SEARCH_SERVICE_NAME)
4045
fi
4146

4247
azSubscriptionId=$(azd env get-value AZURE_SUBSCRIPTION_ID)
4348

4449
# Check if all required arguments are provided
45-
if [ -z "$storageAccount" ] || [ -z "$fileSystem" ] || [ -z "$keyvaultName" ] || [ -z "$cosmosDbAccountName" ] || [ -z "$resourceGroupName" ] || [ -z "$aiFoundryName" ] || [ -z "$aiSearchName" ]; then
46-
echo "Usage: $0 <storageAccount> <storageContainerName> <keyvaultName> <cosmosDbAccountName> <resourceGroupName> <aiFoundryName> <aiSearchName>"
50+
if [ -z "$storageAccount" ] || [ -z "$fileSystem" ] || [ -z "$keyvaultName" ] || [ -z "$cosmosDbAccountName" ] || [ -z "$resourceGroupName" ] || [ -z "$aiFoundryName" ] || [ -z "$aiFoundryRgName" ] || [ -z "$aiSearchName" ]; then
51+
echo "Usage: $0 <storageAccount> <storageContainerName> <keyvaultName> <cosmosDbAccountName> <resourceGroupName> <aiFoundryName> <aiFoundryRgName> <aiSearchName>"
4752
exit 1
4853
fi
4954

@@ -125,7 +130,7 @@ echo "copy_kb_files.sh completed successfully."
125130

126131
# Call run_create_index_scripts.sh
127132
echo "Running run_create_index_scripts.sh"
128-
bash infra/scripts/run_create_index_scripts.sh "$keyvaultName" "$resourceGroupName" "$aiFoundryName" "$aiSearchName" "$managedIdentityClientId"
133+
bash infra/scripts/run_create_index_scripts.sh "$keyvaultName" "$resourceGroupName" "$aiFoundryName" "$aiFoundryRgName" "$aiSearchName" "$managedIdentityClientId"
129134
if [ $? -ne 0 ]; then
130135
echo "Error: run_create_index_scripts.sh failed."
131136
exit 1

infra/scripts/run_create_index_scripts.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
keyvaultName="$1"
66
resourceGroupName="$2"
77
aiFoundryName="$3"
8-
aiSearchName="$4"
9-
managedIdentityClientId="$5"
8+
aiFoundryRgName="$4"
9+
aiSearchName="$5"
10+
managedIdentityClientId="$6"
1011
# requirementFile="infra/scripts/index_scripts/requirements.txt"
1112
# requirementFileUrl=${baseUrl}"infra/scripts/index_scripts/requirements.txt"
1213

@@ -66,7 +67,7 @@ fi
6667
### Assign Azure AI User role to the signed in user ###
6768

6869
echo "Getting Azure AI resource id"
69-
aif_resource_id=$(az cognitiveservices account show --name $aiFoundryName --resource-group $resourceGroupName --query id --output tsv)
70+
aif_resource_id=$(az cognitiveservices account show --name $aiFoundryName --resource-group $aiFoundryRgName --query id --output tsv)
7071

7172
# Check if the user has the Azure AI User role
7273
echo "Checking if user has the Azure AI User role"

0 commit comments

Comments
 (0)