@@ -4,79 +4,72 @@ param (
44 [string ]$ModelsParameter
55)
66
7- # Read from environment variables (do not pass in azure.yaml)
8- $AiServiceName = $env: AZURE_AISERVICE_NAME
7+ $AiFoundryName = $env: AZURE_AIFOUNDRY_NAME
98$ResourceGroup = $env: AZURE_RESOURCE_GROUP
109
1110# Validate required parameters
1211$MissingParams = @ ()
13-
14- if (-not $SubscriptionId ) {
15- $MissingParams += " subscription"
16- }
17- if (-not $Location ) {
18- $MissingParams += " location"
19- }
20- if (-not $ModelsParameter ) {
21- $MissingParams += " models-parameter"
22- }
12+ if (-not $SubscriptionId ) { $MissingParams += " SubscriptionId" }
13+ if (-not $Location ) { $MissingParams += " Location" }
14+ if (-not $ModelsParameter ) { $MissingParams += " ModelsParameter" }
15+ if (-not $AiFoundryName ) { $MissingParams += " AZURE_AISERVICE_NAME" }
16+ if (-not $ResourceGroup ) { $MissingParams += " AZURE_RESOURCE_GROUP" }
2317
2418if ($MissingParams.Count -gt 0 ) {
2519 Write-Error " ❌ ERROR: Missing required parameters: $ ( $MissingParams -join ' , ' ) "
26- Write-Host " Usage: .\validate_model_deployment_quotas.ps1 -SubscriptionId <SUBSCRIPTION_ID> -Location <LOCATION> -ModelsParameter <MODELS_PARAMETER>"
2720 exit 1
2821}
2922
30- # Load main. parameters.json
23+ # Load model deployment parameters
3124$JsonContent = Get-Content - Path " ./infra/main.parameters.json" - Raw | ConvertFrom-Json
3225if (-not $JsonContent ) {
3326 Write-Error " ❌ ERROR: Failed to parse main.parameters.json. Ensure the JSON file is valid."
3427 exit 1
3528}
3629
3730$aiModelDeployments = $JsonContent.parameters .$ModelsParameter.value
31+
3832if (-not $aiModelDeployments -or -not ($aiModelDeployments -is [System.Collections.IEnumerable ])) {
3933 Write-Error " ❌ ERROR: The specified property '$ModelsParameter ' does not exist or is not an array."
4034 exit 1
4135}
4236
43- # Check if AI resource + all deployments already exist
44- if ($AiServiceName -and $ResourceGroup ) {
45- $existing = az cognitiveservices account show `
46- -- name $AiServiceName `
47- -- resource- group $ResourceGroup `
48- -- query " name" -- output tsv 2> $null
49-
50- if ($existing ) {
51- $deployedModels = az cognitiveservices account deployment list `
52- -- name $AiServiceName `
53- -- resource- group $ResourceGroup `
54- -- query " [].name" -- output tsv 2> $null
37+ # Check if AI Foundry and model deployments already exist
38+ $existing = az cognitiveservices account show `
39+ -- name $AiFoundryName `
40+ -- resource- group $ResourceGroup `
41+ -- query " name" -- output tsv 2> $null
5542
56- $requiredDeployments = @ ()
57- foreach ($deployment in $aiModelDeployments ) {
58- $requiredDeployments += $deployment.name
59- }
43+ if ($existing ) {
44+ $deployedModelsOutput = az cognitiveservices account deployment list `
45+ -- name $AiFoundryName `
46+ -- resource- group $ResourceGroup `
47+ -- query " [].name" -- output tsv 2> $null
48+
49+ # Normalize output to array
50+ $deployedModels = @ ()
51+ if ($deployedModelsOutput -is [string ]) {
52+ $deployedModels += $deployedModelsOutput
53+ } elseif ($deployedModelsOutput ) {
54+ $deployedModels = $deployedModelsOutput -split " `r ?`n "
55+ }
6056
61- $missingDeployments = @ ()
62- foreach ($required in $requiredDeployments ) {
63- if ($deployedModels -notcontains $required ) {
64- $missingDeployments += $required
65- }
66- }
57+ $requiredDeployments = $aiModelDeployments | ForEach-Object { $_.name }
58+ $missingDeployments = $requiredDeployments | Where-Object { $_ -notin $deployedModels }
6759
68- if ($missingDeployments.Count -eq 0 ) {
69- Write-Host " ℹ️ Azure AI service '$AiServiceName ' exists and all required model deployments are provisioned."
70- Write-Host " ⏭️ Skipping quota validation."
71- exit 0
72- } else {
73- Write-Host " 🔍 AI service exists, but the following model deployments are missing: $ ( $missingDeployments -join ' , ' ) "
74- Write-Host " ➡️ Proceeding with quota validation for missing models..."
75- }
60+ if ($missingDeployments.Count -eq 0 ) {
61+ Write-Host " ℹ️ AI Foundry '$AiFoundryName ' exists and all required model deployments are already provisioned."
62+ Write-Host " ⏭️ Skipping quota validation."
63+ exit 0
64+ } else {
65+ Write-Host " 🔍 AI Foundry exists, but the following model deployments are missing: $ ( $missingDeployments -join ' , ' ) "
66+ Write-Host " ➡️ Proceeding with quota validation for missing models..."
7667 }
68+ } else {
69+ Write-Host " ❌ AI Foundry '$AiFoundryName ' not found. Proceeding with quota validation."
7770}
7871
79- # Start quota validation
72+ # Run quota validation
8073az account set -- subscription $SubscriptionId
8174Write-Host " 🎯 Active Subscription: $ ( az account show -- query ' [name, id]' -- output tsv) "
8275
@@ -94,17 +87,17 @@ foreach ($deployment in $aiModelDeployments) {
9487
9588 if ($exitCode -ne 0 ) {
9689 if ($exitCode -eq 2 ) {
97- exit 1 # already printed, graceful
90+ exit 1
9891 }
9992 Write-Error " ❌ ERROR: Quota validation failed for model deployment: $name "
10093 $QuotaAvailable = $false
10194 }
10295}
10396
10497if (-not $QuotaAvailable ) {
105- Write-Error " ❌ ERROR: One or more model deployments failed validation."
98+ Write-Error " ❌ ERROR: One or more model deployments failed quota validation."
10699 exit 1
107100} else {
108101 Write-Host " ✅ All model deployments passed quota validation successfully."
109102 exit 0
110- }
103+ }
0 commit comments