From cc905c81af9baf502ea729986514dfdc279e25dc Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Wed, 3 Apr 2024 11:49:43 +0100 Subject: [PATCH] enhancement: support separate starter module upgrade (#110) # Pull Request ## Description This change improves the upgrade process to be able to auto upgrade the bootstrap and starter modules independently. ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license. --- .../Invoke-FullUpgrade.ps1 | 26 +++++++++++-------- .../Invoke-Upgrade.ps1 | 5 +++- .../New-Bootstrap.ps1 | 9 ++++--- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-FullUpgrade.ps1 b/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-FullUpgrade.ps1 index 25711462..442f700a 100644 --- a/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-FullUpgrade.ps1 +++ b/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-FullUpgrade.ps1 @@ -32,36 +32,40 @@ function Invoke-FullUpgrade { if ($PSCmdlet.ShouldProcess("Upgrade Release", "Operation")) { # Run upgrade for bootstrap state - $wasUpgraded = Invoke-Upgrade ` + $bootstrapWasUpgraded = Invoke-Upgrade ` + -moduleType "bootstrap" ` -targetDirectory $bootstrapPath ` -targetFolder $bootstrapModuleFolder ` -cacheFileName "terraform.tfstate" ` -release $bootstrapRelease ` -autoApprove:$autoApprove.IsPresent - if($wasUpgraded) { + if($bootstrapWasUpgraded) { # Run upgrade for interface inputs Invoke-Upgrade ` -targetDirectory $bootstrapPath ` -cacheFileName $interfaceCacheFileName ` -release $bootstrapRelease ` - -autoApprove:$wasUpgraded | Out-String | Write-Verbose + -autoApprove:$bootstrapWasUpgraded | Out-String | Write-Verbose # Run upgrade for bootstrap inputs Invoke-Upgrade ` -targetDirectory $bootstrapPath ` -cacheFileName $bootstrapCacheFileName ` -release $bootstrapRelease ` - -autoApprove:$wasUpgraded | Out-String | Write-Verbose + -autoApprove:$bootstrapWasUpgraded | Out-String | Write-Verbose + } - # Run upgrade for starter - Invoke-Upgrade ` - -targetDirectory $starterPath ` - -cacheFileName $starterCacheFileName ` - -release $starterRelease ` - -autoApprove:$wasUpgraded | Out-String | Write-Verbose + # Run upgrade for starter + $starterWasUpgraded = Invoke-Upgrade ` + -moduleType "starter" ` + -targetDirectory $starterPath ` + -cacheFileName $starterCacheFileName ` + -release $starterRelease ` + -autoApprove:$autoApprove.IsPresent | Out-String | Write-Verbose - Write-InformationColored "AUTOMATIC UPGRADE: Upgrade complete. If any starter files have been updated, you will need to remove branch protection in order for the Terraform apply to succeed." -ForegroundColor Yellow -InformationAction Continue + if($starterWasUpgraded -or $bootstrapWasUpgraded) { + Write-InformationColored "AUTOMATIC UPGRADE: Upgrade complete. If any starter files have been updated, you will need to remove branch protection in order for the Terraform apply to succeed." -NewLineBefore -ForegroundColor Yellow -InformationAction Continue } } } diff --git a/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Upgrade.ps1 b/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Upgrade.ps1 index eeb43bc0..4c30ed9d 100644 --- a/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Upgrade.ps1 +++ b/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Upgrade.ps1 @@ -1,6 +1,9 @@ function Invoke-Upgrade { [CmdletBinding(SupportsShouldProcess = $true)] param ( + [Parameter(Mandatory = $false)] + [string] $moduleType, + [Parameter(Mandatory = $false)] [string] $targetDirectory, @@ -54,7 +57,7 @@ function Invoke-Upgrade { if($autoApprove) { $upgrade = "upgrade" } else { - Write-InformationColored "AUTOMATIC UPGRADE: We found version $previousVersion that has been previously run. You can upgrade from this version to the new version $currentVersion" -ForegroundColor Yellow -InformationAction Continue + Write-InformationColored "AUTOMATIC UPGRADE: We found version $previousVersion of the $moduleType module that has been previously run. You can upgrade from this version to the new version $currentVersion" -NewLineBefore -ForegroundColor Yellow -InformationAction Continue $upgrade = Read-Host "If you would like to upgrade, enter 'upgrade' or just hit 'enter' to continue with a new environment. (upgrade/exit)" } diff --git a/src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1 b/src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1 index 7bdd5683..a31dc63a 100644 --- a/src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1 +++ b/src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1 @@ -54,12 +54,8 @@ function New-Bootstrap { $bootstrapCacheFileName = "bootstrap-cache.json" $starterCacheFileName = "starter-cache.json" $interfaceCachePath = Join-Path -Path $bootstrapPath -ChildPath $interfaceCacheFileName - $interfaceCachedConfig = Get-ALZConfig -configFilePath $interfaceCachePath $bootstrapCachePath = Join-Path -Path $bootstrapPath -ChildPath $bootstrapCacheFileName - $bootstrapCachedConfig = Get-ALZConfig -configFilePath $bootstrapCachePath $starterCachePath = Join-Path -Path $starterPath -ChildPath $starterCacheFileName - $starterCachedConfig = Get-ALZConfig -configFilePath $starterCachePath - $bootstrapModulePath = Join-Path -Path $bootstrapPath -ChildPath $bootstrapDetails.Value.location Write-Verbose "Bootstrap Module Path: $bootstrapModulePath" @@ -76,6 +72,11 @@ function New-Bootstrap { -starterCacheFileName $starterCacheFileName ` -autoApprove:$autoApprove.IsPresent + # Get cached inputs + $interfaceCachedConfig = Get-ALZConfig -configFilePath $interfaceCachePath + $bootstrapCachedConfig = Get-ALZConfig -configFilePath $bootstrapCachePath + $starterCachedConfig = Get-ALZConfig -configFilePath $starterCachePath + # Get starter module $starter = "" $starterModulePath = ""