Skip to content

Commit

Permalink
Fixing #596 - Allowing Location within deploymentTemplates (#604)
Browse files Browse the repository at this point in the history
Co-authored-by: James Brundage <@github.com>
  • Loading branch information
StartAutomating authored Mar 11, 2022
1 parent 7277e5b commit b035ca5
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ if ($TemplateObjectCopy.parameters.psobject -ne $null) {

# Determine where the parameters section is within the JSON
$paramsSection = Resolve-JSONContent -JSONPath 'parameters' -JSONText $TemplateText
$deployments = Find-JsonContent -InputObject $TemplateObject -Key type -Value Microsoft.Resources/deployments | # Find any deployments
Resolve-JSONContent -JSONText $TemplateText -JSONPath { $_.JsonPath -replace '\.type$' } # and then resolve the resource they are in.

$ignoredRanges =
@() + @(
if ($paramsSection.Index -and $paramSection.Length) {
$paramsSection.Index..($paramsSection.Index + $paramsSection.Length)
}
) + @(
foreach ($deployment in $deployments) {
$deployment.Index..($deployment.Index + $deployment.Length)
}
)

$LocationRegex = '(?>resourceGroup|deployment)\(\).location'


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

foreach ($spotFound in $foundResourceGroupLocations) {
if ($spotFound.Index -ge $paramsSection.Index -and $spotFound.Index -le ($paramsSection.Index + $paramsSection.Length)) {
if ($spotFound.Index -in $ignoredRanges) {
continue
}
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
Expand Down

0 comments on commit b035ca5

Please sign in to comment.