Skip to content

Commit

Permalink
Merge pull request #754 from psah434/master
Browse files Browse the repository at this point in the history
Addressing fixes for GitHub issues 738, 753 and 745
  • Loading branch information
psah434 authored Nov 20, 2023
2 parents 45f84e6 + fd081f3 commit c52c8dc
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,23 @@ foreach ($inner in $originalInnerTemplates) {

foreach ($parent in $inner.ParentObject) { # Walk up the list of parent objects until
if ($parent.parameters.$mappedParameterName.type -and # We find this parameter defined
$parent.parameters.$mappedParameterName.type -ne $innerTemplateParameterType -and # with a different type.
$innerTemplateParam.Value.value -notmatch "\[parameters(?<mappedParameterName>\(.*\))(\[.*?\]|\.)(.*)\]" # https://regex101.com/r/ao6tsK/1 https://github.com/Azure/arm-ttk/issues/635
$parent.parameters.$mappedParameterName.type -ne $innerTemplateParameterType # with a different type.
) {
$innerTemplateParamValue = $innerTemplateParam.Value
$regexParam = "\[.*parameters(?<mappedParameterName>\(.*\))(\[.*?\]|\.|\,)(.*)\]" # https://regex101.com/r/V0dzVv/1 and https://regex101.com/r/ao6tsK/1 https://github.com/Azure/arm-ttk/issues/635
if($null -ne $innerTemplateParamValue.value)
{
$innerTemplateParamValue = $innerTemplateParamValue.value
}
if(($innerTemplateParamValue -is [string]) -and ($innerTemplateParamValue -notmatch $regexParam))
{
# If this is the case, write an error
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]@{
JSONPath = $inner.JSONPath + ".parameters.$parameterName"
})
break # and then stop processing, because we only wish to compare this against the immediate parent template.
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.22.6.54827",
"templateHash": "2557909781805504768"
}
},
"parameters": {
"choice": {
"type": "bool"
}
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "module1",
"location": "[deployment().location]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"intext": "[if(parameters('choice'), createObject('value', 'foo'), createObject('value', 'bar'))]"
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.22.6.54827",
"templateHash": "10164220933236466129"
}
},
"parameters": {
"intext": {
"type": "string"
}
},
"resources": [],
"outputs": {
"outtext": {
"type": "string",
"value": "[parameters('intext')]"
}
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.13.1.58284",
"templateHash": "6364080903705651062"
}
},
"parameters": {
"textParam2": {
"type": "string",
"defaultValue": "container2"
}
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-10-01",
"name": "mod1",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"arrayParam": {
"value": [
"first",
"[parameters('textParam2')]",
"last"
]
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.13.1.58284",
"templateHash": "279482116342234053"
}
},
"parameters": {
"arrayParam": {
"type": "array",
"defaultValue": []
}
},
"resources": [],
"outputs": {
"outArray": {
"type": "array",
"value": "[parameters('arrayParam')]"
}
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.22.6.54827",
"templateHash": "12026618333363551042"
}
},
"parameters": {
"input": {
"type": "object"
}
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "[parameters('input').module_one]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"intext": {
"value": "hello"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.22.6.54827",
"templateHash": "15717468013965412695"
}
},
"parameters": {
"intext": {
"type": "string"
}
},
"resources": [],
"outputs": {
"outtext": {
"type": "string",
"value": "[parameters('intext')]"
}
}
}
}
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "moduleTwo",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"intext": {
"value": "[reference(resourceId('Microsoft.Resources/deployments', parameters('input').module_one), '2022-09-01').outputs.outtext.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.22.6.54827",
"templateHash": "15717468013965412695"
}
},
"parameters": {
"intext": {
"type": "string"
}
},
"resources": [],
"outputs": {
"outtext": {
"type": "string",
"value": "[parameters('intext')]"
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', parameters('input').module_one)]"
]
}
]
}

0 comments on commit c52c8dc

Please sign in to comment.