-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathEdit-ALZConfigurationFilesInPlace.ps1
More file actions
43 lines (37 loc) · 1.68 KB
/
Edit-ALZConfigurationFilesInPlace.ps1
File metadata and controls
43 lines (37 loc) · 1.68 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
function Edit-ALZConfigurationFilesInPlace {
param(
[Parameter(Mandatory = $false)]
[Alias("Output")]
[Alias("OutputDirectory")]
[Alias("O")]
[string] $alzEnvironmentDestination = ".",
[Parameter(Mandatory = $true)]
[object] $configuration
)
$locations = @("orchestration", "customization")
$files = @()
foreach ($location in $locations) {
$bicepModules = Join-Path $alzEnvironmentDestination $location
$files += @(Get-ChildItem -Path $bicepModules -Recurse -Filter *.parameters.json)
}
foreach ($file in $files) {
$bicepConfiguration = Get-Content $file.FullName | ConvertFrom-Json -AsHashtable
$modified = $false
foreach ($configKey in $configuration.PsObject.Properties) {
foreach ($target in $configKey.Value.Targets) {
if ($target.Destination -eq "Parameters" -and $null -ne $bicepConfiguration.parameters[$target.Name]) {
if ($configKey.Value.Type -eq "Computed") {
$bicepConfiguration.parameters[$target.Name].value = Format-TokenizedConfigurationString $configKey.Value.Value $configuration
} else {
$bicepConfiguration.parameters[$target.Name].value = $configKey.Value.Value
}
$modified = $true
}
}
}
if ($true -eq $modified) {
Write-InformationColored $file.FullName -ForegroundColor Yellow -InformationAction Continue
$bicepConfiguration | ConvertTo-Json -Depth 10 | Out-File $file.FullName
}
}
}