Skip to content

Commit 6749ac1

Browse files
committed
[autoSync] CI: add fmt, validate, tflint check
1 parent afb8faa commit 6749ac1

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

Diff for: .github/workflows/e2e.yml

+99
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,107 @@ on:
1111
- '**/*.tf'
1212

1313
jobs:
14+
terraform-fmt:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: checkout
18+
uses: actions/checkout@v3
19+
- name: fmt-check
20+
run: |
21+
if [ ! -f /usr/local/bin/terraform ]; then
22+
wget -q https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
23+
unzip terraform_1.6.0_linux_amd64.zip -d /usr/local/bin/
24+
fi
25+
error=false
26+
echo "===> Terraform fmt -diff checking"
27+
terraform fmt -diff -recursive -check
28+
if [[ $? -ne 0 ]]; then
29+
echo -e "\033[31m[ERROR]\033[0m: Some codes has not been formatted, and please running terraform fmt --recursive command before pushing."
30+
exit 1
31+
fi
32+
33+
terraform-validate:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: checkout
37+
uses: actions/checkout@v3
38+
- name: validate-check
39+
run: |
40+
if [ ! -f /usr/local/bin/terraform ]; then
41+
wget -q https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
42+
unzip terraform_1.6.0_linux_amd64.zip -d /usr/local/bin/
43+
fi
44+
exp="examples"
45+
submod="modules"
46+
output_file="combined_output.txt"
47+
echo "./" > "$output_file"
48+
if [[ -d "$exp" ]]; then
49+
find $exp -type d -print -mindepth 1 -maxdepth 1 >> $output_file
50+
fi
51+
if [[ -d "$submod" ]]; then
52+
find $submod -type d -print -mindepth 1 -maxdepth 1 >> $output_file
53+
fi
54+
55+
exitCode=0
56+
while IFS= read -r line
57+
do
58+
echo "===> Terraform validate checking in $line"
59+
terraform -chdir=$line init -upgrade
60+
terraform -chdir=$line validate
61+
if [[ $? -ne 0 ]]; then
62+
echo -e "\033[31m[ERROR]\033[0m: Some codes contain errors, and please running terraform validate command before pushing."
63+
exitCode=1
64+
fi
65+
done < $output_file
66+
rm $output_file
67+
exit $exitCode
68+
69+
tflint:
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: checkout
73+
uses: actions/checkout@v3
74+
75+
- uses: actions/checkout@v4
76+
name: Checkout source code
77+
78+
- uses: actions/cache@v4
79+
name: Cache plugin dir
80+
with:
81+
path: ~/.tflint.d/plugins
82+
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
83+
84+
- uses: terraform-linters/setup-tflint@v4
85+
name: Setup TFLint
86+
with:
87+
tflint_version: v0.52.0
88+
89+
- name: Init TFLint
90+
run: tflint --init
91+
env:
92+
GITHUB_TOKEN: ${{ github.token }}
93+
94+
- name: tflint
95+
run: |
96+
tflint --recursive \
97+
--enable-rule=terraform_comment_syntax \
98+
--enable-rule=terraform_deprecated_index \
99+
--enable-rule=terraform_deprecated_interpolation \
100+
--enable-rule=terraform_deprecated_lookup \
101+
--enable-rule=terraform_documented_outputs \
102+
--enable-rule=terraform_documented_variables \
103+
--enable-rule=terraform_typed_variables \
104+
--enable-rule=terraform_unused_declarations \
105+
--enable-rule=terraform_required_version \
106+
--disable-rule=terraform_required_providers \
107+
--disable-rule=terraform_module_version
108+
if [[ $? -ne 0 ]]; then
109+
exit_code=1
110+
fi
111+
14112
e2e-check:
15113
# if: github.event.review.state == 'approved' || github.event.review.body == 'approved'
114+
needs: [terraform-fmt, terraform-validate, tflint]
16115
runs-on: ubuntu-latest
17116
name: 'e2e check'
18117
steps:

0 commit comments

Comments
 (0)