Skip to content

Commit d66f6d0

Browse files
Merge pull request #472 from microsoft/psl-rc-postdscript
fix: Updated post deployment script for ai user role assignment
2 parents f75c7fb + d5153af commit d66f6d0

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

docs/DeploymentGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Once you've opened the project in [Codespaces](#github-codespaces), [Dev Contain
167167
```
168168
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:
169169
```shell
170-
bash ./infra/scripts/process_sample_data.sh <Storage-Account-name> <Storage-Account-container-name> <Key-Vault-name> <CosmosDB-Account-name> <Resource-Group-name>
170+
bash ./infra/scripts/process_sample_data.sh <Storage-Account-name> <Storage-Account-container-name> <Key-Vault-name> <CosmosDB-Account-name> <Resource-Group-name> <aiFoundryResourceName>
171171
```
172172

173173
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/main.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,4 @@ output STORAGE_CONTAINER_NAME string = storageAccount.outputs.storageContainer
178178
output KEY_VAULT_NAME string = kvault.outputs.keyvaultName
179179
output COSMOSDB_ACCOUNT_NAME string = cosmosDBModule.outputs.cosmosAccountName
180180
output RESOURCE_GROUP_NAME string = resourceGroup().name
181+
output AI_FOUNDRY_NAME string = aifoundry.outputs.aiFoundryName

infra/main.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.36.1.42791",
8-
"templateHash": "16830004841131342789"
8+
"templateHash": "5837450370511727433"
99
}
1010
},
1111
"parameters": {
@@ -2291,6 +2291,10 @@
22912291
"RESOURCE_GROUP_NAME": {
22922292
"type": "string",
22932293
"value": "[resourceGroup().name]"
2294+
},
2295+
"AI_FOUNDRY_NAME": {
2296+
"type": "string",
2297+
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.aiFoundryName.value]"
22942298
}
22952299
}
22962300
}

infra/scripts/process_sample_data.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ fileSystem="$2"
66
keyvaultName="$3"
77
cosmosDbAccountName="$4"
88
resourceGroupName="$5"
9-
managedIdentityClientId="$6"
9+
aiFoundryName="$6"
10+
managedIdentityClientId="$7"
1011

1112
# get parameters from azd env, if not provided
1213
if [ -z "$resourceGroupName" ]; then
@@ -29,10 +30,13 @@ if [ -z "$keyvaultName" ]; then
2930
keyvaultName=$(azd env get-value KEY_VAULT_NAME)
3031
fi
3132

33+
if [ -z "$aiFoundryName" ]; then
34+
aiFoundryName=$(azd env get-value AI_FOUNDRY_NAME)
35+
fi
3236

3337
# Check if all required arguments are provided
34-
if [ -z "$storageAccount" ] || [ -z "$fileSystem" ] || [ -z "$keyvaultName" ] || [ -z "$cosmosDbAccountName" ] || [ -z "$resourceGroupName" ]; then
35-
echo "Usage: $0 <storageAccount> <storageContainerName> <keyvaultName> <cosmosDbAccountName> <resourceGroupName>"
38+
if [ -z "$storageAccount" ] || [ -z "$fileSystem" ] || [ -z "$keyvaultName" ] || [ -z "$cosmosDbAccountName" ] || [ -z "$resourceGroupName" ] || [ -z "$aiFoundryName" ]; then
39+
echo "Usage: $0 <storageAccount> <storageContainerName> <keyvaultName> <cosmosDbAccountName> <resourceGroupName> <aiFoundryName>"
3640
exit 1
3741
fi
3842

@@ -56,7 +60,7 @@ echo "copy_kb_files.sh completed successfully."
5660

5761
# Call run_create_index_scripts.sh
5862
echo "Running run_create_index_scripts.sh"
59-
bash infra/scripts/run_create_index_scripts.sh "$keyvaultName" "$managedIdentityClientId"
63+
bash infra/scripts/run_create_index_scripts.sh "$keyvaultName" "$resourceGroupName" "$aiFoundryName" "$managedIdentityClientId"
6064
if [ $? -ne 0 ]; then
6165
echo "Error: run_create_index_scripts.sh failed."
6266
exit 1

infra/scripts/run_create_index_scripts.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# Variables
44
# baseUrl="$1"
55
keyvaultName="$1"
6-
managedIdentityClientId="$2"
6+
resourceGroupName="$2"
7+
aiFoundryName="$3"
8+
managedIdentityClientId="$4"
79
# requirementFile="infra/scripts/index_scripts/requirements.txt"
810
# requirementFileUrl=${baseUrl}"infra/scripts/index_scripts/requirements.txt"
911

@@ -60,6 +62,27 @@ else
6062
echo "User already has the Key Vault Administrator role."
6163
fi
6264

65+
### Assign Azure AI User role to the signed in user ###
66+
67+
echo "Getting Azure AI resource id"
68+
aif_resource_id=$(az cognitiveservices account show --name $aiFoundryName --resource-group $resourceGroupName --query id --output tsv)
69+
70+
# Check if the user has the Azure AI User role
71+
echo "Checking if user has the Azure AI User role"
72+
role_assignment=$(MSYS_NO_PATHCONV=1 az role assignment list --role 53ca6127-db72-4b80-b1b0-d745d6d5456d --scope $aif_resource_id --assignee $signed_user_id --query "[].roleDefinitionId" -o tsv)
73+
if [ -z "$role_assignment" ]; then
74+
echo "User does not have the Azure AI User role. Assigning the role."
75+
MSYS_NO_PATHCONV=1 az role assignment create --assignee $signed_user_id --role 53ca6127-db72-4b80-b1b0-d745d6d5456d --scope $aif_resource_id --output none
76+
if [ $? -eq 0 ]; then
77+
echo "Azure AI User role assigned successfully."
78+
else
79+
echo "Failed to assign Azure AI User role."
80+
exit 1
81+
fi
82+
else
83+
echo "User already has the Azure AI User role."
84+
fi
85+
6386
# RUN apt-get update
6487
# RUN apt-get install python3 python3-dev g++ unixodbc-dev unixodbc libpq-dev
6588
# apk add python3 python3-dev g++ unixodbc-dev unixodbc libpq-dev

0 commit comments

Comments
 (0)