Skip to content

Commit

Permalink
Fixed issue that was causing error handling in provision script to no…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
ryanmcafee committed Jun 10, 2020
1 parent e2b8171 commit 83aeb35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
24 changes: 10 additions & 14 deletions provision.ps1
Original file line number Diff line number Diff line change
@@ -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
)

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






}
5 changes: 5 additions & 0 deletions provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/env bash

set -eax

docker run --rm -it -v "$(pwd)":/workspace ryanmcafee/devops-cli /bin/pwsh provision.ps1 "$@"

0 comments on commit 83aeb35

Please sign in to comment.