Terraform Tests #221
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
schedule: | |
- cron: '0 19 * * 6' | |
workflow_dispatch: | |
inputs: | |
services: | |
type: string | |
required: false | |
default: 'ls-all' | |
description: name of the service to execute tests for (e.g. "ls-community", "ls-pro", "ls-all", "s3,iam,ec2") | |
enable-pro: | |
type: string | |
required: false | |
default: 'true' | |
description: determine if pro capabilities should be enabled | |
tinybird-reporting: | |
type: string | |
required: false | |
default: 'false' | |
description: determine whether results should be reported to tinybird | |
name: Terraform Tests | |
jobs: | |
prepare_list: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: 'true' | |
- id: set-matrix | |
run: echo "matrix=$(python -m terraform_pytest.get_services ${{ github.event.inputs.services || 'ls-all' }})" >> $GITHUB_OUTPUT | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
test_service: | |
needs: prepare_list | |
strategy: | |
max-parallel: 10 | |
fail-fast: false | |
matrix: | |
service_partition: ${{ fromJson(needs.prepare_list.outputs.matrix) }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: 'true' | |
- uses: actions/setup-go@v3 | |
with: | |
go-version: '1.20.x' | |
cache: true | |
cache-dependency-path: terraform-provider-aws/go.sum | |
- uses: actions/checkout@v3 | |
if: ${{ (github.event.inputs.tinybird-reporting || 'true') == 'true' }} | |
with: | |
repository: tinybirdco/pytest-tinybird | |
path: pytest-tinybird | |
- name: Set up Python 3.10.5 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10.5' | |
cache: 'pip' | |
- name: Install system dependencies | |
run: | | |
python -m venv .venv | |
source .venv/bin/activate | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Apply Terraform Plugin Sdk Patch | |
run: | | |
cd terraform-provider-aws | |
sdk_version=$(go list -m github.com/hashicorp/terraform-plugin-sdk/v2 | sed -n -e 's/^.* //p') | |
go mod edit --replace github.com/hashicorp/terraform-plugin-sdk/v2=github.com/localstack/terraform-plugin-sdk/v2@${sdk_version} | |
go mod tidy | |
- name: Patch Terraform Provider | |
run: | | |
source .venv/bin/activate | |
cd terraform-provider-aws && go mod vendor | |
cd ../ | |
python -m terraform_pytest.main patch | |
- name: Build ${{ matrix.service_partition.service }} Binary | |
run: | | |
source .venv/bin/activate | |
python -m terraform_pytest.main build -s ${{ matrix.service_partition.service }} | |
ls -la ./test-bin | |
- name: Setup tinybird plugin | |
if: ${{ (github.event.inputs.tinybird-reporting || 'true') == 'true' }} | |
run: | | |
source .venv/bin/activate | |
cd pytest-tinybird | |
python setup.py install | |
- name: Setup LocalStack | |
env: | |
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} | |
TMP_USER: ${{ secrets.TMP_USER }} | |
TMP_PW: ${{ secrets.TMP_PW }} | |
run: | | |
source .venv/bin/activate | |
pip install --pre localstack | |
enable_pro=${{ inputs.enable-pro || 'true' }} | |
if [[ $enable_pro != 'true' ]] | |
then | |
docker pull localstack/localstack | |
else | |
docker pull localstack/localstack-pro | |
localstack auth login -u $TMP_USER -p $TMP_PW # login is currently required | |
localstack extensions init | |
localstack extensions install "git+https://github.com/localstack/localstack-moto-test-coverage/#egg=collect-raw-metric-data-extension&subdirectory=collect-raw-metric-data-extension" | |
fi | |
- name: Run ${{ matrix.service_partition.service }} - ${{ matrix.service_partition.partition }} Tests | |
env: | |
SERVICE: ${{ matrix.service_partition.service }} | |
PARTITION: ${{ matrix.service_partition.partition }} | |
TINYBIRD_URL: https://api.tinybird.co | |
TINYBIRD_DATASOURCE: localstack_terraform_test_results | |
TINYBIRD_TOKEN: ${{ secrets.TINYBIRD_TOKEN }} | |
CI_COMMIT_SHA: ${{ github.sha }} | |
CI_JOB_ID: ${{ github.job }} | |
CI_JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
CI_JOB_NAME: ${{ github.job }}-${{ matrix.service_partition.service }}-${{ matrix.service_partition.partition }} | |
run: | | |
source .venv/bin/activate | |
enable_pro=${{ inputs.enable-pro || 'true' }} | |
enable_tinybird=${{ inputs.tinybird-reporting || 'true' }} | |
if [[ $enable_pro == 'true' ]] | |
then | |
export LOCALSTACK_API_KEY=${{ secrets.LOCALSTACK_API_KEY }} | |
fi | |
if [[ $enable_tinybird == 'true' ]] | |
then | |
options="-s -v --ls-start --gather-metrics --report-to-tinybird" | |
else | |
options="-s -v --ls-start --gather-metrics" | |
fi | |
if [[ ${{ matrix.service_partition.service }} == "lambda" ]] | |
then | |
make prepare-lambda | |
fi | |
if [[ ${{ matrix.service_partition.partition }} == "All" ]] | |
then | |
python -m pytest --junitxml=target/reports/pytest.xml terraform-provider-aws/internal/service/${{ matrix.service_partition.service }} $options | |
else | |
python -m pytest --junitxml=target/reports/pytest.xml $(python terraform_pytest/get_tf_partitions.py ${{ matrix.service_partition.service }} ${{ matrix.service_partition.partition }} ) $options | |
fi | |
- name: Archive Test Result | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: test-metrics | |
path: target/reports | |
- name: Publish ${{ matrix.service }} Test Results | |
uses: EnricoMi/publish-unit-test-result-action@v2 | |
if: always() | |
with: | |
junit_files: target/reports/*.xml | |
check_name: ${{ matrix.service }} Terraform Test Results |