Skip to content

Commit

Permalink
[terraform-ci] Added bats (#124)
Browse files Browse the repository at this point in the history
* Added bats
  • Loading branch information
goruha authored Jul 12, 2024
1 parent df61cc6 commit cbe6afd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci-terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,44 @@ jobs:
shell: bash
run: git diff --exit-code

bats:
runs-on: ubuntu-latest
container: cloudposse/test-harness:latest
env:
MAKE_INCLUDES: Makefile
TF_PLUGIN_CACHE_DIR: /tmp
BATS_MODULE_TESTS: input-descriptions module-pinning provider-pinning output-descriptions
BATS_EXAMPLES_TESTS: input-descriptions lint output-descriptions
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run tests on modified modules
shell: bash -x -e -o pipefail {0}
run: |
# when running in test-harness, need to mark the directory safe for git operations
make git-safe-directory
MODIFIED_MODULES=($(find . -type f -name "*.tf" | xargs -I{} dirname {} | sort | uniq | grep -v ^./.git/ || true))
pass=true
for relative_dir in "${MODIFIED_MODULES[@]}"; do
dir=$(realpath $relative_dir)
printf "\n\nBegin testing in $dir\n"
(
status=pass
cd $dir
[[ $relative_dir =~ ./examples/.* ]] && tests=$BATS_EXAMPLES_TESTS || tests=$BATS_MODULE_TESTS
for test in $tests; do
printf "\n\nRunning ${test} in $dir\n"
bats -t /test/terraform/${test}.bats || status=fail
done
[[ $status == "pass" ]]
) || pass=false
printf "\n\nEnd of testing in $dir\n\n\n"
done
[[ $pass == "true" ]]
lint-find-dirs:
name: Find modules
runs-on: ${{ fromJSON(inputs.runs-on) }}
Expand Down

0 comments on commit cbe6afd

Please sign in to comment.