Unexpected results in Parameter-Types-Should-Be-Consistent
- Dominant language
- PowerShell
- Stars
- 468
- Forks
- 208
- PR merge metrics
- No merged PRs in 30d
Description
Hi All,
Thanks for creating the validation tool.
I have found that there are 2 edge cases in Parameter-Types-Should-Be-Consistent where we are not getting the expected behavior:
### 1. Nested deployment output of type _int_ -> nested deployment input of type _string_ should fail
Template:
```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"resources": [
{
"name": "nestedDeployment1",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {
"output1": {
"type": "int",
"value": 1
}
}
}
}
},
{
"name": "nestedDeployment2",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"parameter1": {
"value": "[reference(resourceId('Microsoft.Resources/deployments', 'nestedDeployment1')).outputs.output1.value]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"parameter1": {
"type": "string",
"metadata": {
"description": "description"
}
}
},
"variables": {},
"resources": [],
"outputs": {}
}
}
}
],
"outputs": {}
}
```
Test results:
```bash
$ pwsh --Command 'Import-Module .\arm-ttk\arm-ttk.psd1 -Force; ./unit-tests/Parameter-Types-Should-Be-Consistent/Parameter-Types-Should-Be-Consistent.tests.ps1'
Describing Parameter-Types-Should-Be-Consistent
Context Fail
[+] Validates grandchild is flagged 1.09s
[+] Validates InconsistentParameterTypes is flagged 65ms
[-] Validates InconsistentParameterTypesOutput is flagged 100ms
RuntimeException: Errors were expected
at , /home/nagyako/arm-ttk/arm-ttk/unit-tests/arm-ttk.test.functions.ps1: line 131
```
The deployment fails with the below error:

"Deployment template validation failed: 'Template parameter 'parameter1' was provided an invalid value. Expected a value of type 'String, Uri', but received a value of type 'Integer'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.
### 2. Nested deployment output of type _array_ -> nested deployment input of type _array_ should pass
Template:
```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.8.9.13224",
"templateHash": "12511175399169845925"
}
},
"parameters": {
"project": {
"type": "string",
"defaultValue": "Foo"
}
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-10-01",
"name": "[format('{0}nestedDeployment1', parameters('project'))]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.8.9.13224",
"templateHash": "4279842583979532621"
}
},
"resources": [
{
"copy": {
"name": "nestedDeployments",
"count": "[length(range(0, 2))]"
},
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "[format('nestedDeployment{0}', range(0, 2)[copyIndex()])]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": []
}
}
}
],
"outputs": {
"deploymentNames": {
"type": "array",
"copy": {
"count": "[length(range(0, 2))]",
"input": "[format('nestedDeployment{0}', range(0, 2)[range(0, 2)[copyIndex()]])]"
}
}
}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-10-01",
"name": "[format('{0}nestedDeployment2', parameters('project'))]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"deploymentNames": {
"value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}nestedDeployment1', parameters('project')))).outputs.deploymentNames.value]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.8.9.13224",
"templateHash": "11588361600448277843"
}
},
"parameters": {
"deploymentNames": {
"type": "array"
}
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "[format('{0}a', parameters('deploymentNames')[0])]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": []
}
}
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', format('{0}nestedDeployment1', parameters('project')))]"
]
}
]
}
```
Test results:
```bash
Context Pass
[+] Validates ConsistentParameterTypes is correct 61ms
[-] Validates ConsistentParameterTypesOutput is correct 578ms
RuntimeException: Write-Error: /home/nagyako/arm-ttk/arm-ttk/arm-ttk/Test-AzTemplate.ps1:253
Line |
253 | . $myModule $TheTest @testInput 2>&1 3>&1
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Type Mismatch: Parameter 'deploymentNames' in nested template '[format('{0}nestedDeployment2', parameters('project'))]' is defined as array, but the parent template defines it as string).
at , /home/nagyako/arm-ttk/arm-ttk/unit-tests/arm-ttk.test.functions.ps1: line 96
[+] Validates grandchild is correct 77ms
```
The second template was generated from bicep and works fine:

If the referenced resource name is literal and does not contain a parameter like `format('{0}nestedDeployment1', parameters('project'))` then the test is passing.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with unit-tests/Parameter-Types-Should-Be-Consistent/Parameter-Types-Should-Be-Consistent.tests.ps1 and inspect the nested deployment handling in Test-AzTemplate.ps1, especially around line 253. Reproduce both templates, then trace how parameter and output types are inferred for resource names using format expressions. Done means the integer-to-string case is flagged and the array-to-array case passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100