Skip to content

Commit 2f89864

Browse files
Merge pull request #640 from microsoft/psl-bug-21342
fix: Sample data processing script fails when using cross-subscription existing AI project resource ID
2 parents 12b99bb + a8e25dd commit 2f89864

File tree

11 files changed

+97
-61
lines changed

11 files changed

+97
-61
lines changed

.github/workflows/CAdeploy.yml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- dev
88
- demo
99
schedule:
10-
- cron: '0 6,18 * * *' # Runs at 6:00 AM and 6:00 PM GMT
10+
- cron: "0 6,18 * * *" # Runs at 6:00 AM and 6:00 PM GMT
1111

1212
env:
1313
GPT_MIN_CAPACITY: 200
@@ -29,7 +29,6 @@ jobs:
2929
steps:
3030
- name: Checkout
3131
uses: actions/checkout@v4
32-
3332
- name: Install ODBC Driver 18 for SQL Server
3433
run: |
3534
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
@@ -81,7 +80,6 @@ jobs:
8180

8281
- name: Install Bicep CLI
8382
run: az bicep install
84-
8583
- name: Set Deployment Region
8684
id: set_region
8785
run: |
@@ -98,7 +96,6 @@ jobs:
9896
UNIQUE_RG_NAME="arg-${ACCL_NAME}-${SHORT_UUID}"
9997
echo "RESOURCE_GROUP_NAME=${UNIQUE_RG_NAME}" >> $GITHUB_ENV
10098
echo "Generated RESOURCE_GROUP_NAME: ${UNIQUE_RG_NAME}"
101-
10299
- name: Check and Create Resource Group
103100
id: check_create_rg
104101
run: |
@@ -114,7 +111,6 @@ jobs:
114111
fi
115112
# Set output for other jobs
116113
echo "RESOURCE_GROUP_NAME=${{ env.RESOURCE_GROUP_NAME }}" >> $GITHUB_OUTPUT
117-
118114
- name: Generate Unique Solution Prefix
119115
id: generate_solution_prefix
120116
run: |
@@ -137,7 +133,6 @@ jobs:
137133
else TAG="latest"; fi
138134
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
139135
echo "Image Tag: $TAG"
140-
141136
- name: Deploy and extract values from deployment output
142137
id: get_output
143138
run: |
@@ -152,16 +147,14 @@ jobs:
152147
--parameters aiDeploymentsLocation=${{ env.AZURE_LOCATION }} environmentName=${{ env.SOLUTION_PREFIX }} cosmosLocation=westus gptDeploymentCapacity=${{ env.GPT_MIN_CAPACITY }} embeddingDeploymentCapacity=${{ env.TEXT_EMBEDDING_MIN_CAPACITY }} imageTag=${{ env.IMAGE_TAG }} \
153148
--query "properties.outputs" -o json)
154149
155-
156-
157150
echo "Deployment output: $DEPLOY_OUTPUT"
158151
if [[ -z "$DEPLOY_OUTPUT" ]]; then
159152
echo "Error: Deployment output is empty. Please check the deployment logs."
160153
exit 1
161154
fi
162155
163-
export AI_FOUNDARY_NAME=$(echo "$DEPLOY_OUTPUT" | jq -r '.aI_FOUNDRY_NAME.value')
164-
echo "AI_FOUNDARY_NAME=$AI_FOUNDARY_NAME" >> $GITHUB_ENV
156+
export AI_FOUNDRY_RESOURCE_ID=$(echo "$DEPLOY_OUTPUT" | jq -r '.AI_FOUNDRY_RESOURCE_ID.value')
157+
echo "AI_FOUNDRY_RESOURCE_ID=$AI_FOUNDRY_RESOURCE_ID" >> $GITHUB_ENV
165158
export SEARCH_SERVICE_NAME=$(echo "$DEPLOY_OUTPUT" | jq -r '.aI_SEARCH_SERVICE_NAME.value')
166159
echo "SEARCH_SERVICE_NAME=$SEARCH_SERVICE_NAME" >> $GITHUB_ENV
167160
export COSMOS_DB_ACCOUNT_NAME=$(echo "$DEPLOY_OUTPUT" | jq -r '.cosmosdB_ACCOUNT_NAME.value')
@@ -182,8 +175,6 @@ jobs:
182175
echo "CLIENT_NAME=$CLIENT_NAME" >> $GITHUB_ENV
183176
export RG_NAME=$(echo "$DEPLOY_OUTPUT" | jq -r '.resourcE_GROUP_NAME.value')
184177
echo "RG_NAME=$RG_NAME" >> $GITHUB_ENV
185-
export RESOURCE_GROUP_NAME_FOUNDRY=$(echo "$DEPLOY_OUTPUT" | jq -r '.resourcE_GROUP_NAME_FOUNDRY.value')
186-
echo "RESOURCE_GROUP_NAME_FOUNDRY=$RESOURCE_GROUP_NAME_FOUNDRY" >> $GITHUB_ENV
187178
WEBAPP_URL=$(echo $DEPLOY_OUTPUT | jq -r '.weB_APP_URL.value')
188179
echo "WEBAPP_URL=$WEBAPP_URL" >> $GITHUB_OUTPUT
189180
WEB_APP_NAME=$(echo $DEPLOY_OUTPUT | jq -r '.weB_APP_NAME.value')
@@ -195,9 +186,7 @@ jobs:
195186
196187
sleep 30
197188
198-
199-
200-
- name: Deploy Infra and Import Sample Data
189+
- name: Deploy Infra and Import Sample Data
201190
run: |
202191
set -e
203192
az account set --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
@@ -221,9 +210,8 @@ jobs:
221210
"${{ secrets.AZURE_CLIENT_ID }}" \
222211
"${{ env.RG_NAME }}" \
223212
"${{ env.SQL_SERVER_NAME }}" \
224-
"${{ env.AI_FOUNDARY_NAME }}" \
225213
"${{ env.SEARCH_SERVICE_NAME }}" \
226-
"${{ env.RESOURCE_GROUP_NAME_FOUNDRY }}"
214+
"${{ env.AI_FOUNDRY_RESOURCE_ID}}"
227215
228216
229217
user_roles_json='[
@@ -236,9 +224,7 @@ jobs:
236224
"${{ env.SQL_DATABASE }}" \
237225
"$user_roles_json" \
238226
"${{ secrets.AZURE_CLIENT_ID }}"
239-
240227
echo "=== Post-Deployment Script Completed Successfully ==="
241-
242228
243229
- name: Get AI Services name and store in variable
244230
if: always() && steps.check_create_rg.outcome == 'success'
@@ -262,7 +248,6 @@ jobs:
262248
run: |
263249
set -e
264250
echo "Listing all KeyVaults in the resource group ${{ env.RESOURCE_GROUP_NAME }}..."
265-
266251
# Get the list of KeyVaults in the specified resource group
267252
keyvaults=$(az resource list --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "[?type=='Microsoft.KeyVault/vaults'].name" -o tsv)
268253
@@ -288,7 +273,6 @@ jobs:
288273
# Output the formatted array and save it to the job output
289274
echo "KEYVAULTS=$keyvault_array" >> $GITHUB_OUTPUT
290275
fi
291-
292276
- name: Set Deployment Status
293277
id: deployment_status
294278
if: always()
@@ -312,7 +296,7 @@ jobs:
312296
secrets: inherit
313297

314298
cleanup:
315-
if: always()
299+
if: always()
316300
needs: [deploy, e2e-test]
317301
runs-on: ubuntu-latest
318302
env:
@@ -336,12 +320,10 @@ jobs:
336320
set -e
337321
echo "Checking if resource group exists..."
338322
echo "Resource group name: ${{ env.RESOURCE_GROUP_NAME }}"
339-
340323
if [ -z "${{ env.RESOURCE_GROUP_NAME }}" ]; then
341324
echo "Resource group name is empty. Skipping deletion."
342325
exit 0
343326
fi
344-
345327
rg_exists=$(az group exists --name "${{ env.RESOURCE_GROUP_NAME }}")
346328
if [ "$rg_exists" = "true" ]; then
347329
echo "Resource group exists. Cleaning..."
@@ -368,12 +350,9 @@ jobs:
368350
369351
# Remove the surrounding square brackets and quotes, if they exist
370352
stripped_keyvaults=$(echo "$KEYVAULTS" | sed 's/\[\|\]//g' | sed 's/"//g')
371-
372353
# Convert the comma-separated string into an array
373354
IFS=',' read -r -a resources_to_check <<< "$stripped_keyvaults"
374-
375355
echo "List of resources to check: ${resources_to_check[@]}"
376-
377356
# Check if resource group still exists before listing resources
378357
rg_exists=$(az group exists --name "${{ env.RESOURCE_GROUP_NAME }}")
379358
if [ "$rg_exists" = "false" ]; then
@@ -472,7 +451,6 @@ jobs:
472451
473452
# Remove the surrounding square brackets and quotes, if they exist
474453
stripped_keyvaults=$(echo "$KEYVAULTS" | sed 's/\[\|\]//g' | sed 's/"//g')
475-
476454
# Convert the comma-separated string into an array
477455
IFS=',' read -r -a keyvault_array <<< "$stripped_keyvaults"
478456
@@ -506,15 +484,13 @@ jobs:
506484
if: failure() || needs.deploy.result == 'failure' || needs.e2e-test.result == 'failure'
507485
run: |
508486
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
509-
510487
# Construct the email body
511488
EMAIL_BODY=$(cat <<EOF
512489
{
513490
"body": "<p>Dear Team,</p><p>We would like to inform you that the Build-your-own-copilot-Solution-Accelerator(Client Advisior) Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Build URL:</strong> ${RUN_URL}<br> ${OUTPUT}</p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>"
514491
}
515492
EOF
516493
)
517-
518494
# Send the notification
519495
curl -X POST "${{ secrets.LOGIC_APP_URL }}" \
520496
-H "Content-Type: application/json" \

docs/DeploymentGuide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ To adjust quota settings, follow these [steps](./AzureGPTQuotaSettings.md).
143143

144144
Guide to get your [Existing Workspace ID](/docs/re-use-log-analytics.md)
145145

146+
</details>
147+
<details>
148+
149+
<summary><b>Reusing an Existing Azure AI Foundry Project</b></summary>
150+
151+
Guide to get your [Existing Project ID](/docs/re-use-foundry-project.md)
152+
146153
</details>
147154

148155
### Deploying with AZD
331 KB
Loading
94.9 KB
Loading
196 KB
Loading

docs/re-use-foundry-project.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[← Back to *DEPLOYMENT* guide](/docs/DeploymentGuide.md#deployment-options--steps)
2+
3+
# Reusing an Existing Azure AI Foundry Project
4+
To configure your environment to use an existing Azure AI Foundry Project, follow these steps:
5+
---
6+
### 1. Go to Azure Portal
7+
Go to https://portal.azure.com
8+
9+
### 2. Search for Azure AI Foundry
10+
In the search bar at the top, type "Azure AI Foundry" and click on it. Then select the Foundry service instance where your project exists.
11+
12+
![alt text](../docs/images/re_use_foundry_project/azure_ai_foundry_list.png)
13+
14+
### 3. Navigate to Projects under Resource Management
15+
On the left sidebar of the Foundry service blade:
16+
17+
- Expand the Resource Management section
18+
- Click on Projects (this refers to the active Foundry project tied to the service)
19+
20+
### 4. Click on the Project
21+
From the Projects view: Click on the project name to open its details
22+
23+
Note: You will see only one project listed here, as each Foundry service maps to a single project in this accelerator
24+
25+
![alt text](../docs/images/re_use_foundry_project/navigate_to_projects.png)
26+
27+
### 5. Copy Resource ID
28+
In the left-hand menu of the project blade:
29+
30+
- Click on Properties under Resource Management
31+
- Locate the Resource ID field
32+
- Click on the copy icon next to the Resource ID value
33+
34+
![alt text](../docs/images/re_use_foundry_project/project_resource_id.png)
35+
36+
### 6. Set the Foundry Project Resource ID in Your Environment
37+
Run the following command in your terminal
38+
```bash
39+
azd env set AZURE_EXISTING_AI_PROJECT_RESOURCE_ID '<Existing AI Project Resource ID>'
40+
```
41+
Replace `<Existing AI Project Resource ID>` with the value obtained from Step 5.
42+
43+
### 7. Continue Deployment
44+
Proceed with the next steps in the [deployment guide](/documents/DeploymentGuide.md#deployment-options--steps).

infra/deploy_ai_foundry.bicep

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ resource aiFoundryProject 'Microsoft.CognitiveServices/accounts/projects@2025-04
146146
}
147147
}
148148

149+
resource existingAiFoundry 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = if (!empty(azureExistingAIProjectResourceId)) {
150+
name: existingAIFoundryName
151+
scope: resourceGroup(existingAIServiceSubscription, existingAIServiceResourceGroup)
152+
}
153+
149154
@batchSize(1)
150155
resource aiFModelDeployments 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = [
151156
for aiModeldeployment in aiModelDeployments: if (empty(azureExistingAIProjectResourceId)) {
@@ -228,8 +233,7 @@ resource cognitiveServicesOpenAIUser 'Microsoft.Authorization/roleDefinitions@20
228233
name: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
229234
}
230235

231-
232-
resource assignOpenAIRoleToAISearch 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (empty(azureExistingAIProjectResourceId)) {
236+
resource assignOpenAIRoleToAISearch 'Microsoft.Authorization/roleAssignments@2022-04-01' = if (empty(azureExistingAIProjectResourceId)) {
233237
name: guid(resourceGroup().id, aiFoundry.id, cognitiveServicesOpenAIUser.id)
234238
scope: aiFoundry
235239
properties: {
@@ -247,7 +251,7 @@ module assignOpenAIRoleToAISearchExisting 'deploy_foundry_model_role_assignment.
247251
roleAssignmentName: guid(resourceGroup().id, aiSearch.id, cognitiveServicesOpenAIUser.id, 'openai-foundry')
248252
aiFoundryName: !empty(azureExistingAIProjectResourceId) ? existingAIFoundryName : aiFoundryName
249253
principalId: aiSearch.identity.principalId
250-
aiProjectName: !empty(azureExistingAIProjectResourceId) ? existingAIProjectName : aiProjectName
254+
aiProjectName: !empty(azureExistingAIProjectResourceId) ? existingAIProjectName : aiProjectName
251255
aiModelDeployments: aiModelDeployments
252256
}
253257
}
@@ -377,6 +381,7 @@ output aoaiEndpoint string = !empty(existingOpenAIEndpoint)
377381
? existingOpenAIEndpoint
378382
: aiFoundry.properties.endpoints['OpenAI Language Model Instance API'] //aiServices_m.properties.endpoint
379383
output aiFoundryName string = !empty(existingAIFoundryName) ? existingAIFoundryName : aiFoundryName //aiServicesName_m
384+
output aiFoundryId string = !empty(azureExistingAIProjectResourceId) ? existingAiFoundry.id : aiFoundry.id
380385

381386
output aiSearchName string = aiSearchName
382387
output aiSearchId string = aiSearch.id

infra/main.bicep

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,21 @@ param embeddingDeploymentCapacity int = 80
5555
param imageTag string = 'latest'
5656

5757
//restricting to these regions because assistants api for gpt-4o-mini is available only in these regions
58-
@allowed(['australiaeast','eastus', 'eastus2','francecentral','japaneast','swedencentral','uksouth', 'westus', 'westus3'])
58+
@allowed([
59+
'australiaeast'
60+
'eastus'
61+
'eastus2'
62+
'francecentral'
63+
'japaneast'
64+
'swedencentral'
65+
'uksouth'
66+
'westus'
67+
'westus3'
68+
])
5969
// @description('Azure OpenAI Location')
6070
// param AzureOpenAILocation string = 'eastus2'
61-
6271
@metadata({
63-
azd:{
72+
azd: {
6473
type: 'location'
6574
usageName: [
6675
'OpenAI.GlobalStandard.gpt-4o-mini,200'
@@ -112,7 +121,6 @@ var useInternalStream = 'True'
112121
var useAIProjectClientFlag = 'False'
113122
var sqlServerFqdn = '${sqlDBModule.outputs.sqlServerName}.database.windows.net'
114123

115-
116124
var functionAppSqlPrompt = '''Generate a valid T-SQL query to find {query} for tables and columns provided below:
117125
1. Table: Clients
118126
Columns: ClientId, Client, Email, Occupation, MaritalStatus, Dependents
@@ -308,12 +316,11 @@ output STORAGE_CONTAINER_NAME string = storageAccountModule.outputs.storageConta
308316
output KEY_VAULT_NAME string = keyvaultModule.outputs.keyvaultName
309317
output COSMOSDB_ACCOUNT_NAME string = cosmosDBModule.outputs.cosmosAccountName
310318
output RESOURCE_GROUP_NAME string = resourceGroup().name
311-
output RESOURCE_GROUP_NAME_FOUNDRY string = aifoundry.outputs.resourceGroupNameFoundry
319+
output AI_FOUNDRY_RESOURCE_ID string = aifoundry.outputs.aiFoundryId
312320
output SQLDB_SERVER_NAME string = sqlDBModule.outputs.sqlServerName
313321
output SQLDB_DATABASE string = sqlDBModule.outputs.sqlDbName
314322
output MANAGEDIDENTITY_WEBAPP_NAME string = managedIdentityModule.outputs.managedIdentityWebAppOutput.name
315323
output MANAGEDIDENTITY_WEBAPP_CLIENTID string = managedIdentityModule.outputs.managedIdentityWebAppOutput.clientId
316-
output AI_FOUNDRY_NAME string = aifoundry.outputs.aiFoundryName
317324
output AI_SEARCH_SERVICE_NAME string = aifoundry.outputs.aiSearchService
318325
output WEB_APP_NAME string = appserviceModule.outputs.webAppName
319326
output APP_ENV string = appEnvironment

infra/main.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.36.177.2456",
8-
"templateHash": "8388189115253050142"
8+
"templateHash": "11128400850485102096"
99
}
1010
},
1111
"parameters": {
@@ -772,7 +772,7 @@
772772
"_generator": {
773773
"name": "bicep",
774774
"version": "0.36.177.2456",
775-
"templateHash": "5605479917210969670"
775+
"templateHash": "16824105341593554305"
776776
}
777777
},
778778
"parameters": {
@@ -1612,6 +1612,10 @@
16121612
"type": "string",
16131613
"value": "[if(not(empty(variables('existingAIFoundryName'))), variables('existingAIFoundryName'), variables('aiFoundryName'))]"
16141614
},
1615+
"aiFoundryId": {
1616+
"type": "string",
1617+
"value": "[if(not(empty(parameters('azureExistingAIProjectResourceId'))), extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', variables('existingAIServiceSubscription'), variables('existingAIServiceResourceGroup')), 'Microsoft.CognitiveServices/accounts', variables('existingAIFoundryName')), resourceId('Microsoft.CognitiveServices/accounts', variables('aiFoundryName')))]"
1618+
},
16151619
"aiSearchName": {
16161620
"type": "string",
16171621
"value": "[variables('aiSearchName')]"
@@ -3136,9 +3140,9 @@
31363140
"type": "string",
31373141
"value": "[resourceGroup().name]"
31383142
},
3139-
"RESOURCE_GROUP_NAME_FOUNDRY": {
3143+
"AI_FOUNDRY_RESOURCE_ID": {
31403144
"type": "string",
3141-
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.resourceGroupNameFoundry.value]"
3145+
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.aiFoundryId.value]"
31423146
},
31433147
"SQLDB_SERVER_NAME": {
31443148
"type": "string",
@@ -3156,10 +3160,6 @@
31563160
"type": "string",
31573161
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityWebAppOutput.value.clientId]"
31583162
},
3159-
"AI_FOUNDRY_NAME": {
3160-
"type": "string",
3161-
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.aiFoundryName.value]"
3162-
},
31633163
"AI_SEARCH_SERVICE_NAME": {
31643164
"type": "string",
31653165
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.aiSearchService.value]"

0 commit comments

Comments
 (0)