Skip to content

Commit

Permalink
feat: Introduce limited location list (#1006)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSidebotham authored Feb 17, 2024
1 parent a293736 commit 651de62
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Set the location for the resource deployment.
.DESCRIPTION
This script is used to set the location for the resource deployment.
.PARAMETER AllowedRegionsList
Optional. The list of regions to be considered for the selection.
.PARAMETER ExcludedRegions
Optional. The list of regions to be excluded from the selection.
Expand All @@ -29,6 +32,14 @@ function Get-AzAvailableResourceLocation {
[Parameter(Mandatory = $false)]
[string] $RepoRoot = (Get-Item -Path $PSScriptRoot).parent.parent.parent.parent.parent.FullName,

[Parameter(Mandatory = $false)]
[array] $AllowedRegionsList = @(
'eastus',
'uksouth',
'northeurope',
'eastasia' # Including as Edge Region for services like static-site
),

[Parameter(Mandatory = $true)]
[string] $ModuleRoot,

Expand Down Expand Up @@ -72,7 +83,7 @@ function Get-AzAvailableResourceLocation {
Write-Verbose "Region list: $($resourceRegionList | ConvertTo-Json)"

if ($resourceRegionList -eq "global" -or $null -eq $resourceRegionList) {
Write-Verbose "Resource is global, default region [$GlobalResourceGroupLocation] will be used for resource group creation"
Write-Verbose "Resource is global or does not have a location in the Resource Providers API, default region [$GlobalResourceGroupLocation] will be used for resource group creation"
$location = $GlobalResourceGroupLocation # Set Location to resource group location. Globabl resources should have hardocded location in `main.bicep`
}
else {
Expand All @@ -85,13 +96,13 @@ function Get-AzAvailableResourceLocation {
} | Select-Object -ExpandProperty Location
Write-Verbose "Available Locations: $($locations | ConvertTo-Json)"


$index = Get-Random -Maximum ($locations.Count)
$filteredAllowedLocations = @($locations | Where-Object { $_ -in $AllowedRegionsList })
Write-Verbose "Filtered allowed locations: $($filteredAllowedLocations | ConvertTo-Json)"
$index = Get-Random -Maximum ($filteredAllowedLocations.Count)
Write-Verbose "Generated random index [$index]"

$location = $locations[$index]

$location = $filteredAllowedLocations[$index]
}

Write-Verbose "Selected location [$location]" -Verbose

return $location
Expand Down

0 comments on commit 651de62

Please sign in to comment.