@@ -4,75 +4,73 @@ param (
4
4
[string ]$ModelsParameter
5
5
)
6
6
7
- $AiFoundryName = $env: AZURE_AIFOUNDRY_NAME
7
+ # Read from environment variables (do not pass in azure.yaml)
8
+ $AiServiceName = $env: AZURE_AISERVICE_NAME
8
9
$ResourceGroup = $env: AZURE_RESOURCE_GROUP
9
10
10
11
# Validate required parameters
11
12
$MissingParams = @ ()
13
+
12
14
if (-not $SubscriptionId ) { $MissingParams += " SubscriptionId" }
13
15
if (-not $Location ) { $MissingParams += " Location" }
14
16
if (-not $ModelsParameter ) { $MissingParams += " ModelsParameter" }
15
17
16
18
if ($MissingParams.Count -gt 0 ) {
17
19
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>"
19
21
exit 1
20
22
}
21
23
22
- # Load model deployments from parameter file
24
+ # Load main.parameters.json
23
25
$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."
27
28
exit 1
28
29
}
29
30
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
36
35
}
37
36
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 ) {
40
39
$existing = az cognitiveservices account show `
41
- -- name $AiFoundryName `
40
+ -- name $AiServiceName `
42
41
-- resource- group $ResourceGroup `
43
42
-- query " name" -- output tsv 2> $null
44
43
45
44
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 `
51
47
-- resource- group $ResourceGroup `
52
48
-- query " [].name" -- output tsv 2> $null
53
49
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
59
53
}
60
54
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
+ }
63
61
64
62
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."
66
64
Write-Host " ⏭️ Skipping quota validation."
67
65
exit 0
68
66
} 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 ' , ' ) "
70
68
Write-Host " ➡️ Proceeding with quota validation for missing models..."
71
69
}
72
70
}
73
71
}
74
72
75
- # Run quota validation
73
+ # Start quota validation
76
74
az account set -- subscription $SubscriptionId
77
75
Write-Host " 🎯 Active Subscription: $ ( az account show -- query ' [name, id]' -- output tsv) "
78
76
@@ -84,24 +82,23 @@ foreach ($deployment in $aiModelDeployments) {
84
82
$type = if ($env: AZURE_ENV_MODEL_DEPLOYMENT_TYPE ) { $env: AZURE_ENV_MODEL_DEPLOYMENT_TYPE } else { $deployment.sku.name }
85
83
$capacity = if ($env: AZURE_ENV_MODEL_CAPACITY ) { $env: AZURE_ENV_MODEL_CAPACITY } else { $deployment.sku.capacity }
86
84
87
- Write-Host " "
88
- Write-Host " 🔍 Validating model deployment: $name ..."
85
+ Write-Host " `n 🔍 Validating model deployment: $name ..."
89
86
& .\scripts\validate_model_quota.ps1 - Location $Location - Model $model - Capacity $capacity - DeploymentType $type
90
87
$exitCode = $LASTEXITCODE
91
88
92
89
if ($exitCode -ne 0 ) {
93
90
if ($exitCode -eq 2 ) {
94
- exit 1
91
+ exit 1 # already printed, graceful
95
92
}
96
93
Write-Error " ❌ ERROR: Quota validation failed for model deployment: $name "
97
94
$QuotaAvailable = $false
98
95
}
99
96
}
100
97
101
98
if (-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."
103
100
exit 1
104
101
} else {
105
102
Write-Host " ✅ All model deployments passed quota validation successfully."
106
103
exit 0
107
- }
104
+ }
0 commit comments