forked from Azure/ALZ-PowerShell-Module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-AvailabilityZonesBicepParameters.ps1
More file actions
51 lines (45 loc) · 2.04 KB
/
Add-AvailabilityZonesBicepParameters.ps1
File metadata and controls
51 lines (45 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
}
}