Skip to content

Commit 4bd4781

Browse files
authored
improved error message (#628)
1 parent f9ab9f4 commit 4bd4781

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@
55
Ensures that the Sizes of a virtual machine in a template are parameters
66
#>
77
param(
8-
[Parameter(Mandatory=$true)]
9-
[PSObject]
10-
$TemplateObject
8+
[Parameter(Mandatory = $true)]
9+
[PSObject]
10+
$TemplateObject
1111
)
1212

1313
$vmSizes = $TemplateObject.resources | Find-JsonContent -Key vmSize -Value * -Like
1414

1515
foreach ($vmSizeObject in $vmSizes) {
1616

1717
$vmSize = $vmSizeObject.vmSize
18+
$resourceType = $vmSizeObject.ParentObject.type
19+
$resourceName = $vmSizeObject.ParentObject.name
1820

1921
if ($vmSize -notmatch "\s{0,}\[.*?parameters\s{0,}\(\s{0,}'") {
2022
if ($vmSize -match "\s{0,}\[.*?variables\s{0,}\(\s{0,}'") {
2123
$resolvedVmSize = Expand-AzTemplate -Expression $vmSize -InputObject $TemplateObject
2224
if ($resolvedVmSize -notmatch "\s{0,}\[.*?parameters\s{0,}\(\s{0,}'") {
23-
Write-Error "VM Size must be a parameter" -TargetObject $vm
25+
Write-Error "VM Size for resourceType '$resourceType' named '$resourceName' must be a parameter" -TargetObject $vm
2426
}
25-
} else {
26-
Write-Error "VM Size must be a parameter" -TargetObject $vm
27+
}
28+
else {
29+
Write-Error "VM Size for resourceType '$resourceType' named '$resourceName' must be a parameter" -TargetObject $vm
2730
}
2831
}
32+
2933
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
{
5+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
6+
"contentVersion": "1.0.0.0",
7+
"parameters": {
8+
"_artifactsLocation": {
9+
"type": "string"
10+
},
11+
"_artifactsLocationSasToken": {
12+
"type": "securestring"
13+
}
14+
},
15+
"variables": {
16+
"vmTemplateLink": "[concat(parameters('_artifactsLocation'),'common/vm.json', parameters('_artifactsLocationSasToken'))]"
17+
},
18+
"resources": [
19+
{
20+
"name": "Deploy_VM",
21+
"type": "Microsoft.Resources/deployments",
22+
"apiVersion": "2020-10-01",
23+
"properties": {
24+
"mode": "Incremental",
25+
"templateLink": {
26+
"uri": "[variables('vmTemplateLink')]"
27+
},
28+
"parameters": {
29+
"vmSize": {
30+
"value": "Standard_D2_v3"
31+
}
32+
}
33+
}
34+
}
35+
]
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
{
5+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
6+
"contentVersion": "1.0.0.0",
7+
"parameters": {
8+
"vmSize": {
9+
"type": "object"
10+
},
11+
"_artifactsLocation": {
12+
"type": "string"
13+
},
14+
"_artifactsLocationSasToken": {
15+
"type": "securestring"
16+
}
17+
},
18+
"variables": {
19+
"vmTemplateLink": "[concat(parameters('_artifactsLocation'),'common/vm.json', parameters('_artifactsLocationSasToken'))]"
20+
},
21+
"resources": [
22+
{
23+
"name": "[concat('Deploy_VM', copyIndex())]",
24+
"type": "Microsoft.Resources/deployments",
25+
"apiVersion": "2020-10-01",
26+
"properties": {
27+
"mode": "Incremental",
28+
"templateLink": {
29+
"uri": "[variables('vmTemplateLink')]"
30+
},
31+
"parameters": {
32+
"vmSize": {
33+
"value": "[parameters('vmSize')]"
34+
}
35+
}
36+
}
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)