diff --git a/.github/opentofu-validate.sh b/.github/opentofu-validate.sh index e6516d6..9cee8e8 100644 --- a/.github/opentofu-validate.sh +++ b/.github/opentofu-validate.sh @@ -23,8 +23,6 @@ export IAC_BIN=tofu $IAC_BIN version -for WORKSPACE in $(find . -name 'tf.sh' -print0 | xargs -0 -I{} dirname {} | sort -u); do - pushd "$WORKSPACE" - bash -e tf.sh validate - popd +for WORKSPACE in $(find . \( -name '*.tf' -o -name '*.otf' \) -print0 | xargs -0 -I{} dirname {} | sort -u); do + bash -e tf.sh "$WORKSPACE" validate done diff --git a/.github/terraform-validate.sh b/.github/terraform-validate.sh index 73a0339..24fafeb 100644 --- a/.github/terraform-validate.sh +++ b/.github/terraform-validate.sh @@ -31,8 +31,6 @@ export IAC_BIN=terraform $IAC_BIN version -for WORKSPACE in $(find . -name 'tf.sh' -print0 | xargs -0 -I{} dirname {} | sort -u); do - pushd "$WORKSPACE" - bash -e tf.sh validate - popd +for WORKSPACE in $(find . -name '*.tf' -print0 | xargs -0 -I{} dirname {} | sort -u); do + bash -e tf.sh "$WORKSPACE" validate done diff --git a/.github/workflows/opentofu-checks.yml b/.github/workflows/opentofu-checks.yml index d4d5c2d..a9d2eea 100644 --- a/.github/workflows/opentofu-checks.yml +++ b/.github/workflows/opentofu-checks.yml @@ -24,3 +24,4 @@ on: - .github/workflows/opentofu-checks.yml - '**.otf' - '**.tf' + - tf.sh diff --git a/.github/workflows/terraform-checks.yml b/.github/workflows/terraform-checks.yml index 794cd85..c42e4e5 100644 --- a/.github/workflows/terraform-checks.yml +++ b/.github/workflows/terraform-checks.yml @@ -23,3 +23,4 @@ on: - .github/terraform-fmt.sh - .github/workflows/terraform-checks.yml - '**.tf' + - tf.sh diff --git a/github/johnko/tf.sh b/tf.sh similarity index 85% rename from github/johnko/tf.sh rename to tf.sh index a264a3c..0264091 100755 --- a/github/johnko/tf.sh +++ b/tf.sh @@ -5,7 +5,18 @@ if [[ -z $IAC_BIN ]]; then export IAC_BIN=terraform fi -ACTION="$1" +WORKSPACE="$1" +if [[ -z $WORKSPACE ]]; then + echo "ERROR: missing 'WORKSPACE' as 1st argument" + exit 1 +fi +if [[ ! -d $WORKSPACE ]]; then + echo "ERROR: invalid 'WORKSPACE', received '$WORKSPACE'" + exit 1 +fi +pushd "$WORKSPACE" + +ACTION="$2" if [[ -z $ACTION ]]; then echo "ERROR: missing 'ACTION' as 1st argument" exit 1 @@ -60,3 +71,4 @@ if [[ "APPLY" == "$SAFE_ACTION" || "AUTO" == "$SAFE_ACTION" ]]; then exit $TF_APPLY_EXIT_CODE fi set -e +popd