@@ -15,58 +15,64 @@ if (-not $ModelsParameter) { $MissingParams += "ModelsParameter" }
1515
1616if ($MissingParams.Count -gt 0 ) {
1717 Write-Error " ❌ ERROR: Missing required parameters: $ ( $MissingParams -join ' , ' ) "
18+ Write-Host " Usage: validate_model_deployment_quota.ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
1819 exit 1
1920}
2021
2122# Load model deployments from parameter file
2223$JsonContent = Get-Content - Path " ./infra/main.parameters.json" - Raw | ConvertFrom-Json
23- if (-not $JsonContent ) {
24- Write-Error " ❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
25- exit 1
26- }
27-
2824$aiModelDeployments = $JsonContent.parameters .$ModelsParameter.value
2925if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable ])) {
30- Write-Error " ❌ ERROR: The specified property ' $ModelsParameter ' does not exist or is not an array. "
26+ Write-Error " ❌ ERROR: Failed to parse main.parameters.json or missing ' $ModelsParameter ' "
3127 exit 1
3228}
3329
34- # Check if AI Foundry exists and has all required model deployments
35- $existing = $null
30+ # Try to discover AI Foundry name if not set
31+ if (-not $AiFoundryName -and $ResourceGroup ) {
32+ $AiFoundryName = az cognitiveservices account list `
33+ -- resource- group $ResourceGroup `
34+ -- query " sort_by([?kind=='AIServices'], &name)[0].name" `
35+ - o tsv 2> $null
36+ }
37+
38+ # Check if AI Foundry exists
3639if ($AiFoundryName -and $ResourceGroup ) {
3740 $existing = az cognitiveservices account show `
3841 -- name $AiFoundryName `
3942 -- resource- group $ResourceGroup `
4043 -- query " name" -- output tsv 2> $null
41- }
4244
43- if ($existing ) {
44- $deployedModelsOutput = az cognitiveservices account deployment list `
45- -- name $AiFoundryName `
46- -- resource- group $ResourceGroup `
47- -- query " [].name" -- output tsv 2> $null
45+ if ($existing ) {
46+ # adding into .env
47+ azd env set AZURE_AIFOUNDRY_NAME $existing | Out-Null
4848
49- $deployedModels = @ ()
50- if ($deployedModelsOutput -is [string ]) {
51- $deployedModels += $deployedModelsOutput
52- } elseif ($deployedModelsOutput ) {
53- $deployedModels = $deployedModelsOutput -split " `r ?`n "
54- }
49+ $deployedModelsOutput = az cognitiveservices account deployment list `
50+ -- name $AiFoundryName `
51+ -- resource- group $ResourceGroup `
52+ -- query " [].name" -- output tsv 2> $null
5553
56- $requiredDeployments = $aiModelDeployments | ForEach-Object { $_.name }
57- $missingDeployments = $requiredDeployments | Where-Object { $_ -notin $deployedModels }
54+ $deployedModels = @ ()
55+ if ($deployedModelsOutput -is [string ]) {
56+ $deployedModels += $deployedModelsOutput
57+ } elseif ($deployedModelsOutput ) {
58+ $deployedModels = $deployedModelsOutput -split " `r ?`n "
59+ }
60+
61+ $requiredDeployments = $aiModelDeployments | ForEach-Object { $_.name }
62+ $missingDeployments = $requiredDeployments | Where-Object { $_ -notin $deployedModels }
5863
59- if ($missingDeployments.Count -eq 0 ) {
60- Write-Host " ℹ️ AI Foundry '$AiFoundryName ' exists and all required model deployments are already provisioned."
61- Write-Host " ⏭️ Skipping quota validation."
62- exit 0
63- } else {
64- Write-Host " 🔍 AI Foundry exists, but the following model deployments are missing: $ ( $missingDeployments -join ' , ' ) "
65- Write-Host " ➡️ Proceeding with quota validation for missing models..."
64+ if ($missingDeployments.Count -eq 0 ) {
65+ Write-Host " ℹ️ AI Foundry '$AiFoundryName ' exists and all required model deployments are already provisioned."
66+ Write-Host " ⏭️ Skipping quota validation."
67+ exit 0
68+ } else {
69+ Write-Host " 🔍 AI Foundry exists, but the following model deployments are missing: $ ( $missingDeployments -join ' , ' ) "
70+ Write-Host " ➡️ Proceeding with quota validation for missing models..."
71+ }
6672 }
6773}
6874
69- # Run quota validation for all models
75+ # Run quota validation
7076az account set -- subscription $SubscriptionId
7177Write-Host " 🎯 Active Subscription: $ ( az account show -- query ' [name, id]' -- output tsv) "
7278
@@ -78,7 +84,8 @@ foreach ($deployment in $aiModelDeployments) {
7884 $type = if ($env: AZURE_ENV_MODEL_DEPLOYMENT_TYPE ) { $env: AZURE_ENV_MODEL_DEPLOYMENT_TYPE } else { $deployment.sku.name }
7985 $capacity = if ($env: AZURE_ENV_MODEL_CAPACITY ) { $env: AZURE_ENV_MODEL_CAPACITY } else { $deployment.sku.capacity }
8086
81- Write-Host " `n 🔍 Validating model deployment: $name ..."
87+ Write-Host " "
88+ Write-Host " 🔍 Validating model deployment: $name ..."
8289 & .\scripts\validate_model_quota.ps1 - Location $Location - Model $model - Capacity $capacity - DeploymentType $type
8390 $exitCode = $LASTEXITCODE
8491
0 commit comments