11---
2- name : e2e test
3-
4- on :
5- pull_request :
6- types : ['opened', 'reopened', 'synchronize']
7- merge_group :
8- workflow_dispatch :
9-
10- permissions :
11- contents : read
12- id-token : write
13-
14- jobs :
15- getexamples :
16- if : github.event.repository.name != 'terraform-azurerm-avm-template'
17- runs-on : ubuntu-latest
18- outputs :
19- examples : ${{ steps.getexamples.outputs.examples }}
20- steps :
21- - uses : actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
22- - name : get examples
23- id : getexamples
24- uses : Azure/terraform-azurerm-avm-template/.github/actions/e2e-getexamples@main
25- with :
26- github-token : ${{ secrets.GITHUB_TOKEN }}
27-
28- testexamples :
29- if : github.event.repository.name != 'terraform-azurerm-avm-template'
30- runs-on : [ self-hosted, 1ES.Pool=ff314ac9fce031b9e7f5dde283f515666e148ae7 ]
31- needs : getexamples
32- environment : test
33- env :
34- TF_IN_AUTOMATION : 1
35- TF_VAR_enable_telemetry : false
36- strategy :
37- matrix :
38- example : ${{ fromJson(needs.getexamples.outputs.examples) }}
39- fail-fast : false
40- steps :
41- - uses : actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
42-
43- - name : Test example
44- shell : bash
45- env :
46- SECRETS_CONTEXT : ${{ toJson(secrets) }}
47- VARS_CONTEXT : ${{ toJson(vars) }}
48- run : |
49- set -e
50- MAX_RETRIES=10
51- RETRY_COUNT=0
52- until [ $RETRY_COUNT -ge $MAX_RETRIES ]
53- do
54- az login --identity --username $MSI_ID > /dev/null && break
55- RETRY_COUNT=$[$RETRY_COUNT+1]
56- sleep 10
57- done
58- if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
59- echo "Failed to login after $MAX_RETRIES attempts."
60- exit 1
61- fi
62-
63- declare -A secrets
64- eval "$(echo $SECRETS_CONTEXT | jq -r 'to_entries[] | @sh "secrets[\(.key|tostring)]=\(.value|tostring)"')"
65-
66- declare -A variables
67- eval "$(echo $VARS_CONTEXT | jq -r 'to_entries[] | @sh "variables[\(.key|tostring)]=\(.value|tostring)"')"
68-
69- for key in "${!secrets[@]}"; do
70- if [[ $key = \TF_VAR_* ]]; then
71- lowerKey=$(echo "$key" | tr '[:upper:]' '[:lower:]')
72- finalKey=${lowerKey/tf_var_/TF_VAR_}
73- export "$finalKey"="${secrets[$key]}"
74- fi
75- done
76-
77- for key in "${!variables[@]}"; do
78- if [[ $key = \TF_VAR_* ]]; then
79- lowerKey=$(echo "$key" | tr '[:upper:]' '[:lower:]')
80- finalKey=${lowerKey/tf_var_/TF_VAR_}
81- export "$finalKey"="${variables[$key]}"
82- fi
83- done
84-
85- echo -e "Custom environment variables:\n$(env | grep TF_VAR_ | grep -v ' "TF_VAR_')"
86-
87- export ARM_SUBSCRIPTION_ID=$(az login --identity --username $MSI_ID | jq -r '.[0] | .id')
88- export ARM_TENANT_ID=$(az login --identity --username $MSI_ID | jq -r '.[0] | .tenantId')
89- export ARM_CLIENT_ID=$(az identity list | jq -r --arg MSI_ID "$MSI_ID" '.[] | select(.principalId == $MSI_ID) | .clientId')
90- docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/src -w /src --network=host -e TF_IN_AUTOMATION -e TF_VAR_enable_telemetry -e AVM_MOD_PATH=/src -e AVM_EXAMPLE=${{ matrix.example }} -e MSI_ID -e ARM_SUBSCRIPTION_ID -e ARM_TENANT_ID -e ARM_CLIENT_ID -e ARM_USE_MSI=true --env-file <(env | grep TF_VAR_ | grep -v ' "TF_VAR_') mcr.microsoft.com/azterraform:latest make test-example
91-
92- # This job is only run when all the previous jobs are successful.
93- # We can use it for PR validation to ensure all examples have completed.
94- testexamplescomplete :
95- if : github.event.repository.name != 'terraform-azurerm-avm-template'
96- runs-on : ubuntu-latest
97- needs : testexamples
98- steps :
99- - run : echo "All tests passed"
2+ name : test examples
3+ on :
4+ pull_request :
5+ types : ['opened', 'reopened', 'synchronize']
6+ merge_group :
7+ workflow_dispatch :
8+
9+ jobs :
10+ check :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - name : Checking for Fork
14+ shell : pwsh
15+ run : |
16+ $isFork = "${{ github.event.pull_request.head.repo.fork }}"
17+ if($isFork -eq "true") {
18+ echo "### WARNING: This workflow is disabled for forked repositories. Please follow the [release branch process](https://azure.github.io/Azure-Verified-Modules/contributing/terraform/terraform-contribution-flow/#5-create-a-pull-request-to-the-upstream-repository) if end to end tests are required." >> $env:GITHUB_STEP_SUMMARY
19+ }
20+
21+ run-e2e-tests :
22+ if : github.event.pull_request.head.repo.fork == false
23+ uses : Azure/terraform-azurerm-avm-template/.github/workflows/test-examples-template.yml@main
24+ name : end to end
25+ secrets : inherit
26+ permissions :
27+ id-token : write
28+ contents : read
29+
0 commit comments