Skip to content

Commit ec02cd9

Browse files
fix: Skip Quota check for Dereployment and Perform Quota check intially for Provided Region. If it fails check for all regions
1 parent 28b097e commit ec02cd9

File tree

4 files changed

+74
-48
lines changed

4 files changed

+74
-48
lines changed

azure.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ hooks:
3030
posix:
3131
shell: sh
3232
run: >
33-
./infra/scripts/validate_model_deployment_quota.sh --subscription "$AZURE_SUBSCRIPTION_ID" --location "${AZURE_LOCATION:-swedencentral}" --models-parameter "aiModelDeployments"
33+
./infra/scripts/validate_model_deployment_quota.sh --Subscription "$AZURE_SUBSCRIPTION_ID" --Location "${AZURE_LOCATION:-swedencentral}" --ModelsParameter "aiModelDeployments"
3434
interactive: false
3535
continueOnError: false
3636
windows:

infra/main.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,4 @@ output STORAGE_CONTAINER_NAME string = storageAccount.outputs.storageContainer
454454
output KEY_VAULT_NAME string = kvault.outputs.keyvaultName
455455
output COSMOSDB_ACCOUNT_NAME string = cosmosDBModule.outputs.cosmosAccountName
456456
output RESOURCE_GROUP_NAME string = resourceGroup().name
457+
output AZURE_AIFOUNDRY_NAME string = aifoundry.outputs.aiServicesName

infra/main.parameters.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,30 @@
1010
"name": "gpt-4o"
1111
},
1212
"sku": {
13-
"name": "Standard",
13+
"name": "GlobalStandard",
1414
"capacity": 30
1515
}
1616
},
1717
{
18-
"name": "gpt4o",
18+
"name": "embedding",
1919
"model": {
20-
"name": "gpt-4o"
20+
"name": "text-embedding-ada-002"
2121
},
2222
"sku": {
23-
"name": "GlobalStandard",
24-
"capacity": 30
23+
"name": "Standard",
24+
"capacity": 80
2525
}
2626
},
2727
{
28-
"name": "embedding",
28+
"name": "gpt4o",
2929
"model": {
30-
"name": "text-embedding-ada-002"
30+
"name": "gpt-4o"
3131
},
3232
"sku": {
3333
"name": "Standard",
34-
"capacity": 80
34+
"capacity": 30
3535
}
3636
}
37-
3837
]
3938
}
4039
}

infra/scripts/validate_model_deployment_quota.sh

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,85 @@ SUBSCRIPTION_ID=""
44
LOCATION=""
55
MODELS_PARAMETER=""
66

7-
ALL_REGIONS=('australiaeast' 'eastus2' 'francecentral' 'japaneast' 'norwayeast' 'swedencentral' 'uksouth' 'westus')
8-
9-
# Parse command-line arguments
107
while [[ $# -gt 0 ]]; do
118
case "$1" in
12-
--subscription)
9+
--Subscription)
1310
SUBSCRIPTION_ID="$2"
1411
shift 2
1512
;;
16-
--location)
13+
--Location)
1714
LOCATION="$2"
1815
shift 2
1916
;;
20-
--models-parameter)
17+
--ModelsParameter)
2118
MODELS_PARAMETER="$2"
2219
shift 2
2320
;;
2421
*)
25-
echo "Unknown option: $1"
22+
echo "❌ ERROR: Unknown option: $1"
2623
exit 1
2724
;;
2825
esac
2926
done
3027

31-
# Validate inputs
28+
AIFOUNDRY_NAME="${AZURE_AIFOUNDRY_NAME}"
29+
RESOURCE_GROUP="${AZURE_RESOURCE_GROUP}"
30+
31+
# Validate required parameters
3232
MISSING_PARAMS=()
33-
[[ -z "$SUBSCRIPTION_ID" ]] && MISSING_PARAMS+=("subscription")
34-
[[ -z "$LOCATION" ]] && MISSING_PARAMS+=("location")
35-
[[ -z "$MODELS_PARAMETER" ]] && MISSING_PARAMS+=("models-parameter")
33+
[[ -z "$SUBSCRIPTION_ID" ]] && MISSING_PARAMS+=("SubscriptionId")
34+
[[ -z "$LOCATION" ]] && MISSING_PARAMS+=("Location")
35+
[[ -z "$MODELS_PARAMETER" ]] && MISSING_PARAMS+=("ModelsParameter")
36+
[[ -z "$RESOURCE_GROUP" ]] && MISSING_PARAMS+=("AZURE_RESOURCE_GROUP")
37+
38+
if [[ ${#MISSING_PARAMS[@]} -ne 0 ]]; then
39+
echo "❌ ERROR: Missing required parameters: ${MISSING_PARAMS[*]}"
40+
echo "Usage: $0 --SubscriptionId <SUBSCRIPTION_ID> --Location <LOCATION> --ModelsParameter <MODELS_PARAMETER>"
41+
exit 1
42+
fi
3643

37-
if [[ ${#MISSING_PARAMS[@]} -gt 0 ]]; then
38-
echo "❌ ERROR: Missing parameters: ${MISSING_PARAMS[*]}"
44+
# If AI Foundry already exists, skip quota validation
45+
existing=$(az cognitiveservices account show --name "$AIFOUNDRY_NAME" --resource-group "$RESOURCE_GROUP" --query "name" --output tsv 2>/dev/null)
46+
if [[ -n "$existing" ]]; then
47+
echo "✅ AI Foundry '$AIFOUNDRY_NAME' exists. ⏭️ Skipping quota validation."
48+
exit 0
49+
else
50+
echo "❌ AI Foundry '$AIFOUNDRY_NAME' not found. Proceeding with quota validation..."
51+
fi
52+
53+
# Load model deployments
54+
aiModelDeployments=$(jq -c ".parameters.$MODELS_PARAMETER.value[]" ./infra/main.parameters.json)
55+
if [[ $? -ne 0 ]]; then
56+
echo "❌ ERROR: Failed to parse main.parameters.json. Ensure jq is installed and the JSON is valid."
3957
exit 1
4058
fi
4159

42-
az account set --subscription "$SUBSCRIPTION_ID" || exit 1
60+
az account set --subscription "$SUBSCRIPTION_ID"
4361
echo "🎯 Active Subscription: $(az account show --query '[name, id]' --output tsv)"
4462

45-
aiModelDeployments=$(jq -c ".parameters.$MODELS_PARAMETER.value[]" ./infra/main.parameters.json)
63+
ALL_REGIONS=('australiaeast' 'eastus2' 'francecentral' 'japaneast' 'norwayeast' 'swedencentral' 'uksouth' 'westus')
4664

4765
declare -A regionAvailabilityMap
4866
declare -a fallbackRegions
49-
printf -- "-----------------------------------------------------------------------------------------------\n"
50-
printf "%-4s | %-15s | %-40s | %-6s | %-6s | %-9s\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
67+
68+
# Prioritize selected location first
69+
REGIONS_TO_CHECK=("$LOCATION")
70+
for r in "${ALL_REGIONS[@]}"; do
71+
[[ "$r" != "$LOCATION" ]] && REGIONS_TO_CHECK+=("$r")
72+
done
73+
74+
# Header
75+
printf "\n%-4s | %-15s | %-40s | %-6s | %-6s | %-9s\n" "No." "Region" "Model Name" "Limit" "Used" "Available"
5176
printf -- "-----------------------------------------------------------------------------------------------\n"
5277

5378
region_idx=1
5479

55-
for region in "${ALL_REGIONS[@]}"; do
80+
for region in "${REGIONS_TO_CHECK[@]}"; do
5681
allModelsFit=true
5782
regionPrinted=false
5883

5984
while IFS= read -r deployment; do
85+
name=$(echo "$deployment" | jq -r '.name')
6086
model=$(echo "$deployment" | jq -r '.model.name')
6187
type=$(echo "$deployment" | jq -r '.sku.name')
6288
capacity=$(echo "$deployment" | jq -r '.sku.capacity')
@@ -89,31 +115,31 @@ for region in "${ALL_REGIONS[@]}"; do
89115

90116
if $allModelsFit; then
91117
regionAvailabilityMap["$region"]="true"
92-
[[ "$region" != "$LOCATION" ]] && fallbackRegions+=("$region")
118+
if [[ "$region" == "$LOCATION" ]]; then
119+
echo "✅ Sufficient quota is available in selected region: $LOCATION"
120+
exit 0
121+
else
122+
fallbackRegions+=("$region")
123+
fi
93124
fi
94125

95126
((region_idx++))
96127
done
97128

98-
# Result Evaluation
99-
if [[ "${regionAvailabilityMap[$LOCATION]}" == "true" ]]; then
100-
echo "✅ Sufficient quota is available for all models in the selected region: $LOCATION"
101-
exit 0
129+
# Fallback result
130+
echo -e "\n❌ The selected region '$LOCATION' does not have sufficient quota for all required models."
131+
if [[ ${#fallbackRegions[@]} -gt 0 ]]; then
132+
echo "➡️ You can try using one of the following regions where all models have sufficient quota:"
133+
for fallback in "${fallbackRegions[@]}"; do
134+
echo "$fallback"
135+
done
136+
echo -e "\n🔧 To proceed, run:"
137+
echo " azd env set AZURE_ENV_OPENAI_LOCATION '<region>'"
138+
echo "📌 To confirm it's set correctly, run:"
139+
echo " azd env get-value AZURE_ENV_OPENAI_LOCATION"
140+
echo "▶️ Once confirmed, re-run azd up to deploy the model in the new region."
141+
exit 2
102142
else
103-
echo -e "\n❌ The selected region '$LOCATION' does not have sufficient quota for all required models."
104-
if [[ ${#fallbackRegions[@]} -gt 0 ]]; then
105-
echo "➡️ You can try using one of the following regions where all models have sufficient quota:"
106-
for fallback in "${fallbackRegions[@]}"; do
107-
echo "$fallback"
108-
done
109-
echo -e "\n🔧 To proceed, run:"
110-
echo " azd env set AZURE_ENV_OPENAI_LOCATION '<region>'"
111-
echo "📌 To confirm it's set correctly, run:"
112-
echo " azd env get-value AZURE_ENV_OPENAI_LOCATION"
113-
echo "▶️ Once confirmed, re-run azd up to deploy the model in the new region."
114-
exit 2
115-
else
116-
echo "❌ No fallback regions found with sufficient quota for all models."
117-
fi
143+
echo "❌ No fallback regions found with sufficient quota for all models."
118144
exit 1
119145
fi

0 commit comments

Comments
 (0)