Skip to content

Commit 4da6d95

Browse files
Fixing VMSize Test: No Longer Checking for top-level parameter (#710)
* Fixing VMSize Test: No Longer Checking for top-level parameter (Fixes #695) * Allowing VMSize to be in any parameter, not just top-level parameters * Adding VMSize-With-Alternate-Parameter-Name passing test * Updating VMSize test: Not considering resource parameters as valid values * Removing NestedVMSize failure test * Update VMSize-With-Alternate-Parameter-Name.json Co-authored-by: James Brundage <@github.com> Co-authored-by: Brian Moore <[email protected]>
1 parent 7f568a1 commit 4da6d95

File tree

3 files changed

+43
-112
lines changed

3 files changed

+43
-112
lines changed

arm-ttk/testcases/deploymentTemplate/VM-Size-Should-Be-A-Parameter.test.ps1

+12-10
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,26 @@ foreach ($vmSizeObject in $vmSizes) {
3333

3434
$vmSize = $vmSizeObject.vmSize
3535
# If the vmSize was in a parameter, we will want to continue
36-
if ($vmSizeObject.JSONPath -match '^parameters\.vmsize$') {
36+
if ($vmSizeObject.JSONPath -match '^parameters' -or
37+
$vmSizeObject.JSONPath -match '\.parameters\.') {
3738
# but not before we check if it was an inner template
3839
if ($vmSizeObject.ParentObject[0].expressionEvaluationOptions.scope -eq 'inner') {
3940
# If it was an inner template, check to make sure that the inner template contains a vmSize
40-
if (-not $vmSize.Value | ?<ARM_Parameter> -Parameter vmSize) {
41-
Write-Error "Nested template parameter vmSize does not map to vmSize parameter" -TargetObject $vmSizeObject
41+
if (-not ($vmSize.Value | ?<ARM_Parameter>)) {
42+
Write-Error "Nested template parameter vmSize does not map to a parameter" -TargetObject $vmSizeObject
4243
continue
4344
}
4445
} else {
46+
4547
# Otherwise, make note of the fact that we have a parameter called VMSize
4648
$vmSizeTopLevelParameterDeclared = $true
4749
}
48-
continue
50+
51+
# If the VMSize was in the properties passed to a template, it is not declaring the parameter.
52+
# Therefore, if we determine that we are examining properties, we should validate this as any other VMSize parameter.
53+
if ($vmSizeObject.JSONPath -notmatch 'resources\[\d+\]\.properties\.parameters') {
54+
continue
55+
}
4956
}
5057

5158
# The only other places we should find VMSizes are in resources.
@@ -55,7 +62,7 @@ foreach ($vmSizeObject in $vmSizes) {
5562
$resourceName = $vmSizeObject.ParentObject.name
5663

5764

58-
if (-not $vmSize | ?<ARM_Parameter>) { # If the VMSize does not have a parameter reference
65+
if (-not ($vmSize | ?<ARM_Parameter>)) { # If the VMSize does not have a parameter reference
5966
if ($vmSize | ?<ARM_Variable>) { # but does have a variable reference
6067
# try expanding the variable
6168
$resolvedVmSize = Expand-AzTemplate -Expression $vmSize -InputObject $OriginalTemplateObject
@@ -70,9 +77,4 @@ foreach ($vmSizeObject in $vmSizes) {
7077
Write-Error "VM Size for resourceType '$resourceType' named '$resourceName' must be a parameter" -TargetObject $vm
7178
}
7279
}
73-
}
74-
75-
if ($vmSizes -and -not $vmSizeTopLevelParameterDeclared) {
76-
Write-Error "VMSize parameter must be declared for the parent template"
77-
return
7880
}

unit-tests/VM-Size-Should-Be-A-Parameter/Fail/NestedVMSize.json

-102
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"nodeSku": {}
6+
},
7+
"resources": [
8+
{
9+
"type": "Microsoft.MachineLearningServices/workspaces/computes",
10+
"apiVersion": "2018-11-19",
11+
"name": "[concat(parameters('workspaceName'), '/gpu-cluster')]",
12+
"location": "[parameters('location')]",
13+
"properties": {
14+
"computeType": "AmlCompute",
15+
"computeLocation": "[parameters('location')]",
16+
"description": "gpu nodes",
17+
"properties": {
18+
"remoteLoginPortPublicAccess": "Enabled",
19+
"scaleSettings": {
20+
"maxNodeCount": 4,
21+
"minNodeCount": 0
22+
},
23+
"subnet": {
24+
"id": "[variables('subnet')]"
25+
},
26+
"vmSize": "[parameters('nodeSku')]"
27+
}
28+
}
29+
}
30+
]
31+
}

0 commit comments

Comments
 (0)