Skip to content

Commit 8af41ae

Browse files
authored
fix: lint create and destroy scripts (rancher#137)
Signed-off-by: matttrach <matt.trachier@suse.com>
1 parent c5652b0 commit 8af41ae

2 files changed

Lines changed: 45 additions & 16 deletions

File tree

modules/deploy/create.sh.tpl

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
1+
#!/usr/bin/env sh
12
set -x
23
DIR=$(pwd)
3-
cd ${deploy_path}
4+
# shellcheck disable=SC2154
5+
cd "${deploy_path}" || exit
46
pwd
57
ls -lah
68
whoami
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
816
terraform version
917

18+
# shellcheck disable=SC2034
1019
TF_CLI_ARGS_init=""
20+
# shellcheck disable=SC2034
1121
TF_CLI_ARGS_apply=""
1222

23+
# shellcheck disable=SC2154
1324
${init_script}
1425

26+
# shellcheck disable=SC2154
1527
MAX=${attempts}
1628
EXITCODE=1
1729
ATTEMPTS=0
1830
E=1
1931
E1=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
5469
done
55-
if [ $ATTEMPTS -eq $MAX ]; then echo "max attempts reached..."; fi
70+
if [ $ATTEMPTS -eq "$MAX" ]; then echo "max attempts reached..."; fi
5671
if [ $EXITCODE -ne 0 ]; then echo "failure, exit code $EXITCODE..."; fi
5772
if [ $EXITCODE -eq 0 ]; then
5873
echo "success...";
5974
terraform output -json -state="tfstate" > outputs.json
6075
fi
61-
cd $DIR
76+
cd "$DIR" || exit
6277
exit $EXITCODE

modules/deploy/destroy.sh.tpl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
#!/usr/bin/env sh
12
set -x
23
DIR=$(pwd)
3-
cd ${deploy_path}
4+
# shellcheck disable=SC2154
5+
cd "${deploy_path}" || exit 1
46
pwd
57
ls -lah
68
whoami
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
816
terraform version
917

18+
# shellcheck disable=SC2034
1019
TF_CLI_ARGS_init=""
20+
# shellcheck disable=SC2034
1121
TF_CLI_ARGS_apply=""
22+
23+
# shellcheck disable=SC2154
1224
if [ -z "${skip_destroy}" ]; then
13-
timeout -k 1m ${timeout} terraform init -upgrade -reconfigure -no-color
14-
timeout -k 1m ${timeout} terraform destroy -var-file="inputs.tfvars" -no-color -auto-approve -state="tfstate" || true
25+
# shellcheck disable=SC2154
26+
timeout -k 1m "${timeout}" terraform init -upgrade -reconfigure -no-color
27+
# shellcheck disable=SC2154
28+
timeout -k 1m "${timeout}" terraform destroy -var-file="inputs.tfvars" -no-color -auto-approve -state="tfstate" || true
1529
else
1630
echo "Not destroying deployed module, it will no longer be managed here."
1731
fi
18-
cd $DIR
32+
cd "$DIR" || exit 1
1933
exit 0

0 commit comments

Comments
 (0)