Last active
June 8, 2024 00:37
-
-
Save kewalaka/93ec3da3c6a39610da3eef4b04c37365 to your computer and use it in GitHub Desktop.
using GitHub Cloud runners for E2E tests with Azure Verified Modules
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
# from .github/actions/e2e-testexamples/ | |
author: AVM | |
name: e2e - testexamples | |
description: Tests the example supplied in the input. Needs checkout and Azure login prior. | |
inputs: | |
example: | |
description: The example directory to test | |
required: true | |
runs: | |
using: composite | |
steps: | |
- uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_version: ">=1.5.0" | |
- name: terraform init | |
run: terraform init | |
working-directory: examples/${{ inputs.example }} | |
shell: bash | |
- name: terraform apply | |
run: terraform apply -auto-approve | |
working-directory: examples/${{ inputs.example }} | |
shell: bash | |
- name: terraform plan | |
id: plan | |
run: | | |
terraform plan -detailed-exitcode | |
echo PLANCODE="$?" >> "$GITHUB_OUTPUT" | |
continue-on-error: true | |
working-directory: examples/${{ inputs.example }} | |
shell: bash | |
- name: check idempotent | |
run: | | |
echo Error: terraform plan code is ${{ steps.plan.outputs.PLANCODE }} | |
exit 1 | |
working-directory: examples/${{ inputs.example }} | |
shell: bash | |
if: steps.plan.outputs.PLANCODE != 0 | |
- name: terraform destroy | |
run: terraform destroy -auto-approve | |
working-directory: examples/${{ inputs.example }} | |
shell: bash | |
if: always() |
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
--- | |
name: e2e test | |
on: | |
pull_request: | |
types: ['opened', 'reopened', 'synchronize'] | |
merge_group: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
id-token: write | |
jobs: | |
getexamples: | |
if: github.event.repository.name != 'terraform-azurerm-avm-template' | |
runs-on: ubuntu-latest | |
outputs: | |
examples: ${{ steps.getexamples.outputs.examples }} | |
steps: | |
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6 | |
- name: get examples | |
id: getexamples | |
uses: Azure/terraform-azurerm-avm-template/.github/actions/e2e-getexamples@main | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
testexamples: | |
if: github.event.repository.name != 'terraform-azurerm-avm-template' | |
runs-on: ubuntu-latest # runs-on: [ self-hosted, 1ES.Pool=terraform-azurerm-avm-template ] | |
needs: getexamples | |
environment: test | |
env: | |
TF_IN_AUTOMATION: 1 | |
TF_VAR_enable_telemetry: false | |
strategy: | |
matrix: | |
example: ${{ fromJson(needs.getexamples.outputs.examples) }} | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 #v4.1.6 | |
- uses: Azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Test example | |
uses: Azure/terraform-azurerm-avm-template/.github/actions/e2e-testexamples@main | |
with: | |
example: ${{ matrix.example }} | |
# This job is only run when all the previous jobs are successful. | |
# We can use it for PR validation to ensure all examples have completed. | |
testexamplescomplete: | |
if: github.event.repository.name != 'terraform-azurerm-avm-template' | |
runs-on: ubuntu-latest | |
needs: testexamples | |
steps: | |
- run: echo "All tests passed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment