From 10bdc5422ba40e9dc130f88a3d33d07feb77a630 Mon Sep 17 00:00:00 2001 From: Zach Trocinski Date: Wed, 14 Aug 2024 23:43:46 -0500 Subject: [PATCH 1/3] Fix logic for Bicep legacy upgrades and creation --- .../Legacy-Bicep/New-ALZEnvironmentBicep.ps1 | 38 +++++++++++-------- src/ALZ/Private/Shared/Get-GithubRelease.ps1 | 6 +-- src/ALZ/Public/New-ALZEnvironment.ps1 | 35 +++++++++-------- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/ALZ/Private/Legacy-Bicep/New-ALZEnvironmentBicep.ps1 b/src/ALZ/Private/Legacy-Bicep/New-ALZEnvironmentBicep.ps1 index 8cb8718b..0485aed7 100644 --- a/src/ALZ/Private/Legacy-Bicep/New-ALZEnvironmentBicep.ps1 +++ b/src/ALZ/Private/Legacy-Bicep/New-ALZEnvironmentBicep.ps1 @@ -21,7 +21,10 @@ function New-ALZEnvironmentBicep { [switch] $local, [Parameter(Mandatory = $false)] - [switch] $autoApprove + [switch] $autoApprove, + + [Parameter(Mandatory = $false)] + [switch] $replaceFiles ) if ($PSCmdlet.ShouldProcess("ALZ-Bicep module configuration", "modify")) { @@ -33,22 +36,27 @@ function New-ALZEnvironmentBicep { Write-Verbose "Config path: $configFilePath" $bicepConfig = Get-ALZConfig -configFilePath $configFilePath - Write-InformationColored "Copying ALZ-Bicep module to $targetDirectory" -ForegroundColor Green -InformationAction Continue - Copy-ALZParametersFile -alzEnvironmentDestination $targetDirectory -upstreamReleaseDirectory $upstreamReleaseFolderPath -configFiles $bicepConfig.config_files | Out-String | Write-Verbose - Copy-ALZParametersFile -alzEnvironmentDestination $targetDirectory -upstreamReleaseDirectory $upstreamReleaseFolderPath -configFiles $bicepConfig.cicd.$vcs | Out-String | Write-Verbose - - $configuration = Request-ALZEnvironmentConfig -configurationParameters $bicepConfig.parameters -userInputOverrides $userInputOverrides -autoApprove:$autoApprove.IsPresent - - 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 $targetDirectory -zonesSupport $bicepConfig.zonesSupport | Out-String | Write-Verbose - - if($local) { + # Check if the configuration directory exists + $configDirectory = Join-Path -Path $targetDirectory -ChildPath "config" + if (-not (Test-Path -Path $configDirectory) -or $replaceFiles.IsPresent) { + Write-InformationColored "Copying ALZ-Bicep module to $targetDirectory" -ForegroundColor Green -InformationAction Continue + Copy-ALZParametersFile -alzEnvironmentDestination $targetDirectory -upstreamReleaseDirectory $upstreamReleaseFolderPath -configFiles $bicepConfig.config_files | Out-String | Write-Verbose + Copy-ALZParametersFile -alzEnvironmentDestination $targetDirectory -upstreamReleaseDirectory $upstreamReleaseFolderPath -configFiles $bicepConfig.cicd.$vcs | Out-String | Write-Verbose + $configuration = Request-ALZEnvironmentConfig -configurationParameters $bicepConfig.parameters -userInputOverrides $userInputOverrides -autoApprove:$autoApprove.IsPresent + + 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 $targetDirectory -zonesSupport $bicepConfig.zonesSupport | Out-String | Write-Verbose + + } else { + Write-InformationColored "Configuration directory $configDirectory already exists and the replacefiles parameter is set to $replaceFiles. Will skil overwriting the config directory." -ForegroundColor Yellow -InformationAction Continue + } + if ($local) { $isGitRepo = Test-ALZGitRepository -alzEnvironmentDestination $targetDirectory -autoApprove:$autoApprove.IsPresent if (-not $isGitRepo) { - Write-InformationColored "The directory $targetDirectory is not a git repository. Please make sure it is a git repo after initialization." -ForegroundColor Red -InformationAction Continue + Write-InformationColored "The directory $targetDirectory is not a git repository. Please make sure it is a git repo after initialization." -ForegroundColor Red -InformationAction Continue } } } -} \ No newline at end of file +} diff --git a/src/ALZ/Private/Shared/Get-GithubRelease.ps1 b/src/ALZ/Private/Shared/Get-GithubRelease.ps1 index b76011a6..abda301e 100644 --- a/src/ALZ/Private/Shared/Get-GithubRelease.ps1 +++ b/src/ALZ/Private/Shared/Get-GithubRelease.ps1 @@ -146,16 +146,16 @@ function Get-GithubRelease { Remove-Item -Path "$targetVersionPath/tmp" -Force -Recurse Write-InformationColored "The directory for $targetVersionPath has been created and populated." -ForegroundColor Green -InformationAction Continue } else { - Write-InformationColored "The directory for $targetVersionPath already exists and has content in it, so we are not over-writing it." -ForegroundColor Green -InformationAction Continue + Write-InformationColored "The directory for $targetVersionPath already exists and has content in it, so we are not overwriting it." -ForegroundColor Green -InformationAction Continue Write-Verbose "===> Content already exists in $releaseDirectory. Skipping" } # Check and replace the .env file release version if it is Bicep $envFilePath = Join-Path -Path $parentDirectory -ChildPath ".env" - if(Test-Path $envFilePath) { + if (Test-Path $envFilePath) { Write-Verbose "===> Replacing the .env file release version with $releaseTag" (Get-Content $envFilePath) -replace "UPSTREAM_RELEASE_VERSION=.*", "UPSTREAM_RELEASE_VERSION=$releaseTag" | Set-Content $envFilePath } return $releaseTag -} \ No newline at end of file +} diff --git a/src/ALZ/Public/New-ALZEnvironment.ps1 b/src/ALZ/Public/New-ALZEnvironment.ps1 index 52283f03..1c600022 100644 --- a/src/ALZ/Public/New-ALZEnvironment.ps1 +++ b/src/ALZ/Public/New-ALZEnvironment.ps1 @@ -57,7 +57,6 @@ function New-ALZEnvironment { [Alias("b")] [string] $bootstrap = "", - [Parameter(Mandatory = $false, HelpMessage = "The starter module to deploy. You will be prompted to enter this if not supplied.")] [string] $starter = "", @@ -123,36 +122,36 @@ function New-ALZEnvironment { if ($PSCmdlet.ShouldProcess("Accelerator setup", "modify")) { # Get User Inputs from the -inputs file $userInputOverrides = $null - if($userInputOverridePath -ne "") { + if ($userInputOverridePath -ne "") { $userInputOverrides = Get-ALZConfig -configFilePath $userInputOverridePath } # Get the IAC type if not specified - if($iac -eq "") { + if ($iac -eq "") { $iac = Request-SpecialInput -type "iac" -userInputOverrides $userInputOverrides } # Setup the Bicep flag $isLegacyBicep = $false - if($iac -eq "bicep") { + if ($iac -eq "bicep") { $isLegacyBicep = $bicepLegacyMode -eq $true } - if($isLegacyBicep) { + if ($isLegacyBicep) { Write-Verbose "We are running in legacy Bicep mode" } - if(!$isLegacyBicep){ + if (!$isLegacyBicep) { Write-Verbose "We are running in modern mode" } # Check and install Terraform CLI if needed - if(!$isLegacyBicep) { - if($skipInternetChecks) { + if (!$isLegacyBicep) { + if ($skipInternetChecks) { Write-InformationColored "Skipping Terraform tool check as you used the skipInternetCheck parameter. Please ensure you have the most recent version of Terraform installed" -ForegroundColor Yellow -InformationAction Continue } else { Write-InformationColored "Checking you have the latest version of Terraform installed..." -ForegroundColor Green -NewLineBefore -InformationAction Continue - if($iac -eq "bicep") { + if ($iac -eq "bicep") { Write-InformationColored "Although you have selected Bicep, the Accelerator leverages the Terraform tool to bootstrap your Version Control System and Azure. This is will not impact your choice of Bicep post this initial bootstrap. Please refer to our documentation for further details..." -ForegroundColor Yellow -InformationAction Continue } $toolsPath = Join-Path -Path $targetDirectory -ChildPath ".tools" @@ -165,7 +164,7 @@ function New-ALZEnvironment { $bootstrapPath = "" $bootstrapTargetFolder = "bootstrap" - if(!$isLegacyBicep) { + if (!$isLegacyBicep) { Write-InformationColored "Checking and Downloading the bootstrap module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue $versionAndPath = New-ModuleSetup ` @@ -187,8 +186,9 @@ function New-ALZEnvironment { $starterFolder = "starter" $starterModuleTargetFolder = $starterFolder - if($isLegacyBicep) { + if ($isLegacyBicep) { $starterModuleTargetFolder = "./upstream-releases" + $starterFolder = "" } # Setup the variables for bootstrap and starter modules @@ -203,7 +203,7 @@ function New-ALZEnvironment { $inputConfig = $null $zonesSupport = $null - if(!$isLegacyBicep) { + if (!$isLegacyBicep) { $bootstrapAndStarterConfig = Get-BootstrapAndStarterConfig ` -iac $iac ` -bootstrap $bootstrap ` @@ -221,18 +221,17 @@ function New-ALZEnvironment { $inputConfig = $bootstrapAndStarterConfig.inputConfig $zonesSupport = $bootstrapAndStarterConfig.zonesSupport } else { - if($bootstrap -eq "") { + if ($bootstrap -eq "") { $bootstrap = Request-SpecialInput -type "bootstrap" -bootstrapModules $bootstrapModules -userInputOverrides $userInputOverrides } } # Download the starter modules $starterReleaseTag = "" - $starterPath = "" $starterConfig = $null - if(($hasStarterModule -or $isLegacyBicep)) { - Write-InformationColored "Checking and Downloading the starter module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue + if (($hasStarterModule -or $isLegacyBicep)) { + Write-InformationColored "Checking and downloading the starter module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue $versionAndPath = New-ModuleSetup ` -targetDirectory $targetDirectory ` @@ -247,7 +246,7 @@ function New-ALZEnvironment { $starterReleaseTag = $versionAndPath.releaseTag $starterPath = $versionAndPath.path - if($starterConfigFilePath -ne "") { + if ($starterConfigFilePath -ne "") { $starterConfig = Get-StarterConfig -starterPath $starterPath -starterConfigPath $starterConfigFilePath } } @@ -273,7 +272,7 @@ function New-ALZEnvironment { } # Run the bootstrap - if(!$isLegacyBicep) { + if (!$isLegacyBicep) { # Set computed interface inputs $computedInputs = @{ From f731a7585515901a8978c1c679203d5d08c801f4 Mon Sep 17 00:00:00 2001 From: Zach Trocinski Date: Thu, 15 Aug 2024 00:04:44 -0500 Subject: [PATCH 2/3] Update wiki for commandlets --- ...er-Guide]-Quick-Start-Phase-2-Azure-DevOps.md | 16 ++++++++-------- .../[User-Guide]-Quick-Start-Phase-2-GitHub.md | 16 ++++++++-------- .../[User-Guide]-Quick-Start-Phase-2-Local.md | 16 ++++++++-------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/wiki/[User-Guide]-Quick-Start-Phase-2-Azure-DevOps.md b/docs/wiki/[User-Guide]-Quick-Start-Phase-2-Azure-DevOps.md index cd5bc576..e9189dcb 100644 --- a/docs/wiki/[User-Guide]-Quick-Start-Phase-2-Azure-DevOps.md +++ b/docs/wiki/[User-Guide]-Quick-Start-Phase-2-Azure-DevOps.md @@ -13,14 +13,14 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs, ```pwsh # Windows - New-Item c:\accelerator\config\inputs.yaml -Force - New-Item c:\accelerator\output + New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force + New-Item -ItemType "directory" c:\accelerator\output ``` ```pwsh # Linux/Mac - New-Item ~/accelerator/config/inputs.yaml -Force - New-Item ~/accelerator/output + New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force + New-Item -ItemType "directory" ~/accelerator/output ``` ```plaintext @@ -89,14 +89,14 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs, ```pwsh # Windows - New-Item c:\accelerator\config\inputs.yaml -Force - New-Item c:\accelerator\output + New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force + New-Item -ItemType "directory" c:\accelerator\output ``` ```pwsh # Linux/Mac - New-Item ~/accelerator/config/inputs.yaml -Force - New-Item ~/accelerator/output + New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force + New-Item -ItemType "directory" ~/accelerator/output ``` ```plaintext diff --git a/docs/wiki/[User-Guide]-Quick-Start-Phase-2-GitHub.md b/docs/wiki/[User-Guide]-Quick-Start-Phase-2-GitHub.md index 22fbde5a..7c3c7cf8 100644 --- a/docs/wiki/[User-Guide]-Quick-Start-Phase-2-GitHub.md +++ b/docs/wiki/[User-Guide]-Quick-Start-Phase-2-GitHub.md @@ -13,12 +13,12 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs, ```pwsh # Windows - New-Item c:\accelerator\config\inputs.yaml -Force - New-Item c:\accelerator\output + New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force + New-Item -ItemType "directory" c:\accelerator\output # Linux/Mac - New-Item ~/accelerator/config/inputs.yaml -Force - New-Item ~/accelerator/output + New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force + New-Item -ItemType "directory" ~/accelerator/output ``` ```plaintext @@ -81,12 +81,12 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs, ```pwsh # Windows - New-Item c:\accelerator\config\inputs.yaml -Force - New-Item c:\accelerator\output + New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force + New-Item -ItemType "directory" c:\accelerator\output # Linux/Mac - New-Item ~/accelerator/config/inputs.yaml -Force - New-Item ~/accelerator/output + New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force + New-Item -ItemType "directory" ~/accelerator/output ``` ```plaintext diff --git a/docs/wiki/[User-Guide]-Quick-Start-Phase-2-Local.md b/docs/wiki/[User-Guide]-Quick-Start-Phase-2-Local.md index 8f1a40bb..50c83d25 100644 --- a/docs/wiki/[User-Guide]-Quick-Start-Phase-2-Local.md +++ b/docs/wiki/[User-Guide]-Quick-Start-Phase-2-Local.md @@ -13,12 +13,12 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs, ```pwsh # Windows - New-Item c:\accelerator\config\inputs.yaml -Force - New-Item c:\accelerator\output + New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force + New-Item -ItemType "directory" c:\accelerator\output # Linux/Mac - New-Item ~/accelerator/config/inputs.yaml -Force - New-Item ~/accelerator/output + New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force + New-Item -ItemType "directory" ~/accelerator/output ``` ```plaintext @@ -74,14 +74,14 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs, ```pwsh # Windows - New-Item c:\accelerator\config\inputs.yaml -Force - New-Item c:\accelerator\output + New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force + New-Item -ItemType "directory" c:\accelerator\output ``` ```pwsh # Linux/Mac - New-Item ~/accelerator/config/inputs.yaml -Force - New-Item ~/accelerator/output + New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force + New-Item -ItemType "directory" ~/accelerator/output ``` ```plaintext From 230c80a4a1a453d8497f039b329df5880360cbf9 Mon Sep 17 00:00:00 2001 From: Zach Trocinski Date: Mon, 26 Aug 2024 22:34:04 -0500 Subject: [PATCH 3/3] Fix bicep reference --- .../wiki/examples/powershell-inputs/inputs-local-terraform.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/wiki/examples/powershell-inputs/inputs-local-terraform.yaml b/docs/wiki/examples/powershell-inputs/inputs-local-terraform.yaml index 0e797643..9031a771 100644 --- a/docs/wiki/examples/powershell-inputs/inputs-local-terraform.yaml +++ b/docs/wiki/examples/powershell-inputs/inputs-local-terraform.yaml @@ -3,7 +3,7 @@ # https://github.com/Azure/ALZ-PowerShell-Module/wiki/%5BUser-Guide%5D-Quick-Start-Phase-2-Azure-DevOps#2211-azure-devops-with-bicep # Basic Inputs -iac: "bicep" +iac: "terraform" bootstrap: "alz_local" starter: "complete"