Skip to content

Commit c52c8dc

Browse files
authored
Merge pull request Azure#754 from psah434/master
Addressing fixes for GitHub issues 738, 753 and 745
2 parents 45f84e6 + fd081f3 commit c52c8dc

File tree

4 files changed

+229
-3
lines changed

4 files changed

+229
-3
lines changed

arm-ttk/testcases/deploymentTemplate/Parameter-Types-Should-Be-Consistent.test.ps1

+11-3
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,23 @@ foreach ($inner in $originalInnerTemplates) {
4747

4848
foreach ($parent in $inner.ParentObject) { # Walk up the list of parent objects until
4949
if ($parent.parameters.$mappedParameterName.type -and # We find this parameter defined
50-
$parent.parameters.$mappedParameterName.type -ne $innerTemplateParameterType -and # with a different type.
51-
$innerTemplateParam.Value.value -notmatch "\[parameters(?<mappedParameterName>\(.*\))(\[.*?\]|\.)(.*)\]" # https://regex101.com/r/ao6tsK/1 https://github.com/Azure/arm-ttk/issues/635
50+
$parent.parameters.$mappedParameterName.type -ne $innerTemplateParameterType # with a different type.
5251
) {
52+
$innerTemplateParamValue = $innerTemplateParam.Value
53+
$regexParam = "\[.*parameters(?<mappedParameterName>\(.*\))(\[.*?\]|\.|\,)(.*)\]" # https://regex101.com/r/V0dzVv/1 and https://regex101.com/r/ao6tsK/1 https://github.com/Azure/arm-ttk/issues/635
54+
if($null -ne $innerTemplateParamValue.value)
55+
{
56+
$innerTemplateParamValue = $innerTemplateParamValue.value
57+
}
58+
if(($innerTemplateParamValue -is [string]) -and ($innerTemplateParamValue -notmatch $regexParam))
59+
{
5360
# If this is the case, write an error
5461
Write-Error -ErrorId Inconsistent.Parameter -Message "Type Mismatch: Parameter '$parameterName' in nested template '$($inner.ParentObject[0].name)' is defined as $innerTemplateParameterType, but the parent template defines it as $($parent.parameters.$mappedParameterName.type))." -TargetObject ([PSCustomObject]@{
5562
JSONPath = $inner.JSONPath + ".parameters.$parameterName"
5663
})
5764
break # and then stop processing, because we only wish to compare this against the immediate parent template.
65+
}
5866
}
5967
}
6068
}
61-
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"metadata": {
5+
"_generator": {
6+
"name": "bicep",
7+
"version": "0.22.6.54827",
8+
"templateHash": "2557909781805504768"
9+
}
10+
},
11+
"parameters": {
12+
"choice": {
13+
"type": "bool"
14+
}
15+
},
16+
"resources": [
17+
{
18+
"type": "Microsoft.Resources/deployments",
19+
"apiVersion": "2022-09-01",
20+
"name": "module1",
21+
"location": "[deployment().location]",
22+
"properties": {
23+
"expressionEvaluationOptions": {
24+
"scope": "inner"
25+
},
26+
"mode": "Incremental",
27+
"parameters": {
28+
"intext": "[if(parameters('choice'), createObject('value', 'foo'), createObject('value', 'bar'))]"
29+
},
30+
"template": {
31+
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
32+
"contentVersion": "1.0.0.0",
33+
"metadata": {
34+
"_generator": {
35+
"name": "bicep",
36+
"version": "0.22.6.54827",
37+
"templateHash": "10164220933236466129"
38+
}
39+
},
40+
"parameters": {
41+
"intext": {
42+
"type": "string"
43+
}
44+
},
45+
"resources": [],
46+
"outputs": {
47+
"outtext": {
48+
"type": "string",
49+
"value": "[parameters('intext')]"
50+
}
51+
}
52+
}
53+
}
54+
}
55+
]
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"metadata": {
5+
"_generator": {
6+
"name": "bicep",
7+
"version": "0.13.1.58284",
8+
"templateHash": "6364080903705651062"
9+
}
10+
},
11+
"parameters": {
12+
"textParam2": {
13+
"type": "string",
14+
"defaultValue": "container2"
15+
}
16+
},
17+
"resources": [
18+
{
19+
"type": "Microsoft.Resources/deployments",
20+
"apiVersion": "2020-10-01",
21+
"name": "mod1",
22+
"properties": {
23+
"expressionEvaluationOptions": {
24+
"scope": "inner"
25+
},
26+
"mode": "Incremental",
27+
"parameters": {
28+
"arrayParam": {
29+
"value": [
30+
"first",
31+
"[parameters('textParam2')]",
32+
"last"
33+
]
34+
}
35+
},
36+
"template": {
37+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
38+
"contentVersion": "1.0.0.0",
39+
"metadata": {
40+
"_generator": {
41+
"name": "bicep",
42+
"version": "0.13.1.58284",
43+
"templateHash": "279482116342234053"
44+
}
45+
},
46+
"parameters": {
47+
"arrayParam": {
48+
"type": "array",
49+
"defaultValue": []
50+
}
51+
},
52+
"resources": [],
53+
"outputs": {
54+
"outArray": {
55+
"type": "array",
56+
"value": "[parameters('arrayParam')]"
57+
}
58+
}
59+
}
60+
}
61+
}
62+
]
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"metadata": {
5+
"_generator": {
6+
"name": "bicep",
7+
"version": "0.22.6.54827",
8+
"templateHash": "12026618333363551042"
9+
}
10+
},
11+
"parameters": {
12+
"input": {
13+
"type": "object"
14+
}
15+
},
16+
"resources": [
17+
{
18+
"type": "Microsoft.Resources/deployments",
19+
"apiVersion": "2022-09-01",
20+
"name": "[parameters('input').module_one]",
21+
"properties": {
22+
"expressionEvaluationOptions": {
23+
"scope": "inner"
24+
},
25+
"mode": "Incremental",
26+
"parameters": {
27+
"intext": {
28+
"value": "hello"
29+
}
30+
},
31+
"template": {
32+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
33+
"contentVersion": "1.0.0.0",
34+
"metadata": {
35+
"_generator": {
36+
"name": "bicep",
37+
"version": "0.22.6.54827",
38+
"templateHash": "15717468013965412695"
39+
}
40+
},
41+
"parameters": {
42+
"intext": {
43+
"type": "string"
44+
}
45+
},
46+
"resources": [],
47+
"outputs": {
48+
"outtext": {
49+
"type": "string",
50+
"value": "[parameters('intext')]"
51+
}
52+
}
53+
}
54+
}
55+
},
56+
{
57+
"type": "Microsoft.Resources/deployments",
58+
"apiVersion": "2022-09-01",
59+
"name": "moduleTwo",
60+
"properties": {
61+
"expressionEvaluationOptions": {
62+
"scope": "inner"
63+
},
64+
"mode": "Incremental",
65+
"parameters": {
66+
"intext": {
67+
"value": "[reference(resourceId('Microsoft.Resources/deployments', parameters('input').module_one), '2022-09-01').outputs.outtext.value]"
68+
}
69+
},
70+
"template": {
71+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
72+
"contentVersion": "1.0.0.0",
73+
"metadata": {
74+
"_generator": {
75+
"name": "bicep",
76+
"version": "0.22.6.54827",
77+
"templateHash": "15717468013965412695"
78+
}
79+
},
80+
"parameters": {
81+
"intext": {
82+
"type": "string"
83+
}
84+
},
85+
"resources": [],
86+
"outputs": {
87+
"outtext": {
88+
"type": "string",
89+
"value": "[parameters('intext')]"
90+
}
91+
}
92+
}
93+
},
94+
"dependsOn": [
95+
"[resourceId('Microsoft.Resources/deployments', parameters('input').module_one)]"
96+
]
97+
}
98+
]
99+
}

0 commit comments

Comments
 (0)