Skip to content

Commit dea45ac

Browse files
committed
Add tftest POC
Add tftest about terraform init, add it to the terraform github workflow. Use latest ubuntu everywhere in all github workflows.
1 parent 02b37af commit dea45ac

8 files changed

Lines changed: 79 additions & 30 deletions

File tree

.github/workflows/ansible.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ name: Ansible
33
on:
44
push:
55
branches:
6-
- "main"
6+
- 'main'
77
pull_request:
88
paths:
9-
- ansible/**
10-
- requirements.txt
11-
- .github/workflows/ansible.yml
9+
- 'ansible/**'
10+
- 'requirements.txt'
11+
- '.github/workflows/ansible.yml'
1212

1313
jobs:
1414
build:
@@ -26,4 +26,4 @@ jobs:
2626
- name: Run ansible static tests
2727
run: |
2828
make -n static-ansible
29-
make SHELL='sh -x' static-ansible
29+
make SHELL='sh -x' static-ansible

.github/workflows/gluescript.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,59 @@ name: Glue Script
33
on:
44
push:
55
branches:
6-
- "main"
6+
- 'main'
77
pull_request:
88
paths:
9-
- scripts/qesap/**
10-
- .github/workflows/gluescript.yml
9+
- 'scripts/qesap/**'
10+
- '.github/workflows/gluescript.yml'
1111

1212
jobs:
1313
build:
1414
runs-on: ${{ matrix.platform }}
1515
strategy:
1616
matrix:
17-
platform: [ubuntu-20.04]
17+
platform: [ubuntu-latest]
1818
# all available versions are in https://github.com/actions/python-versions/blob/main/versions-manifest.json
1919
python-version: ['3.10.14', '3.11.9', '3.12.3']
2020

2121
steps:
2222
- uses: actions/checkout@v3
23+
2324
- name: Set up Python ${{ matrix.python-version }}
2425
uses: actions/setup-python@v4
2526
with:
2627
python-version: ${{ matrix.python-version }}
28+
2729
- name: Install dependencies
2830
run: |
2931
python -m pip install --upgrade pip
3032
python -m pip install tox tox-gh-actions
33+
3134
- name: PyLint with tox
3235
working-directory: scripts/qesap/
3336
run: tox -e pylint
3437
env:
3538
PLATFORM: ${{ matrix.platform }}
39+
3640
- name: flake8 with tox
3741
working-directory: scripts/qesap/
3842
run: tox -e flake8
3943
env:
4044
PLATFORM: ${{ matrix.platform }}
45+
4146
- name: flake8 test code with tox
4247
working-directory: scripts/qesap/
4348
run: |
4449
tox -e flake8_test
4550
env:
4651
PLATFORM: ${{ matrix.platform }}
52+
4753
- name: UT tox
4854
working-directory: scripts/qesap/
4955
run: tox
5056
env:
5157
PLATFORM: ${{ matrix.platform }}
58+
5259
- name: Test UT variants
5360
working-directory: scripts/qesap/
5461
run: |
@@ -57,6 +64,7 @@ jobs:
5764
tox -e pytest_finddep
5865
env:
5966
PLATFORM: '3.11.9'
67+
6068
- name: Test e2e
6169
run: |
6270
python -m pip install -r requirements.txt

.github/workflows/markdown.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ name: 'Markdown'
33
on:
44
push:
55
branches:
6-
- "main"
6+
- 'main'
77
pull_request:
88
paths:
9-
- README.md
10-
- CONTRIBUTING.md
11-
- terraform/aws/README.md
12-
- terraform/azure/README.md
13-
- terraform/gcp/README.md
14-
- .github/workflows/markdown.yml
9+
- 'README.md'
10+
- 'CONTRIBUTING.md'
11+
- 'terraform/aws/README.md'
12+
- 'terraform/azure/README.md'
13+
- 'terraform/gcp/README.md'
14+
- '.github/workflows/markdown.yml'
1515

1616
permissions:
1717
contents: read

.github/workflows/terraform.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ name: 'Terraform'
33
on:
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

1212
permissions:
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+
1522
jobs:
1623
terraform:
1724
name: 'Terraform'
@@ -21,7 +28,6 @@ jobs:
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

@@ -48,3 +57,13 @@ jobs:
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 }}

.github/workflows/tools.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
name: Tools environment
2-
2+
# Purpose of this workflow is to check that all binary the project
3+
# is recommending are installable and usable on openSUSE TW.
4+
# This workflow refer to th eDockerfile in the root of the repo.
35
on:
46
push:
57
branches:
6-
- "main"
8+
- 'main'
79
pull_request:
810
paths:
9-
- Dockerfile
10-
- requirements.txt
11-
- requirements.yml
12-
- .github/workflows/tools.yml
13-
11+
- 'Dockerfile'
12+
- 'requirements.txt'
13+
- 'requirements.yml'
14+
- '.github/workflows/tools.yml'
15+
- 'terraform/azure/version.tf'
16+
- 'terraform/aws/version.tf'
17+
- 'terraform/gcp/version.tf'
1418
env:
1519
REGISTRY: ghcr.io
1620

terraform/tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
import pytest
3+
4+
5+
@pytest.fixture(scope='session')
6+
def fixtures_dir():
7+
return os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')

terraform/tests/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest>=7.2
2+
tftest==1.8.5

terraform/tests/test_init.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pytest
2+
import tftest
3+
4+
5+
@pytest.mark.parametrize("csp", ['azure', 'aws', 'gcp'])
6+
def test_init(fixtures_dir, csp):
7+
tf = tftest.TerraformTest(csp, fixtures_dir)
8+
init_out = tf.init(output=True)
9+
assert 'Terraform has been successfully initialized' in init_out

0 commit comments

Comments
 (0)