Skip to content

Commit

Permalink
enhancement: support separate starter module upgrade (#110)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
jaredfholgate authored Apr 3, 2024
1 parent d131152 commit cc905c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
26 changes: 15 additions & 11 deletions src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-FullUpgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
function Invoke-Upgrade {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $false)]
[string] $moduleType,

[Parameter(Mandatory = $false)]
[string] $targetDirectory,

Expand Down Expand Up @@ -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)"
}

Expand Down
9 changes: 5 additions & 4 deletions src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = ""
Expand Down

0 comments on commit cc905c8

Please sign in to comment.