@@ -3,15 +3,22 @@ name: 'Terraform'
33on :
44 push :
55 branches :
6- - " main"
6+ - ' main'
77 pull_request :
88 paths :
9- - terraform/**
10- - .github/workflows/terraform.yml
9+ - ' terraform/**'
10+ - ' .github/workflows/terraform.yml'
1111
1212permissions :
1313 contents : read
1414
15+ env :
16+ PYTEST_ADDOPTS : " --color=yes"
17+ PYTHON_VERSION : 3.11
18+ TF_PLUGIN_CACHE_DIR : " /home/runner/.terraform.d/plugin-cache"
19+ TF_VERSION : 1.5.7
20+ TFTESTS_FOLDER : " terraform/tests"
21+
1522jobs :
1623 terraform :
1724 name : ' Terraform'
2128 matrix :
2229 provider : ['azure', 'gcp', 'aws']
2330
24- # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
2531 defaults :
2632 run :
2733 shell : bash
@@ -32,12 +38,15 @@ jobs:
3238 - name : Checkout
3339 uses : actions/checkout@v3
3440
35- # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token
41+ # Install the specific version of Terraform that the project support and
3642 - name : Setup Terraform
3743 uses : hashicorp/setup-terraform@v2
3844 with :
39- terraform_version : 1.5.7
40- # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
45+ terraform_version : ${{ env.TF_VERSION }}
46+ terraform_wrapper : false
47+
48+ # Initialize each CSP Terraform working directory
49+ # by creating initial files, downloading modules, etc.
4150 - name : Terraform Init
4251 run : terraform init
4352
4857 # Validate
4958 - name : Terraform Validate
5059 run : terraform validate
60+
61+ # Plan
62+ - name : Terraform Plan
63+ run : terraform plan -out=plan.zip
64+
65+ - name : Run tftests
66+ run : |
67+ mkdir -p ${{ env.TF_PLUGIN_CACHE_DIR }}
68+ pip install -r ${{ env.TFTESTS_FOLDER }}/requirements.txt
69+ pytest -vv -o log_cli=true -o log_cli_level=10 ${{ env.TFTESTS_FOLDER }}
0 commit comments