-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (97 loc) · 3.54 KB
/
test-data-terraform-ci.yml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
name: Test Data (Terraform CI)
on:
push:
workflow_dispatch:
pull_request:
types: [opened, edited, synchronize]
env:
TF_ROOT: test/terraform
jobs:
set_up_job:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set matrix
id: set-matrix
run: |
MODULES_DIR="${{ env.TF_ROOT }}/*"
MODULES=$(find $MODULES_DIR -maxdepth 1 -type d | sed "s|${{ env.TF_ROOT }}/||") # Exclude base TF_ROOT from list
DIRS_ARRAY=()
for module in $MODULES
do
# Exclude certain directories as needed.
if [[ "$module" != "_env" ]]; then
DIRS_ARRAY+=("$module")
fi
done
MODULES_JSON=$(echo "${DIRS_ARRAY[@]}" | jq -R -s -c 'split(" ")')
echo "::set-output name=matrix::${MODULES_JSON}"
ci:
needs: set_up_job
runs-on: ubuntu-latest
strategy:
matrix:
module: ${{fromJson(needs.set_up_job.outputs.matrix)}}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform Init
run: |
cd ${{ env.TF_ROOT }}/${{ matrix.module }}
terraform init
- name: Terraform Fmt
run: |
cd ${{ env.TF_ROOT }}/${{ matrix.module }}
terraform fmt -check -recursive
- name: Terraform Validate
run: |
cd ${{ env.TF_ROOT }}/${{ matrix.module }}
terraform validate
- name: Validate Terraform docs file
run: |
cd ${{ env.TF_ROOT }}/${{ matrix.module }}
if [ -f .terraform-docs.yml ]; then
echo "terraform-docs configuration file found"
cat .terraform-docs.yml
else
echo "Error: .terraform-docs.yml file not found"
exit 1
fi
- name: Validate TFLint file
run: |
cd ${{ env.TF_ROOT }}/${{ matrix.module }}
if [ -f .tflint.hcl ]; then
echo "TFLint configuration file found"
cat .tflint.hcl
else
echo "Error: .tflint.hcl file not found"
exit 1
fi
- name: Check for README.md file
run: |
cd ${{ env.TF_ROOT }}/${{ matrix.module }}
if [ -f README.md ]; then
echo "README.md file found"
else
echo "Error: README.md file not found"
exit 1
fi
- name: Terraform TFLintSetup
id: terraform-tflint-setup
uses: terraform-linters/setup-tflint@v1
with:
tflint_version: latest
- name: TFLint Run
id: terraform-tflint-run
run: |
cd ${{ env.TF_ROOT }}/${{ matrix.module }}
tflint --version
tflint --init
tflint --disable-rule=terraform_module_pinned_source
tflint