forked from aztfmod/terraform-azurerm-caf
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (81 loc) · 2.71 KB
/
pr_tests-compute.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
# Copyright (c) Microsoft Corporation
# Licensed under the MIT License.
#
name: PR compute-tests
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'compute_*'
- 'modules/compute/**'
- 'examples/compute/**'
- '.github/workflows/*compute.*'
env:
SCENARIO: standalone-compute.json
TF_VERSION: "1.8.4"
TF_LINT_VERSION: "v0.50.3"
jobs:
load_scenarios:
name: Load Test Scenarios Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.load_scenarios.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: load_scenarios
run: |
cases=$(cat ./.github/workflows/${{ env.SCENARIO }} | jq -c .)
echo "matrix=${cases}" >> $GITHUB_OUTPUT
mock_plan_scenarios:
name: ${{ matrix.config_files }}
runs-on: ubuntu-latest
needs: load_scenarios
strategy:
fail-fast: false
matrix: ${{fromJSON(needs.load_scenarios.outputs.matrix)}}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create environment variables
run: |
cd ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }}
FILE_NAME=$(echo ${{ matrix.config_files }} | sed 's./..g' | xargs)
echo STATE_FILE=${HOME}/tfstates/${FILE_NAME}.tfstate >> $GITHUB_ENV
echo PLAN_FILE=${HOME}/tfstates/${FILE_NAME}.plan >> $GITHUB_ENV
echo CURRENT_FOLDER=${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} >> $GITHUB_ENV
echo PARAMETER_FILES=$(find ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} | grep .tfvars | sed 's/.*/-var-file=&/' | xargs) >> $GITHUB_ENV
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Configure Terraform plugin cache
run: |
echo "TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache" >>"$GITHUB_ENV"
mkdir --parents "$HOME/.terraform.d/plugin-cache"
- name: Cache Terraform
uses: actions/cache@v4
with:
path: |
~/.terraform.d/plugin-cache
key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }}
restore-keys: |
${{ runner.os }}-terraform-
- name: Terraform Init example
id: tf_init
run: |
terraform -chdir=examples \
init
- name: Terraform Test example
id: tf_test
run: |
terraform -chdir=examples \
test \
-test-directory=./tests/mock \
${{ env.PARAMETER_FILES }} \
-verbose