From 969afb5c57c087a8425f3d12c594423503de9c88 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Thu, 23 Nov 2023 09:20:59 +0000 Subject: [PATCH 1/3] Simplify update process --- README.md | 8 ++-- src/ALZ/Private/New-ALZEnvironmentBicep.ps1 | 4 +- .../Private/New-ALZEnvironmentTerraform.ps1 | 4 +- src/ALZ/Public/Get-ALZGithubRelease.ps1 | 45 +++++++++++++++++-- src/ALZ/Public/New-ALZEnvironment.ps1 | 4 ++ .../Public/Get-ALZGithubRelease.Tests.ps1 | 4 +- 6 files changed, 54 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b6629c4..4702f0f 100644 --- a/README.md +++ b/README.md @@ -81,13 +81,13 @@ This currently tests for: #### Azure Landing Zone Environment with Bicep and GitHub Actions Workflows ```powershell -New-ALZEnvironment -o -IaC "bicep" -cicd "github +New-ALZEnvironment -o -i "bicep" -c "github" ``` #### Azure Landing Zone Environment with Bicep and Azure DevOps Pipelines ```powershell -New-ALZEnvironment -o -IaC "bicep" -cicd "azuredevops" +New-ALZEnvironment -o -i "bicep" -c "azuredevops" ``` > **Note** @@ -96,13 +96,13 @@ New-ALZEnvironment -o -IaC "bicep" -cicd "azuredevops" #### Azure Landing Zone Environment with Terraform and GitHub Pipelines ```powershell -New-ALZEnvironment -o -IaC "terraform" -cicd "github" +New-ALZEnvironment -o -i "terraform" -c "github" ``` #### Azure Landing Zone Environment with Terraform and Azure DevOps Pipelines ```powershell -New-ALZEnvironment -o -IaC "terraform" -cicd "azuredevops" +New-ALZEnvironment -o -i "terraform" -c "azuredevops" ``` ## Additional Cmdlets diff --git a/src/ALZ/Private/New-ALZEnvironmentBicep.ps1 b/src/ALZ/Private/New-ALZEnvironmentBicep.ps1 index 6af7baf..fc17493 100644 --- a/src/ALZ/Private/New-ALZEnvironmentBicep.ps1 +++ b/src/ALZ/Private/New-ALZEnvironmentBicep.ps1 @@ -16,8 +16,6 @@ function New-ALZEnvironmentBicep { [string] $alzCicdPlatform ) - $bicepModuleUrl = "https://github.com/Azure/ALZ-Bicep" - if ($PSCmdlet.ShouldProcess("ALZ-Bicep module configuration", "modify")) { if($alzVersion -ne "latest" -and $alzVersion -notlike "*-preview") { @@ -34,7 +32,7 @@ function New-ALZEnvironmentBicep { $alzEnvironmentDestinationInternalCode = Join-Path $alzEnvironmentDestination "upstream-releases" # Downloading the latest or specified version of the bicep accelerator module - $releaseTag = Get-ALZGithubRelease -directoryForReleases $alzEnvironmentDestinationInternalCode -githubRepoUrl $bicepModuleUrl -release $alzVersion + $releaseTag = Get-ALZGithubRelease -directoryForReleases $alzEnvironmentDestination -iac "bicep" -release $alzVersion $releasePath = Join-Path -Path $alzEnvironmentDestinationInternalCode -ChildPath $releaseTag # Getting the configuration diff --git a/src/ALZ/Private/New-ALZEnvironmentTerraform.ps1 b/src/ALZ/Private/New-ALZEnvironmentTerraform.ps1 index 353d92d..dc0ddc2 100644 --- a/src/ALZ/Private/New-ALZEnvironmentTerraform.ps1 +++ b/src/ALZ/Private/New-ALZEnvironmentTerraform.ps1 @@ -23,8 +23,6 @@ function New-ALZEnvironmentTerraform { [switch] $autoApprove ) - $terraformModuleUrl = "https://github.com/Azure/alz-terraform-accelerator" - if ($PSCmdlet.ShouldProcess("ALZ-Terraform module configuration", "modify")) { Write-InformationColored "Downloading alz-terraform-accelerator Terraform module to $alzEnvironmentDestination" -ForegroundColor Green -InformationAction Continue @@ -36,7 +34,7 @@ function New-ALZEnvironmentTerraform { } # Downloading the latest or specified version of the alz-terraform-accelerator module - $releaseTag = Get-ALZGithubRelease -directoryForReleases $alzEnvironmentDestination -githubRepoUrl $terraformModuleUrl -release $alzVersion + $releaseTag = Get-ALZGithubRelease -directoryForReleases $alzEnvironmentDestination -iac "terraform" -release $alzVersion $releasePath = Join-Path -Path $alzEnvironmentDestination -ChildPath $releaseTag # Getting the configuration for the initial bootstrap user input and validators diff --git a/src/ALZ/Public/Get-ALZGithubRelease.ps1 b/src/ALZ/Public/Get-ALZGithubRelease.ps1 index 30b63eb..6e5e760 100644 --- a/src/ALZ/Public/Get-ALZGithubRelease.ps1 +++ b/src/ALZ/Public/Get-ALZGithubRelease.ps1 @@ -22,16 +22,28 @@ Checks for the releases of a GitHub repository and downloads the latest release function Get-ALZGithubRelease { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, Position = 1, HelpMessage = "Please the provide the full URL of the GitHub repository you wish to check for the latest release.")] + [Parameter(Mandatory = $true, Position = 0, HelpMessage = "The IaC provider to use for the ALZ environment.")] + [ValidateSet("bicep", "terraform")] + [Alias("Iac")] + [Alias("i")] [string] - $githubRepoUrl, + $alzIacProvider, + + [Parameter(Mandatory = $false, Position = 1, HelpMessage = "Please the provide the full URL of the GitHub repository you wish to check for the latest release.")] + [string] + $githubRepoUrl = "", [Parameter(Mandatory = $false, Position = 2, HelpMessage = "The releases to download. Specify 'all' to download all releases or 'latest' to download the latest release. Defaults to the latest release.")] [array] + [Alias("version")] + [Alias("v")] $release = "latest", [Parameter(Mandatory = $false, Position = 3, HelpMessage = "The directory to download the releases to. Defaults to the current directory.")] [string] + [Alias("Output")] + [Alias("OutputDirectory")] + [Alias("O")] $directoryForReleases = "$PWD/releases", [Parameter(Mandatory = $false, Position = 4, HelpMessage = "An array of strings contianing the paths to the directories or files that you wish to keep when downloading and extracting from the releases.")] @@ -43,6 +55,23 @@ function Get-ALZGithubRelease { $queryOnly ) + # Set the repository URL if not provided + $bicepModuleUrl = "https://github.com/Azure/ALZ-Bicep" + $terraformModuleUrl = "https://github.com/Azure/alz-terraform-accelerator" + if($githubRepoUrl -eq "") { + if($alzIacProvider -eq "bicep") { + $githubRepoUrl = $bicepModuleUrl + } elseif($alzIacProvider -eq "terraform") { + $githubRepoUrl = $terraformModuleUrl + } + } + + $parentDirectory = $directoryForReleases + # Bicep specific path setup + if($alzIacProvider -eq "bicep") { + $directoryForReleases = Join-Path $directoryForReleases "upstream-releases" + } + # Split Repo URL into parts $repoOrgPlusRepo = $githubRepoUrl.Split("/")[-2..-1] -join "/" @@ -81,7 +110,7 @@ function Get-ALZGithubRelease { New-Item -ItemType Directory -Path $directoryForReleases | Out-String | Write-Verbose } - # Check the firectory for this release + # Check the directory for this release $releaseDirectory = "$directoryForReleases/$releaseTag" Write-Verbose "===> Checking if directory for release version exists: $releaseDirectory" @@ -117,8 +146,18 @@ function Get-ALZGithubRelease { Remove-Item -Path "$releaseDirectory/tmp" -Force -Recurse } else { + Write-InformationColored "The release directory for this version already exists and has content in it, so we are not over-writing it." -ForegroundColor Yellow -InformationAction Continue Write-Verbose "===> Content already exists in $releaseDirectory. Skipping" } + # Check and replace the .env file release version if it is Bicep + if($alzIacProvider -eq "bicep") { + $envFilePath = Join-Path -Path $parentDirectory -ChildPath ".env" + 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 b5dbb36..327df43 100644 --- a/src/ALZ/Public/New-ALZEnvironment.ps1 +++ b/src/ALZ/Public/New-ALZEnvironment.ps1 @@ -35,16 +35,20 @@ function New-ALZEnvironment { [Parameter(Mandatory = $false)] [Alias("alzBicepVersion")] + [Alias("version")] + [Alias("v")] [string] $alzVersion = "latest", [Parameter(Mandatory = $false)] [ValidateSet("bicep", "terraform")] [Alias("Iac")] + [Alias("i")] [string] $alzIacProvider = "bicep", [Parameter(Mandatory = $false)] [ValidateSet("github", "azuredevops")] [Alias("Cicd")] + [Alias("c")] [string] $alzCicdPlatform = "github", [Parameter(Mandatory = $false)] diff --git a/src/Tests/Unit/Public/Get-ALZGithubRelease.Tests.ps1 b/src/Tests/Unit/Public/Get-ALZGithubRelease.Tests.ps1 index e4fa491..9551f5c 100644 --- a/src/Tests/Unit/Public/Get-ALZGithubRelease.Tests.ps1 +++ b/src/Tests/Unit/Public/Get-ALZGithubRelease.Tests.ps1 @@ -100,13 +100,13 @@ InModuleScope 'ALZ' { } It 'Should get the correct releases' { - Get-ALZGithubRelease -githubRepoUrl "http://github.com/test/repo" -directoryAndFilesToKeep @('repo-1.0.0') -directoryForReleases "output" + Get-ALZGithubRelease -iac "bicep" -githubRepoUrl "http://github.com/test/repo" -directoryAndFilesToKeep @('repo-1.0.0') -directoryForReleases "output" Should -Invoke Expand-Archive Should -Not -Invoke Write-Warning } It 'Should throw an exception when you ask for a release that does not exist' { - { Get-ALZGithubRelease -githubRepoUrl "http://github.com/test/repo" -release 'v2.0.0' -directoryAndFilesToKeep @('repo-1.0.0') -directoryForReleases "output" } | Should -Throw + { Get-ALZGithubRelease -iac "bicep" -githubRepoUrl "http://github.com/test/repo" -release 'v2.0.0' -directoryAndFilesToKeep @('repo-1.0.0') -directoryForReleases "output" } | Should -Throw Should -Invoke Write-Error } } From e986a79fc4608dddcd362c99d8fce01740ef3db8 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Thu, 23 Nov 2023 09:21:40 +0000 Subject: [PATCH 2/3] Update read me --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4702f0f..24f867a 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ New-ALZEnvironment -o -i "terraform" -c "azuredevops" #### Downloads and pulls down the specified release version from the remote GitHub repository to a local directory ```powershell -Get-ALZGithubRelease -githubRepoUrl "https://github.com/Azure/ALZ-Bicep" -releases "v0.14.0" -directoryForReleases "C:\Repos\ALZ\accelerator\upstream-releases\" +Get-ALZGithubRelease -i "bicep" -releases "v0.14.0" -o "C:\Repos\ALZ\accelerator" ``` ## Development From 053a47b766682b42c1c5beca0989aef8f0a5d3d4 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Thu, 23 Nov 2023 09:37:14 +0000 Subject: [PATCH 3/3] Fix read me --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 24f867a..d24f9f0 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ New-ALZEnvironment -o -i "terraform" -c "azuredevops" #### Downloads and pulls down the specified release version from the remote GitHub repository to a local directory ```powershell -Get-ALZGithubRelease -i "bicep" -releases "v0.14.0" -o "C:\Repos\ALZ\accelerator" +Get-ALZGithubRelease -i "bicep" -v "v0.14.0" -o "C:\Repos\ALZ\accelerator" ``` ## Development