|
1 | | -name: 'Terraform' |
| 1 | +name: Terraform |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | | - - "main" |
| 6 | + - 'main' |
7 | 7 | pull_request: |
8 | 8 | paths: |
9 | | - - terraform/** |
10 | | - - .github/workflows/terraform.yml |
11 | | - |
12 | | -permissions: |
13 | | - contents: read |
| 9 | + - 'terraform/**' |
| 10 | + - '.github/workflows/terraform.yml' |
14 | 11 |
|
15 | 12 | env: |
| 13 | + PYTEST_ADDOPTS: "--color=yes" |
| 14 | + PYTHON_VERSION: 3.11 |
| 15 | + TF_PLUGIN_CACHE_DIR: "/home/runner/.terraform.d/plugin-cache" |
16 | 16 | TF_VERSION: 1.5.7 |
| 17 | + TFTESTS_FOLDER: "terraform/tests" |
17 | 18 |
|
18 | 19 | jobs: |
19 | 20 | terraform: |
20 | | - name: 'Terraform' |
21 | 21 | runs-on: ubuntu-latest |
22 | | - environment: production |
23 | 22 | strategy: |
24 | 23 | matrix: |
25 | 24 | provider: ['azure', 'gcp', 'aws'] |
26 | 25 |
|
27 | | - # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest |
28 | 26 | defaults: |
29 | 27 | run: |
30 | 28 | shell: bash |
31 | 29 | working-directory: terraform/${{ matrix.provider }} |
32 | 30 |
|
33 | 31 | steps: |
34 | | - # Checkout the repository to the GitHub Actions runner |
35 | 32 | - name: Checkout |
36 | 33 | uses: actions/checkout@v3 |
37 | 34 |
|
38 | | - # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token |
| 35 | + # Install the specific version of Terraform that the project support and |
39 | 36 | - name: Setup Terraform |
40 | 37 | uses: hashicorp/setup-terraform@v2 |
41 | 38 | with: |
42 | 39 | terraform_version: ${{ env.TF_VERSION }} |
43 | 40 | terraform_wrapper: false |
44 | 41 |
|
45 | | - # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. |
| 42 | + # Initialize each CSP Terraform working directory |
| 43 | + # by creating initial files, downloading modules, etc. |
46 | 44 | - name: Terraform Init |
47 | 45 | run: terraform init |
48 | 46 |
|
|
53 | 51 | # Validate |
54 | 52 | - name: Terraform Validate |
55 | 53 | run: terraform validate |
| 54 | + |
| 55 | + tftest: |
| 56 | + runs-on: ubuntu-latest |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Checkout |
| 60 | + uses: actions/checkout@v3 |
| 61 | + |
| 62 | + # Install the specific version of Terraform that the project support and |
| 63 | + - name: Setup Terraform |
| 64 | + uses: hashicorp/setup-terraform@v2 |
| 65 | + with: |
| 66 | + terraform_version: ${{ env.TF_VERSION }} |
| 67 | + terraform_wrapper: false |
| 68 | + |
| 69 | + - name: Run tftests |
| 70 | + run: | |
| 71 | + mkdir -p ${{ env.TF_PLUGIN_CACHE_DIR }} |
| 72 | + pip install -r ${{ env.TFTESTS_FOLDER }}/requirements.txt |
| 73 | + pytest -vv -o log_cli=true -o log_cli_level=10 ${{ env.TFTESTS_FOLDER }} |
0 commit comments