Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function Add-AvailabilityZonesBicepParameter {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $true)]
[Alias("Output")]
[Alias("OutputDirectory")]
[Alias("O")]
[string] $alzEnvironmentDestination,

[Parameter(Mandatory = $true)]
[PSCustomObject]$configFile
)

$parametersConfig = @(
[pscustomobject]@{
source = "hubNetworking.parameters.all.json";
parameters = "parAzErGatewayAvailabilityZones,parAzVpnGatewayAvailabilityZones,parAzFirewallAvailabilityZones"
}
[pscustomobject]@{
source = "vwanConnectivity.parameters.all.json";
parameters = "parAzFirewallAvailabilityZones"
}
)

foreach ($parametersFile in $parametersConfig) {
$parametersFilePath = Join-Path -Path $alzEnvironmentDestination "config\custom-parameters\$($parametersFile.source)"
$region = (Get-Content $parametersFilePath | ConvertFrom-Json).parameters.parLocation.Value
$zones = ($configFile.PsObject.Properties["zonesSupport"].Value | Where-Object { $_.region -eq $region }).zones
$parametersFileJsonContent = Get-Content -Path $parametersFilePath -Raw
$jsonObject = $parametersFileJsonContent | ConvertFrom-Json
$parametersFile.parameters.Split(",") | ForEach-Object {
$parameter = $_
try {
if ($null -eq $jsonObject.parameters.$parameter.value) {
$jsonObject.parameters.$parameter.value = @($zones)
}

else {
$jsonObject.parameters.$parameter.value = $zones
}

}

catch {
Write-Error -Message "The parameter $parameter does not exist in the file $parametersFilePath"
}
}
$parametersFileJsonContent = $jsonObject | ConvertTo-Json -Depth 10
Set-Content -Path $parametersFilePath -Value $parametersFileJsonContent
}
}
1 change: 1 addition & 0 deletions src/ALZ/Private/Legacy-Bicep/New-ALZEnvironmentBicep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function New-ALZEnvironmentBicep {
Set-ComputedConfiguration -configuration $configuration | Out-String | Write-Verbose
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $targetDirectory -configuration $configuration | Out-String | Write-Verbose
Build-ALZDeploymentEnvFile -configuration $configuration -Destination $targetDirectory -version $upstreamReleaseVersion | Out-String | Write-Verbose
Add-AvailabilityZonesBicepParameter -alzEnvironmentDestination $alzEnvironmentDestination -configFile $bicepConfig| Out-String | Write-Verbose

if($local) {
$isGitRepo = Test-ALZGitRepository -alzEnvironmentDestination $targetDirectory -autoApprove:$autoApprove.IsPresent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = 'ALZ'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
#if the module is already in memory, remove it
Remove-Module -Name $ModuleName -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------

InModuleScope 'ALZ' {
Describe "Add-AvailabilityZonesBicepParameter" {
BeforeAll {
$alzEnvironmentDestination = "TestDrive:\"
$hubParametersPath = "https://raw.githubusercontent.com/Azure/ALZ-Bicep/main/infra-as-code/bicep/modules/hubNetworking/parameters/hubNetworking.parameters.all.json"
Invoke-WebRequest -Uri $hubParametersPath -OutFile "$alzEnvironmentDestination\hubNetworking.parameters.all.json"
}
Context "Hub networking parameters availability zones check" {
BeforeAll {
Mock -CommandName Join-Path -MockWith {
$alzEnvironmentDestination + "\hubNetworking.parameters.all.json"
}
Mock -CommandName Get-Content -ParameterFilter { $Path -contains 'parametersFilePath' } -MockWith {
Get-Content -Path "TestDrive:\hubNetworking.parameters.all.json"
}
}
It "Should add 3 availability zones for hub networking parameters" {
Add-AvailabilityZonesBicepParameter -alzEnvironmentDestination $alzEnvironmentDestination -configFile ([PSCustomObject]@{
zonesSupport = @(
[PSCustomObject]@{
region = "eastus"
zones = @("1", "2", "3")
}
)
})
$parametersFileJsonContent = Get-Content -Path "TestDrive:\hubNetworking.parameters.all.json" -Raw
$jsonObject = $parametersFileJsonContent | ConvertFrom-Json
$jsonObject.parameters.parAzErGatewayAvailabilityZones.value | Should -Be @("1", "2", "3")
$jsonObject.parameters.parAzVpnGatewayAvailabilityZones.value | Should -Be @("1", "2", "3")
$jsonObject.parameters.parAzFirewallAvailabilityZones.value | Should -Be @("1", "2", "3")
}
It "Should add 2 availability zones for hub networking parameters" {
Add-AvailabilityZonesBicepParameter -alzEnvironmentDestination $alzEnvironmentDestination -configFile ([PSCustomObject]@{
zonesSupport = @(
[PSCustomObject]@{
region = "eastus"
zones = @("1", "2")
}
)
})
$parametersFileJsonContent = Get-Content -Path "TestDrive:\hubNetworking.parameters.all.json" -Raw
$jsonObject = $parametersFileJsonContent | ConvertFrom-Json
$jsonObject.parameters.parAzErGatewayAvailabilityZones.value | Should -Be @("1", "2")
$jsonObject.parameters.parAzVpnGatewayAvailabilityZones.value | Should -Be @("1", "2")
$jsonObject.parameters.parAzFirewallAvailabilityZones.value | Should -Be @("1", "2")
}
It "Should add 0 availability zones for hub networking parameters" {
Add-AvailabilityZonesBicepParameter -alzEnvironmentDestination $alzEnvironmentDestination -configFile ([PSCustomObject]@{
zonesSupport = @(
[PSCustomObject]@{
region = "eastus"
zones = @()
}
)
})
$parametersFileJsonContent = Get-Content -Path "TestDrive:\hubNetworking.parameters.all.json" -Raw
$jsonObject = $parametersFileJsonContent | ConvertFrom-Json
$jsonObject.parameters.parAzErGatewayAvailabilityZones.value | Should -Be @()
$jsonObject.parameters.parAzVpnGatewayAvailabilityZones.value | Should -Be @()
$jsonObject.parameters.parAzFirewallAvailabilityZones.value | Should -Be @()
}
}
}

}