@@ -4,75 +4,73 @@ param (
44 [string ]$ModelsParameter
55)
66
7- $AiFoundryName = $env: AZURE_AIFOUNDRY_NAME
7+ # Read from environment variables (do not pass in azure.yaml)
8+ $AiServiceName = $env: AZURE_AISERVICE_NAME
89$ResourceGroup = $env: AZURE_RESOURCE_GROUP
910
1011# Validate required parameters
1112$MissingParams = @ ()
13+
1214if (-not $SubscriptionId ) { $MissingParams += " SubscriptionId" }
1315if (-not $Location ) { $MissingParams += " Location" }
1416if (-not $ModelsParameter ) { $MissingParams += " ModelsParameter" }
1517
1618if ($MissingParams.Count -gt 0 ) {
1719 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>"
20+ Write-Host " Usage: .\validate_model_deployment_quotas .ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
1921 exit 1
2022}
2123
22- # Load model deployments from parameter file
24+ # Load main.parameters.json
2325$JsonContent = Get-Content - Path " ./infra/main.parameters.json" - Raw | ConvertFrom-Json
24- $aiModelDeployments = $JsonContent.parameters .$ModelsParameter.value
25- if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable ])) {
26- Write-Error " ❌ ERROR: Failed to parse main.parameters.json or missing '$ModelsParameter '"
26+ if (-not $JsonContent ) {
27+ Write-Error " ❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
2728 exit 1
2829}
2930
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
31+ $aiModelDeployments = $JsonContent.parameters .$ModelsParameter.value
32+ if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable ])) {
33+ Write-Error " ❌ ERROR: The specified property '$ModelsParameter ' does not exist or is not an array."
34+ exit 1
3635}
3736
38- # Check if AI Foundry exists
39- if ($AiFoundryName -and $ResourceGroup ) {
37+ # Check if AI resource + all deployments already exist
38+ if ($AiServiceName -and $ResourceGroup ) {
4039 $existing = az cognitiveservices account show `
41- -- name $AiFoundryName `
40+ -- name $AiServiceName `
4241 -- resource- group $ResourceGroup `
4342 -- query " name" -- output tsv 2> $null
4443
4544 if ($existing ) {
46- # adding into .env
47- azd env set AZURE_AIFOUNDRY_NAME $existing | Out-Null
48-
49- $deployedModelsOutput = az cognitiveservices account deployment list `
50- -- name $AiFoundryName `
45+ $deployedModels = az cognitiveservices account deployment list `
46+ -- name $AiServiceName `
5147 -- resource- group $ResourceGroup `
5248 -- query " [].name" -- output tsv 2> $null
5349
54- $deployedModels = @ ()
55- if ($deployedModelsOutput -is [string ]) {
56- $deployedModels += $deployedModelsOutput
57- } elseif ($deployedModelsOutput ) {
58- $deployedModels = $deployedModelsOutput -split " `r ?`n "
50+ $requiredDeployments = @ ()
51+ foreach ($deployment in $aiModelDeployments ) {
52+ $requiredDeployments += $deployment.name
5953 }
6054
61- $requiredDeployments = $aiModelDeployments | ForEach-Object { $_.name }
62- $missingDeployments = $requiredDeployments | Where-Object { $_ -notin $deployedModels }
55+ $missingDeployments = @ ()
56+ foreach ($required in $requiredDeployments ) {
57+ if ($deployedModels -notcontains $required ) {
58+ $missingDeployments += $required
59+ }
60+ }
6361
6462 if ($missingDeployments.Count -eq 0 ) {
65- Write-Host " ℹ️ AI Foundry '$AiFoundryName ' exists and all required model deployments are already provisioned."
63+ Write-Host " ℹ️ Azure AI service '$AiServiceName ' exists and all required model deployments are provisioned."
6664 Write-Host " ⏭️ Skipping quota validation."
6765 exit 0
6866 } else {
69- Write-Host " 🔍 AI Foundry exists, but the following model deployments are missing: $ ( $missingDeployments -join ' , ' ) "
67+ Write-Host " 🔍 AI service exists, but the following model deployments are missing: $ ( $missingDeployments -join ' , ' ) "
7068 Write-Host " ➡️ Proceeding with quota validation for missing models..."
7169 }
7270 }
7371}
7472
75- # Run quota validation
73+ # Start quota validation
7674az account set -- subscription $SubscriptionId
7775Write-Host " 🎯 Active Subscription: $ ( az account show -- query ' [name, id]' -- output tsv) "
7876
@@ -84,24 +82,23 @@ foreach ($deployment in $aiModelDeployments) {
8482 $type = if ($env: AZURE_ENV_MODEL_DEPLOYMENT_TYPE ) { $env: AZURE_ENV_MODEL_DEPLOYMENT_TYPE } else { $deployment.sku.name }
8583 $capacity = if ($env: AZURE_ENV_MODEL_CAPACITY ) { $env: AZURE_ENV_MODEL_CAPACITY } else { $deployment.sku.capacity }
8684
87- Write-Host " "
88- Write-Host " 🔍 Validating model deployment: $name ..."
85+ Write-Host " `n 🔍 Validating model deployment: $name ..."
8986 & .\scripts\validate_model_quota.ps1 - Location $Location - Model $model - Capacity $capacity - DeploymentType $type
9087 $exitCode = $LASTEXITCODE
9188
9289 if ($exitCode -ne 0 ) {
9390 if ($exitCode -eq 2 ) {
94- exit 1
91+ exit 1 # already printed, graceful
9592 }
9693 Write-Error " ❌ ERROR: Quota validation failed for model deployment: $name "
9794 $QuotaAvailable = $false
9895 }
9996}
10097
10198if (-not $QuotaAvailable ) {
102- Write-Error " ❌ ERROR: One or more model deployments failed quota validation."
99+ Write-Error " ❌ ERROR: One or more model deployments failed validation."
103100 exit 1
104101} else {
105102 Write-Host " ✅ All model deployments passed quota validation successfully."
106103 exit 0
107- }
104+ }
0 commit comments