Skip to content

Commit

Permalink
Add terraform-test action
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed Jun 1, 2024
1 parent 6dde691 commit e4e2ce4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/test-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Check
- name: Test
uses: ./terraform-test
with:
path: tests/workflows/test-test/local
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Check
- name: Test
uses: ./terraform-test
with:
path: tests/workflows/test-test/local
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Check
- name: Test
uses: ./terraform-test
with:
path: tests/workflows/test-test/local
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Check
- name: Test
uses: ./terraform-test
id: failing
continue-on-error: true
Expand All @@ -68,3 +68,8 @@ jobs:
echo "Test did not fail correctly"
exit 1
fi
if [[ "${{ steps.failing.outcome }}" != "failure" ]]; then
echo "Test did not fail correctly"
exit 1
fi
7 changes: 5 additions & 2 deletions image/entrypoints/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function set-test-args() {
fi

if [[ -n "$INPUT_TEST_PATH" ]]; then
TEST_ARGS="$TEST_ARGS -test-directory=$(relative_to "$INPUT_PATH" "$INPUT_TEST_PATH")"
TEST_ARGS="$TEST_ARGS -test-directory=$INPUT_TEST_PATH"
fi

if [[ -n "$INPUT_TEST_FILTER" ]]; then
Expand All @@ -32,4 +32,7 @@ PLAN_ARGS=""
set-variable-args

debug_log $TOOL_COMMAND_NAME test -no-color $TEST_ARGS '$PLAN_ARGS' # don't expand PLAN_ARGS
$TOOL_COMMAND_NAME test -no-color $TEST_ARGS $PLAN_ARGS
if ! (cd "$INPUT_PATH" && $TOOL_COMMAND_NAME test -no-color $TEST_ARGS $PLAN_ARGS); then
set_output failure-reason tests-failed
exit 1
fi
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
run "require_provider" {
# This will require terraform to be initialised correctly to bring in the time provider
command = apply

module = {
source = "./sleep"
}
}

run "test_third" {
command = apply

Expand Down
3 changes: 3 additions & 0 deletions tests/workflows/test-test/local/sleep/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "time_sleep" "this" {
create_duration = "1s"
}

0 comments on commit e4e2ce4

Please sign in to comment.