Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Terraform.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function Invoke-Terraform {
[Parameter(Mandatory = $false)]
[switch] $destroy,

[Parameter(Mandatory = $false)]
[switch] $planOnly,

[Parameter(Mandatory = $false)]
[string] $output = "",

Expand Down Expand Up @@ -40,6 +43,11 @@ function Invoke-Terraform {

terraform -chdir="$moduleFolderPath" init
$action = "apply"

if($planOnly) {
$action = "plan"
}

if($destroy) {
$action = "destroy"
}
Expand Down Expand Up @@ -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."
Expand Down
7 changes: 5 additions & 2 deletions src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function New-Bootstrap {
[Parameter(Mandatory = $false)]
[switch] $destroy,

[Parameter(Mandatory = $false)]
[switch] $planOnly,

[Parameter(Mandatory = $false)]
[PSCustomObject] $zonesSupport = $null,

Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/ALZ/Public/Deploy-Accelerator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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 `
Expand Down
Loading