Skip to content

Commit b035ca5

Browse files
Fixing #596 - Allowing Location within deploymentTemplates (#604)
Co-authored-by: James Brundage <@github.com>
1 parent 7277e5b commit b035ca5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

arm-ttk/testcases/deploymentTemplate/Location-Should-Not-Be-Hardcoded.test.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ if ($TemplateObjectCopy.parameters.psobject -ne $null) {
4040

4141
# Determine where the parameters section is within the JSON
4242
$paramsSection = Resolve-JSONContent -JSONPath 'parameters' -JSONText $TemplateText
43+
$deployments = Find-JsonContent -InputObject $TemplateObject -Key type -Value Microsoft.Resources/deployments | # Find any deployments
44+
Resolve-JSONContent -JSONText $TemplateText -JSONPath { $_.JsonPath -replace '\.type$' } # and then resolve the resource they are in.
45+
46+
$ignoredRanges =
47+
@() + @(
48+
if ($paramsSection.Index -and $paramSection.Length) {
49+
$paramsSection.Index..($paramsSection.Index + $paramsSection.Length)
50+
}
51+
) + @(
52+
foreach ($deployment in $deployments) {
53+
$deployment.Index..($deployment.Index + $deployment.Length)
54+
}
55+
)
56+
4357
$LocationRegex = '(?>resourceGroup|deployment)\(\).location'
4458

4559

@@ -74,7 +88,7 @@ else {
7488
$foundResourceGroupLocations = [Regex]::Matches($TemplateText, $LocationRegex, 'IgnoreCase')
7589

7690
foreach ($spotFound in $foundResourceGroupLocations) {
77-
if ($spotFound.Index -ge $paramsSection.Index -and $spotFound.Index -le ($paramsSection.Index + $paramsSection.Length)) {
91+
if ($spotFound.Index -in $ignoredRanges) {
7892
continue
7993
}
8094
Write-Error "$TemplateFileName must use the location parameter, not resourceGroup().location or deployment().location (except when used as a default value in the main template)" -ErrorId Location.Parameter.Should.Be.Used -TargetObject $parameter

0 commit comments

Comments
 (0)