|
1 | | -name: Terraform unit test |
2 | | -description: Terraform unit tests for root module and submodules |
| 1 | +name: Terraform test |
| 2 | +description: | |
| 3 | + Terraform tests for root module and submodules, please set $AVM_TEST_TYPE to "unit" to run unit tests. |
| 4 | + Set $AVM_TEST_TYPE to "integration" to run integration tests. |
3 | 5 | command_groups: |
4 | | - - name: terraform_unit_tests |
5 | | - description: Run Terraform unit tests for root module and submodules |
| 6 | + - name: terraform_tests |
| 7 | + description: Run Terraform tests for root module and submodules |
6 | 8 | commands: |
| 9 | + - type: copycwdtotemp |
| 10 | + name: Copy current working directory to temp |
| 11 | + cwd: "." |
| 12 | + |
| 13 | + - type: shell |
| 14 | + name: Clean Terraform |
| 15 | + command_line: | |
| 16 | + echo $(pwd) && \ |
| 17 | + find . -type d -name .terraform | xargs -n1 rm -rf && \ |
| 18 | + find . -type f -name .terraform.lock.hcl | xargs -n1 rm -f && \ |
| 19 | + find . -type f -name *.tfstate* | xargs -n1 rm -f |
| 20 | +
|
7 | 21 | - type: shell |
8 | | - name: Check for unit tests |
| 22 | + name: Check for AVM_TEST_TYPE env |
9 | 23 | command_line: | |
10 | | - if [ ! -d ./tests/unit ]; then |
11 | | - echo "No unit tests found in $(pwd)" |
| 24 | + if [ -z "$AVM_TEST_TYPE" ]; then |
| 25 | + echo "AVM_TEST_TYPE is not set. Please set AVM_TEST_TYPE to 'unit' or 'integration'." 1>&2 |
| 26 | + echo "E.g. AVM_TEST_TYPE=\"unit\" # ... rest of your command" 1>&2 |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +
|
| 30 | + - type: shell |
| 31 | + name: Check for tests |
| 32 | + command_line: | |
| 33 | + if [ ! -d ./tests/$AVM_TEST_TYPE ]; then |
| 34 | + echo "No $AVM_TEST_TYPE tests found in $(pwd)" |
12 | 35 | exit 99 |
13 | 36 | fi |
14 | 37 | skip_exit_codes: [99] |
| 38 | + |
| 39 | + - type: shell |
| 40 | + name: Check and Run setup.sh |
| 41 | + command_line: | |
| 42 | + if [ -f ./tests/$AVM_TEST_TYPE/setup.sh ]; then |
| 43 | + if [ ! -x ./tests/$AVM_TEST_TYPE/setup.sh ]; then |
| 44 | + echo "Making setup.sh executable" |
| 45 | + chmod +x ./tests/$AVM_TEST_TYPE/setup.sh |
| 46 | + fi |
| 47 | + echo "Running setup.sh" |
| 48 | + ./tests/$AVM_TEST_TYPE/setup.sh |
| 49 | + fi |
| 50 | +
|
15 | 51 | - type: shell |
16 | 52 | name: "Terraform Init" |
17 | | - command_line: "terraform init -test-directory ./tests/unit" |
| 53 | + command_line: "terraform init -test-directory ./tests/$AVM_TEST_TYPE" |
| 54 | + |
18 | 55 | - type: shell |
19 | 56 | name: "Terraform Test" |
20 | | - command_line: "terraform test -test-directory ./tests/unit" |
| 57 | + command_line: "terraform test -test-directory ./tests/$AVM_TEST_TYPE" |
21 | 58 |
|
22 | | -commands: |
23 | | - - type: copycwdtotemp |
24 | | - name: Copy current working directory to temp |
25 | | - cwd: "." |
| 59 | + - type: shell |
| 60 | + name: Clean up |
| 61 | + command_line: | |
| 62 | + rm -fr $(pwd) |
| 63 | + runs_on_condition: always |
26 | 64 |
|
| 65 | +commands: |
27 | 66 | - type: shell |
28 | | - name: Clean Terraform |
29 | | - command_line: | |
30 | | - echo $(pwd) && \ |
31 | | - find . -type d -name .terraform | xargs -n1 rm -rf && \ |
32 | | - find . -type f -name .terraform.lock.hcl | xargs -n1 rm -f && \ |
33 | | - find . -type f -name *.tfstate* | xargs -n1 rm -f |
| 67 | + name: install terraform |
| 68 | + command_line: terraform -version |
| 69 | + cwd: "." |
34 | 70 |
|
35 | 71 | - type: parallel |
36 | | - name: Unit tests |
| 72 | + name: Terraform tests |
37 | 73 | env: |
38 | 74 | TF_IN_AUTOMATION: "1" |
39 | 75 | commands: |
40 | 76 | - type: foreachdirectory |
41 | 77 | name: submodules |
| 78 | + depth: 1 |
42 | 79 | working_directory: "./modules" |
43 | 80 | mode: parallel |
44 | | - command_group: terraform_unit_tests |
| 81 | + skip_on_not_exist: true |
| 82 | + command_group: terraform_tests |
| 83 | + working_directory_strategy: item_relative |
45 | 84 |
|
46 | 85 | - type: serial |
47 | 86 | name: root module |
48 | | - command_group: terraform_unit_tests |
49 | | - |
50 | | - - type: shell |
51 | | - name: Clean up |
52 | | - command_line: | |
53 | | - rm -fr $(pwd) |
54 | | - runs_on_condition: always |
| 87 | + command_group: terraform_tests |
0 commit comments