From 83aeb352b174bc289307ea7eaf1bae35104389b1 Mon Sep 17 00:00:00 2001 From: Ryan McAfee <ryan@ryanmcafee.com> Date: Wed, 10 Jun 2020 18:06:20 -0500 Subject: [PATCH] Fixed issue that was causing error handling in provision script to not work correctly - now resolved. Updated script to not automatically apply by default. It now requires that you specify -auto_approve true when calling the provision script in order to get that behaviour. Added provision.sh wrapper script that utilizes devops-cli docker image for linux users that don't wish to install powershell on their systems. --- provision.ps1 | 24 ++++++++++-------------- provision.sh | 5 +++++ 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 provision.sh diff --git a/provision.ps1 b/provision.ps1 index 8157093..1a13925 100644 --- a/provision.ps1 +++ b/provision.ps1 @@ -1,11 +1,10 @@ -#! /usr/bin/pwsh - [CmdletBinding()] Param( [string]$flavor = "azure", [string]$tf_workspace = (Invoke-Expression -Command "terraform workspace show").Trim(), [string]$kube_config_dir = "credentials/workspaces/${tf_workspace}/.kube", - [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string]$auto_approve = "false", + [Parameter(Position = 0, Mandatory = $false, ValueFromRemainingArguments = $true)] [string[]]$Args ) @@ -39,18 +38,21 @@ try { $provider_specific_variable_file=If (Test-Path "customizations/workspaces/${tf_workspace}/provider.tfvars" -PathType Leaf) {"customizations/workspaces/${tf_workspace}/provider.tfvars"} Else {"customizations/provider.tfvars"} $flavor_variable_file=If (Test-Path "customizations/workspaces/${tf_workspace}/flavorize.tfvars" -PathType Leaf) {"customizations/workspaces/${tf_workspace}/flavorize.tfvars"} Else {"customizations/flavorize.tfvars"} - $terraformstatuscode = 0; #Create the terraform plan terraform plan -detailed-exitcode -var-file="${provider_specific_variable_file}" -var-file="${flavor_variable_file}" -out="${plan}" flavors/${flavor} - #Apply the terraform plan - terraform apply $plan - $terraformstatuscode = 0; + if ($auto_approve -eq "true") { + #Apply the terraform plan + terraform apply $plan + } else { + terraform apply -var-file="${provider_specific_variable_file}" -var-file="${flavor_variable_file}" flavors/${flavor} + } } catch [System.SystemException] { Write-Host "An error occurred during provisioning!" + $terraformstatuscode = 0; } # Only run rest of script if terraform provisioning is successful @@ -90,10 +92,4 @@ If ($terraformstatuscode -ne 1) { Write-Output "Merged kubeconfig file outputted to: credentials/kubeconfig" Write-Output "You're good to go!" Write-Output "Try running the following command: kubectl get pods --all-namespaces" -} - - - - - - +} \ No newline at end of file diff --git a/provision.sh b/provision.sh new file mode 100644 index 0000000..51f37f3 --- /dev/null +++ b/provision.sh @@ -0,0 +1,5 @@ +#!/bin/env bash + +set -eax + +docker run --rm -it -v "$(pwd)":/workspace ryanmcafee/devops-cli /bin/pwsh provision.ps1 "$@"