Skip to content
Open
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
Expand Up @@ -44,6 +44,8 @@ function Convert-BicepConfigToInputConfig {
$configItem | Add-Member -NotePropertyName "targets" -NotePropertyValue $variable.Value.targets
}

$configItem | Add-Member -NotePropertyName "Sensitive" -NotePropertyValue $false

$configItem | Add-Member -NotePropertyName "Description" -NotePropertyValue $description
$configItems | Add-Member -NotePropertyName $variable.Name -NotePropertyValue $configItem
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ function Convert-HCLVariablesToInputConfig {

$configItem | Add-Member -NotePropertyName "Description" -NotePropertyValue $description

$sensitive = $false
if ($variable.Value[0].PSObject.Properties.Name -contains "sensitive" -and $variable.Value[0].sensitive -eq $true) {
$sensitive = $true
Write-Verbose "Marking variable $($variable.Name) as sensitive..."
}
$configItem | Add-Member -NotePropertyName "Sensitive" -NotePropertyValue $sensitive

Write-Verbose "Adding variable $($variable.Name) to the configuration..."
$configItems | Add-Member -NotePropertyName $variable.Name -NotePropertyValue $configItem
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ function Convert-ParametersToInputConfig {
Write-Verbose "Alias $parameterAlias exists in input config, renaming..."
$configItem = $inputConfig.PSObject.Properties | Where-Object { $_.Name -eq $parameterAlias }
$inputConfig | Add-Member -NotePropertyName $parameterKey -NotePropertyValue @{
Value = $configItem.Value.Value
Source = $configItem.Value.Source
Value = $configItem.Value.Value
Source = $configItem.Value.Source
Sensitive = $configItem.Value.Sensitive
}
$inputConfig.PSObject.Properties.Remove($configItem.Name)
continue
Expand All @@ -38,8 +39,9 @@ function Convert-ParametersToInputConfig {
}
Write-Verbose "Adding parameter $parameterKey with value $variableValue"
$inputConfig | Add-Member -NotePropertyName $parameterKey -NotePropertyValue @{
Value = $variableValue
Source = "parameter"
Value = $variableValue
Source = "parameter"
Sensitive = $false
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/ALZ/Private/Config-Helpers/Get-ALZConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ function Get-ALZConfig {

foreach ($property in $config.PSObject.Properties) {
$inputConfig | Add-Member -NotePropertyName $property.Name -NotePropertyValue @{
Value = $property.Value
Source = $extension
Value = $property.Value
Source = $extension
Sensitive = $false
}
}

Expand Down
27 changes: 22 additions & 5 deletions src/ALZ/Private/Config-Helpers/Write-JsonFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ function Write-JsonFile {
[string] $jsonFilePath,

[Parameter(Mandatory = $false)]
[PSObject] $configuration
[PSObject[]] $configurations,

[Parameter(Mandatory = $false)]
[switch] $all
)

if ($PSCmdlet.ShouldProcess("Download Terraform Tools", "modify")) {
Expand All @@ -16,10 +19,24 @@ function Write-JsonFile {

$environmentVariables = [ordered]@{}

foreach ($configKey in $configuration.PsObject.Properties | Sort-Object Name) {
foreach ($target in $configKey.Value.Targets) {
if ($target.Destination -eq "Environment") {
$environmentVariables.$($target.Name) = $configKey.Value.Value
foreach ($configuration in $configurations) {
Write-Verbose "Processing configuration for JSON output to $($jsonFilePath)"
foreach ($configKey in $configuration.PsObject.Properties | Sort-Object Name) {
Write-Verbose "Processing configuration key $($configKey.Name) for $($jsonFilePath)"
Write-Verbose "Configuration key value: $(ConvertTo-Json $configKey.Value -Depth 100)"
if($configKey.Value.Sensitive) {
Write-Verbose "Obfuscating sensitive configuration $($configKey.Name) from JSON output"
$environmentVariables.$($configKey.Name) = "<sensitive>"
continue
}
if($all) {
$environmentVariables.$($configKey.Name) = $configKey.Value.Value
continue
}
foreach ($target in $configKey.Value.Targets) {
if ($target.Destination -eq "Environment") {
$environmentVariables.$($target.Name) = $configKey.Value.Value
}
}
}
}
Expand Down
40 changes: 27 additions & 13 deletions src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ function New-Bootstrap {

# Add the root module folder to bootstrap input config
$inputConfig | Add-Member -NotePropertyName "root_module_folder_relative_path" -NotePropertyValue @{
Value = $starterRootModuleFolder
Source = "calculated"
Value = $starterRootModuleFolder
Source = "calculated"
Sensitive = $false
}

# Set the starter root module folder full path
Expand All @@ -146,6 +147,8 @@ function New-Bootstrap {
$bootstrapParameters = Convert-HCLVariablesToInputConfig -targetVariableFile $terraformFile.FullName -hclParserToolPath $hclParserToolPath -appendToObject $bootstrapParameters
}

Write-Verbose "Bootstrap Parameters before setting config: $(ConvertTo-Json $bootstrapParameters -Depth 100)"

# Getting the configuration for the starter module user input
$starterParameters = [PSCustomObject]@{}

Expand All @@ -165,19 +168,22 @@ function New-Bootstrap {

# Set computed inputs
$inputConfig | Add-Member -NotePropertyName "module_folder_path" -NotePropertyValue @{
Value = $starterModulePath
Source = "calculated"
Value = $starterModulePath
Source = "calculated"
Sensitive = $false
}
$inputConfig | Add-Member -NotePropertyName "availability_zones_bootstrap" -NotePropertyValue @{
Value = @(Get-AvailabilityZonesSupport -region $inputConfig.bootstrap_location.Value -zonesSupport $zonesSupport)
Source = "calculated"
Value = @(Get-AvailabilityZonesSupport -region $inputConfig.bootstrap_location.Value -zonesSupport $zonesSupport)
Source = "calculated"
Sensitive = $false
}

if ($inputConfig.PSObject.Properties.Name -contains "starter_location" -and $inputConfig.PSObject.Properties.Name -notcontains "starter_locations") {
Write-Verbose "Converting starter_location $($inputConfig.starter_location.Value) to starter_locations..."
$inputConfig | Add-Member -NotePropertyName "starter_locations" -NotePropertyValue @{
Value = @($inputConfig.starter_location.Value)
Source = "calculated"
Value = @($inputConfig.starter_location.Value)
Source = "calculated"
Sensitive = $false
}
}

Expand All @@ -187,8 +193,9 @@ function New-Bootstrap {
$availabilityZonesStarter += , @(Get-AvailabilityZonesSupport -region $region -zonesSupport $zonesSupport)
}
$inputConfig | Add-Member -NotePropertyName "availability_zones_starter" -NotePropertyValue @{
Value = $availabilityZonesStarter
Source = "calculated"
Value = $availabilityZonesStarter
Source = "calculated"
Sensitive = $false
}
}

Expand All @@ -200,20 +207,25 @@ function New-Bootstrap {
-configurationParameters $bootstrapParameters `
-inputConfig $inputConfig

Write-Verbose "Final Bootstrap Parameters: $(ConvertTo-Json $bootstrapConfiguration -Depth 100)"

# Getting the input for the starter module
Write-Verbose "Setting the configuration for the starter module..."
$starterConfiguration = Set-Config `
-configurationParameters $starterParameters `
-inputConfig $inputConfig `
-copyEnvVarToConfig

Write-Verbose "Final Starter Parameters: $(ConvertTo-Json $starterParameters -Depth 100)"
Write-Verbose "Final Starter Parameters: $(ConvertTo-Json $starterConfiguration -Depth 100)"

# Creating the tfvars files for the bootstrap and starter module
$tfVarsFileName = "terraform.tfvars.json"
$bootstrapTfvarsPath = Join-Path -Path $bootstrapModulePath -ChildPath $tfVarsFileName
$starterTfvarsPath = Join-Path -Path $starterRootModuleFolderPath -ChildPath "terraform.tfvars.json"
$starterBicepVarsPath = Join-Path -Path $starterModulePath -ChildPath "parameters.json"
$starterBicepVarsFileName = "parameters.json"
$starterBicepAllVarsFileName = "template-parameters.json"
$starterBicepVarsPath = Join-Path -Path $starterModulePath -ChildPath $starterBicepVarsFileName
$starterBicepAllVarsPath = Join-Path -Path $starterModulePath -ChildPath $starterBicepAllVarsFileName

# Write the tfvars file for the bootstrap and starter module
Write-TfvarsJsonFile -tfvarsFilePath $bootstrapTfvarsPath -configuration $bootstrapConfiguration
Expand Down Expand Up @@ -270,10 +282,12 @@ function New-Bootstrap {
Set-ComputedConfiguration -configuration $starterConfiguration
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $starterModulePath -configuration $starterConfiguration
Write-JsonFile -jsonFilePath $starterBicepVarsPath -configuration $starterConfiguration
Write-JsonFile -jsonFilePath $starterBicepAllVarsPath -configuration @($inputConfig, $starterConfiguration, $bootstrapConfiguration) -all

# Remove unrequired files
$foldersOrFilesToRetain = $starterConfig.starter_modules.Value.$($inputConfig.starter_module_name.Value).folders_or_files_to_retain
$foldersOrFilesToRetain += "parameters.json"
$foldersOrFilesToRetain += $starterBicepVarsFileName
$foldersOrFilesToRetain += $starterBicepAllVarsFileName
$foldersOrFilesToRetain += "config"
$foldersOrFilesToRetain += ".config"

Expand Down
25 changes: 15 additions & 10 deletions src/ALZ/Public/Deploy-Accelerator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -354,24 +354,29 @@ function Deploy-Accelerator {

# Set computed interface inputs
$inputConfig | Add-Member -MemberType NoteProperty -Name "bicep_config_file_path" -Value @{
Value = $starterConfigFilePath
Source = "calculated"
Value = $starterConfigFilePath
Source = "calculated"
Sensitive = $false
}
$inputConfig | Add-Member -MemberType NoteProperty -Name "on_demand_folder_repository" -Value @{
Value = $starterModuleUrl
Source = "calculated"
Value = $starterModuleUrl
Source = "calculated"
Sensitive = $false
}
$inputConfig | Add-Member -MemberType NoteProperty -Name "on_demand_folder_artifact_name" -Value @{
Value = $starterReleaseArtifactName
Source = "calculated"
Value = $starterReleaseArtifactName
Source = "calculated"
Sensitive = $false
}
$inputConfig | Add-Member -MemberType NoteProperty -Name "release_version" -Value @{
Value = ($starterReleaseTag -eq "local" ? $inputConfig.starter_module_version.Value : $starterReleaseTag)
Source = "calculated"
Value = ($starterReleaseTag -eq "local" ? $inputConfig.starter_module_version.Value : $starterReleaseTag)
Source = "calculated"
Sensitive = $false
}
$inputConfig | Add-Member -MemberType NoteProperty -Name "time_stamp" -Value @{
Value = (Get-Date).ToString("yyyy-MM-dd-HH-mm-ss")
Source = "calculated"
Value = (Get-Date).ToString("yyyy-MM-dd-HH-mm-ss")
Source = "calculated"
Sensitive = $false
}

# Run the bootstrap
Expand Down
Loading