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
4 changes: 0 additions & 4 deletions src/ALZ/Private/Build-ALZDeploymentEnvFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ function Build-ALZDeploymentEnvFile {
if ($target.Destination -eq "Environment") {

$formattedValue = $configurationValue.Value.Value
if ($configurationValue.Value.Type -eq "Computed") {
$formattedValue = Format-TokenizedConfigurationString -tokenizedString $configurationValue.Value.Value -configuration $configuration
}

Add-Content -Path $envFile -Value "$($($target.Name))=`"$formattedValue`"" | Out-String | Write-Verbose
}
}
Expand Down
32 changes: 1 addition & 31 deletions src/ALZ/Private/Edit-ALZConfigurationFilesInPlace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,7 @@ function Edit-ALZConfigurationFilesInPlace {
# If we're here, we can modify this file and we've got an actual object specified by the Name path value - and we can modify values on it.
if ($target.Destination -eq "Parameters" -and $null -ne $bicepConfigNode) {
$leafPropertyName = $propertyNames[-1]

if ($configKey.Value.Type -eq "Computed") {
# If the value type is computed we replace the value with another which already exists in the configuration hierarchy.
if ($configKey.Value.Value -is [array]) {
$formattedValues = @()
foreach($formatString in $configKey.Value.Value) {
$formattedValues += Format-TokenizedConfigurationString -tokenizedString $formatString -configuration $configuration
}

if ($null -ne $configKey.Value.Process) {
$scriptBlock = [ScriptBlock]::Create($configKey.Value.Process)
$formattedValues = Invoke-Command -ScriptBlock $scriptBlock -ArgumentList $formattedValues
$formattedValues = @($formattedValues)
}

$bicepConfigNode[$leafPropertyName] = $formattedValues
} else {

$formattedValue = Format-TokenizedConfigurationString -tokenizedString $configKey.Value.Value -configuration $configuration

if ($null -ne $configKey.Value.Process) {
$scriptBlock = [ScriptBlock]::Create($configKey.Value.Process)
$formattedValue = Invoke-Command -ScriptBlock $scriptBlock -ArgumentList $formattedValue
}

$bicepConfigNode[$leafPropertyName] = $formattedValue
}
} else {
$bicepConfigNode[$leafPropertyName] = $configKey.Value.Value
}

$bicepConfigNode[$leafPropertyName] = $configKey.Value.Value
$modified = $true
}
}
Expand Down
1 change: 0 additions & 1 deletion src/ALZ/Private/New-ALZDirectoryEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ function New-ALZDirectoryEnvironment {
New-Item -ItemType Directory -Path $config -Force | Out-String | Write-Verbose
New-Item -ItemType Directory -Path $upstream -Force | Out-String | Write-Verbose
New-Item -ItemType Directory -Path $configModules -Force | Out-String | Write-Verbose

}
41 changes: 41 additions & 0 deletions src/ALZ/Private/Set-ComputedConfiguration.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# If the value type is computed we replace the value with another which already exists in the configuration hierarchy.
function Set-ComputedConfiguration {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $true)]
[PSCustomObject] $configuration
)

if ($PSCmdlet.ShouldProcess("ALZ-Bicep computed configuration.", "calculate computed values")) {
foreach ($configKey in $configuration.PsObject.Properties) {
if ($configKey.Value.Type -ne "Computed") {
continue;
}

if ($configKey.Value.Value -is [array]) {
$formattedValues = @()
foreach($formatString in $configKey.Value.Value) {
$formattedValues += Format-TokenizedConfigurationString -tokenizedString $formatString -configuration $configuration
}

if ($null -ne $configKey.Value.Process) {
$scriptBlock = [ScriptBlock]::Create($configKey.Value.Process)
$formattedValues = Invoke-Command -ScriptBlock $scriptBlock -ArgumentList $formattedValues
$formattedValues = @($formattedValues)
}

$configKey.Value.Value = $formattedValues
} else {

$formattedValue = Format-TokenizedConfigurationString -tokenizedString $configKey.Value.Value -configuration $configuration

if ($null -ne $configKey.Value.Process) {
$scriptBlock = [ScriptBlock]::Create($configKey.Value.Process)
$formattedValue = Invoke-Command -ScriptBlock $scriptBlock -ArgumentList $formattedValue
}

$configKey.Value.Value = $formattedValue
}
}
}
}
3 changes: 2 additions & 1 deletion src/ALZ/Public/New-ALZEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ function New-ALZEnvironment {
$alzEnvironmentDestinationInternalCode = Join-Path $alzEnvironmentDestination "upstream-releases"

Get-ALZGithubRelease -directoryForReleases $alzEnvironmentDestinationInternalCode -githubRepoUrl $bicepConfig.module_url -releases @($bicepConfig.version) | Out-String | Write-Verbose

Write-InformationColored "Copying ALZ-Bicep module to $alzEnvironmentDestinationInternalCode" -ForegroundColor Green -InformationAction Continue
Copy-ALZParametersFile -alzEnvironmentDestination $alzEnvironmentDestination -upstreamReleaseDirectory $(Join-Path $alzEnvironmentDestinationInternalCode $bicepConfig.version) -configFiles $bicepConfig.config_files | Out-String | Write-Verbose
Write-InformationColored "ALZ-Bicep source directory: $alzBicepSourceDirectory" -ForegroundColor Green -InformationAction Continue

$configuration = Request-ALZEnvironmentConfig -configurationParameters $bicepConfig.parameters

Set-ComputedConfiguration -configuration $configuration | Out-String | Write-Verbose
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $alzEnvironmentDestination -configuration $configuration | Out-String | Write-Verbose
Build-ALZDeploymentEnvFile -configuration $configuration -Destination $alzEnvironmentDestination | Out-String | Write-Verbose

Expand Down
32 changes: 0 additions & 32 deletions src/Tests/Unit/Private/Build-ALZDeploymentEnvFile.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,6 @@ InModuleScope 'ALZ' {
Should -Invoke New-Item -ParameterFilter { $Path -match ".env$" } -Scope It -Times 1 -Exactly
Should -Invoke Add-Content -Scope It -Times 1 -Exactly
}

It 'Handles Computed values correctly and adds to the .env file.' {

Mock -CommandName New-Item
Mock -CommandName Add-Content

$configuration = [pscustomobject]@{
Setting1 = [pscustomobject]@{
Targets = @(
[pscustomobject]@{
Name = "Setting1"
Destination = "Environment"
})
Value = "Test"
}
Setting2 = [pscustomobject]@{
Targets = @(
[pscustomobject]@{
Name = "Setting2"
Destination = "Environment"
})
Type = "Computed"
Value = "{%Setting1%}"
}
}

Build-ALZDeploymentEnvFile -configuration $configuration -destination "test"

Should -Invoke New-Item -ParameterFilter { $Path -match ".env$" } -Scope It -Times 1 -Exactly
Should -Invoke Add-Content -ParameterFilter { $Value -match "^Setting1=`"Test`"$" } -Scope It -Times 1 -Exactly
Should -Invoke Add-Content -ParameterFilter { $Value -match "^Setting2=`"Test`"$" } -Scope It -Times 1 -Exactly
}
}
}
}
Loading
Loading