diff --git a/README.md b/README.md index c99eb43..ee5e89c 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ -# iac-github \ No newline at end of file +# iac-github + +``` +./tf.sh github/johnko fmt + +./tf.sh github/johnko validate + +./tf.sh github/johnko plan + +./tf.sh github/johnko apply + +./tf.sh github/johnko auto +``` diff --git a/tf.sh b/tf.sh index 0264091..cfc2b2c 100755 --- a/tf.sh +++ b/tf.sh @@ -14,6 +14,7 @@ if [[ ! -d $WORKSPACE ]]; then echo "ERROR: invalid 'WORKSPACE', received '$WORKSPACE'" exit 1 fi +echo "WORKSPACE=$WORKSPACE" pushd "$WORKSPACE" ACTION="$2" @@ -34,30 +35,52 @@ case $SAFE_ACTION in ;; esac echo "SAFE_ACTION=$SAFE_ACTION" + set -ux $IAC_BIN fmt + set +x -if [[ "APPLY" == "$SAFE_ACTION" || "AUTO" == "$SAFE_ACTION" || "PLAN" == "$SAFE_ACTION" || "VALIDATE" == "$SAFE_ACTION" ]]; then +if [[ "FMT" == "$SAFE_ACTION" ]]; then set -x - $IAC_BIN init + exit 0 fi + +set -x +$IAC_BIN init + +set +x +if [[ "INIT" == "$SAFE_ACTION" ]]; then + set -x + exit 0 +fi + +set -x $IAC_BIN validate + +set +x +if [[ "VALIDATE" == "$SAFE_ACTION" ]]; then + set -x + exit 0 +fi + set +x if [[ "APPLY" == "$SAFE_ACTION" || "AUTO" == "$SAFE_ACTION" || "PLAN" == "$SAFE_ACTION" ]]; then if [[ -e import.sh ]]; then + set -x bash -ex import.sh fi +fi + +set +x +if [[ "PLAN" == "$SAFE_ACTION" ]]; then set -x set +e $IAC_BIN plan -detailed-exitcode -input=false -parallelism=5 TF_PLAN_EXIT_CODE=$? set -e - set +x - if [[ "PLAN" == "$SAFE_ACTION" ]]; then - set -x - exit $TF_PLAN_EXIT_CODE - fi + exit $TF_PLAN_EXIT_CODE fi + set +x if [[ "APPLY" == "$SAFE_ACTION" || "AUTO" == "$SAFE_ACTION" ]]; then AUTO_APPROVE_ARG="" @@ -68,7 +91,8 @@ if [[ "APPLY" == "$SAFE_ACTION" || "AUTO" == "$SAFE_ACTION" ]]; then set +e $IAC_BIN apply $AUTO_APPROVE_ARG -input=false -parallelism=5 TF_APPLY_EXIT_CODE=$? + set -e exit $TF_APPLY_EXIT_CODE fi -set -e + popd