1+ #! /usr/bin/env sh
12set -x
23DIR=$( pwd)
3- cd ${ deploy_path}
4+ # shellcheck disable=SC2154
5+ cd " ${deploy_path} " || exit
46pwd
57ls -lah
68whoami
7- . envrc
9+ if [ -f ./envrc ]; then
10+ # shellcheck disable=SC1091
11+ . ./envrc
12+ else
13+ echo " can't find envrc..."
14+ exit 1
15+ fi
816terraform version
917
18+ # shellcheck disable=SC2034
1019TF_CLI_ARGS_init=" "
20+ # shellcheck disable=SC2034
1121TF_CLI_ARGS_apply=" "
1222
23+ # shellcheck disable=SC2154
1324${init_script}
1425
26+ # shellcheck disable=SC2154
1527MAX=${attempts}
1628EXITCODE=1
1729ATTEMPTS=0
1830E=1
1931E1=0
20- while [ $EXITCODE -gt 0 ] && [ $ATTEMPTS -lt $MAX ]; do
32+ while [ $EXITCODE -gt 0 ] && [ $ATTEMPTS -lt " $MAX " ]; do
2133 A=0
22- while [ $E -gt 0 ] && [ $A -lt $MAX ]; do
23- timeout -k 1m ${ timeout} terraform apply -var-file="inputs.tfvars" -no-color -auto-approve -state="tfstate"
34+ while [ $E -gt 0 ] && [ $A -lt " $MAX " ]; do
35+ # shellcheck disable=SC2154
36+ timeout -k 1m " ${timeout} " terraform apply -var-file=" inputs.tfvars" -no-color -auto-approve -state=" tfstate"
2437 E=$?
2538 if [ $E -eq 124 ]; then echo " Apply timed out after ${timeout} " ; fi
2639 A=$(( A+ 1 ))
2740 done
2841 # don't destroy if the last attempt fails
2942 if [ $E -gt 0 ] && [ $ATTEMPTS != $(( MAX- 1 )) ]; then
3043 A1=0
31- while [ $E1 -gt 0 ] && [ $A1 -lt $MAX ]; do
32- timeout -k 1m ${ timeout} terraform destroy -var-file="inputs.tfvars" -no-color -auto-approve -state="tfstate"
44+ while [ $E1 -gt 0 ] && [ $A1 -lt " $MAX " ]; do
45+ timeout -k 1m " ${timeout} " terraform destroy -var-file=" inputs.tfvars" -no-color -auto-approve -state=" tfstate"
3346 E1=$?
3447 if [ $E1 -eq 124 ]; then echo " Apply timed out after ${timeout} " ; fi
3548 A1=$(( A1 + 1 ))
@@ -47,16 +60,18 @@ while [ $EXITCODE -gt 0 ] && [ $ATTEMPTS -lt $MAX ]; do
4760 EXITCODE=0
4861 fi
4962 ATTEMPTS=$(( ATTEMPTS+ 1 ))
50- if [ $EXITCODE -gt 0 ] && [ $ATTEMPTS -lt $MAX ]; then
63+ if [ $EXITCODE -gt 0 ] && [ $ATTEMPTS -lt " $MAX " ]; then
64+ # shellcheck disable=SC2154
5165 echo " wait ${interval} seconds between attempts..."
52- sleep ${ interval}
66+ # shellcheck disable=SC2154
67+ sleep " ${interval} "
5368 fi
5469done
55- if [ $ATTEMPTS -eq $MAX ]; then echo "max attempts reached..."; fi
70+ if [ $ATTEMPTS -eq " $MAX " ]; then echo " max attempts reached..." ; fi
5671if [ $EXITCODE -ne 0 ]; then echo " failure, exit code $EXITCODE ..." ; fi
5772if [ $EXITCODE -eq 0 ]; then
5873 echo " success..." ;
5974 terraform output -json -state=" tfstate" > outputs.json
6075fi
61- cd $DIR
76+ cd " $DIR " || exit
6277exit $EXITCODE
0 commit comments