diff --git a/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Terraform.ps1 b/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Terraform.ps1 index 4d96d8d..6e2dd6a 100644 --- a/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Terraform.ps1 +++ b/src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Terraform.ps1 @@ -13,6 +13,9 @@ function Invoke-Terraform { [Parameter(Mandatory = $false)] [switch] $destroy, + [Parameter(Mandatory = $false)] + [switch] $planOnly, + [Parameter(Mandatory = $false)] [string] $output = "", @@ -40,6 +43,11 @@ function Invoke-Terraform { terraform -chdir="$moduleFolderPath" init $action = "apply" + + if($planOnly) { + $action = "plan" + } + if($destroy) { $action = "destroy" } @@ -89,7 +97,9 @@ function Invoke-Terraform { throw "Terraform plan failed with exit code $exitCode. Please review the error and try again or raise an issue." } - if(!$autoApprove) { + if($planOnly) { + return + } elseif(!$autoApprove) { Write-InformationColored "Terraform plan has completed, please review the plan and confirm you wish to continue." -ForegroundColor Yellow -NewLineBefore -InformationAction Continue $choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&Yes", "&No") $message = "Please confirm you wish to apply the plan." diff --git a/src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1 b/src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1 index 7b70bd9..aa8f595 100644 --- a/src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1 +++ b/src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1 @@ -37,6 +37,9 @@ function New-Bootstrap { [Parameter(Mandatory = $false)] [switch] $destroy, + [Parameter(Mandatory = $false)] + [switch] $planOnly, + [Parameter(Mandatory = $false)] [PSCustomObject] $zonesSupport = $null, @@ -273,10 +276,10 @@ function New-Bootstrap { Write-InformationColored "Thank you for providing those inputs, we are now initializing and applying Terraform to bootstrap your environment..." -ForegroundColor Green -NewLineBefore -InformationAction Continue if($autoApprove) { - Invoke-Terraform -moduleFolderPath $bootstrapModulePath -autoApprove -destroy:$destroy.IsPresent + Invoke-Terraform -moduleFolderPath $bootstrapModulePath -autoApprove -destroy:$destroy.IsPresent -planOnly:$planOnly.IsPresent } else { Write-InformationColored "Once the plan is complete you will be prompted to confirm the apply." -ForegroundColor Green -NewLineBefore -InformationAction Continue - Invoke-Terraform -moduleFolderPath $bootstrapModulePath -destroy:$destroy.IsPresent + Invoke-Terraform -moduleFolderPath $bootstrapModulePath -destroy:$destroy.IsPresent -planOnly:$planOnly.IsPresent } Write-InformationColored "Bootstrap has completed successfully! Thanks for using our tool. Head over to Phase 3 in the documentation to continue..." -ForegroundColor Green -NewLineBefore -InformationAction Continue diff --git a/src/ALZ/Public/Deploy-Accelerator.ps1 b/src/ALZ/Public/Deploy-Accelerator.ps1 index 5f9afc8..f7024d7 100644 --- a/src/ALZ/Public/Deploy-Accelerator.ps1 +++ b/src/ALZ/Public/Deploy-Accelerator.ps1 @@ -86,11 +86,18 @@ function Deploy-Accelerator { [Parameter( Mandatory = $false, - HelpMessage = "[OPTIONAL] Determines that this run is to destroup the bootstrap. This is used to cleanup experiments. Environment variable: ALZ_destroy. Config file input: destroy." + HelpMessage = "[OPTIONAL] Determines that this run is to destroy the bootstrap. This is used to cleanup experiments. Environment variable: ALZ_destroy. Config file input: destroy." )] [Alias("d")] [switch] $destroy, + [Parameter( + Mandatory = $false, + HelpMessage = "[OPTIONAL] Determines that this run is to plan the bootstrap rather than apply. Environment variable: ALZ_planOnly. Config file input: planOnly." + )] + [Alias("p")] + [switch] $planOnly, + [Parameter( Mandatory = $false, HelpMessage = "[OPTIONAL] The bootstrap modules reposiotry url. This can be overridden for custom modules. Environment variable: ALZ_bootstrap_module_url. Config file input: bootstrap_module_url." @@ -375,6 +382,7 @@ function Deploy-Accelerator { -starterConfig $starterConfig ` -autoApprove:$inputConfig.auto_approve.Value ` -destroy:$inputConfig.destroy.Value ` + -planOnly:$inputConfig.planOnly.Value ` -zonesSupport $zonesSupport ` -writeVerboseLogs:$inputConfig.write_verbose_logs.Value ` -hclParserToolPath $hclParserToolPath `