@@ -25,69 +25,80 @@ if ($DeploymentType -ne "Standard" -and $DeploymentType -ne "GlobalStandard") {
2525
2626$ModelType = " OpenAI.$DeploymentType .$Model "
2727
28+ $PreferredRegions = @ (' australiaeast' , ' eastus2' , ' francecentral' , ' japaneast' , ' norwayeast' , ' swedencentral' , ' uksouth' , ' westus' )
29+ $AllResults = @ ()
30+
2831function Check-Quota {
2932 param (
3033 [string ]$Region
3134 )
3235
33- Write-Host " `n 🔍 Checking quota for $ModelType in $Region ..."
34-
3536 $ModelInfoRaw = az cognitiveservices usage list -- location $Region -- query " [?name.value=='$ModelType ']" -- output json
3637 $ModelInfo = $null
3738
3839 try {
3940 $ModelInfo = $ModelInfoRaw | ConvertFrom-Json
4041 } catch {
41- Write-Warning " ⚠️ Failed to parse quota info for region: $Region "
42- return $false
42+ return
4343 }
4444
4545 if (-not $ModelInfo ) {
46- Write-Host " ⚠️ No quota information found for $ModelType in $Region "
47- return $false
46+ return
4847 }
4948
5049 $CurrentValue = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).currentValue
5150 $Limit = ($ModelInfo | Where-Object { $_.name.value -eq $ModelType }).limit
5251
53- $CurrentValue = [int ]($CurrentValue -replace ' \.0+$' , ' ' ) # Remove decimals
54- $Limit = [int ]($Limit -replace ' \.0+$' , ' ' ) # Remove decimals
55-
52+ $CurrentValue = [int ]($CurrentValue -replace ' \.0+$' , ' ' )
53+ $Limit = [int ]($Limit -replace ' \.0+$' , ' ' )
5654 $Available = $Limit - $CurrentValue
57- Write-Host " 🔎 Model: $ModelType | Used: $CurrentValue | Limit: $Limit | Available: $Available "
58-
59- if ($Available -ge $Capacity ) {
60- Write-Host " ✅ Sufficient quota in $Region "
61- return $true
62- } else {
63- Write-Host " ❌ Insufficient quota in $Region (Available: $Available , Required: $Capacity )"
64- return $false
55+
56+ $script :AllResults += [PSCustomObject ]@ {
57+ Region = $Region
58+ Model = $ModelType
59+ Limit = $Limit
60+ Used = $CurrentValue
61+ Available = $Available
6562 }
6663}
6764
68- # List of fallback regions (excluding the one already tried)
69- $PreferredRegions = @ (' australiaeast' , ' eastus2' , ' francecentral' , ' japaneast' , ' norwayeast' , ' swedencentral' , ' uksouth' , ' westus' ) | Where-Object { $_ -ne $Location }
65+ foreach ($region in $PreferredRegions ) {
66+ Check- Quota - Region $region
67+ }
7068
71- # Try original location first
72- if (Check- Quota - Region $Location ) {
69+ # Display Results Table
70+ Write-Host " \n-------------------------------------------------------------------------------------------------------------"
71+ Write-Host " | No. | Region | Model Name | Limit | Used | Available |"
72+ Write-Host " -------------------------------------------------------------------------------------------------------------"
73+
74+ $count = 1
75+ foreach ($entry in $AllResults ) {
76+ $index = $PreferredRegions.IndexOf ($entry.Region ) + 1
77+ $modelShort = $entry.Model.Substring ($entry.Model.LastIndexOf (" ." ) + 1 )
78+ Write-Host (" | {0,-4} | {1,-16} | {2,-35} | {3,-7} | {4,-7} | {5,-9} |" -f $index , $entry.Region , $entry.Model , $entry.Limit , $entry.Used , $entry.Available )
79+ $count ++
80+ }
81+ Write-Host " -------------------------------------------------------------------------------------------------------------"
82+
83+ $EligibleRegion = $AllResults | Where-Object { $_.Region -eq $Location -and $_.Available -ge $Capacity }
84+ if ($EligibleRegion ) {
85+ Write-Host " \n✅ Sufficient quota found in original region '$Location '."
7386 exit 0
7487}
7588
76- Write-Host " `n 🔁 Trying fallback regions for available quota... "
89+ $FallbackRegions = $AllResults | Where-Object { $_ .Region -ne $Location -and $_ .Available -ge $Capacity }
7790
78- foreach ($region in $PreferredRegions ) {
79- if (Check- Quota - Region $region ) {
80- Write-Host " 🚫 Deployment cannot proceed because the original region '$Location ' lacks sufficient quota."
81- Write-Host " ➡️ You can retry using the available region: '$region '"
82- Write-Host " 🔧 To proceed, update the 'AZURE_OPENAI_LOCATION' value in the 'main.bicepparam' file, then run the following command:"
83- Write-Host " azd env set AZURE_OPENAI_LOCATION '$region '"
91+ if ($FallbackRegions.Count -gt 0 ) {
92+ Write-Host " `n ❌ Deployment cannot proceed because the original region '$Location ' lacks sufficient quota."
93+ Write-Host " ➡️ You can retry using one of the following regions with sufficient quota:`n "
8494
85- # Optional: update `.azure/env` (uncomment if needed)
86- # Add-Content ".azure/env" "`nAZURE_OPENAI_LOCATION=$region"
87-
88- # Exit with non-zero code to halt deployment
89- exit 2
95+ foreach ($region in $FallbackRegions ) {
96+ Write-Host " • $ ( $region.Region ) (Available: $ ( $region.Available ) )"
9097 }
98+
99+ Write-Host " `n 🔧 To proceed, update the 'AZURE_OPENAI_LOCATION' value in the 'main.bicepparam' file, then run:"
100+ Write-Host " azd env set AZURE_OPENAI_LOCATION '<region>'"
101+ exit 2
91102}
92103
93104Write-Error " ❌ ERROR: No available quota found in any region."
0 commit comments