@@ -14,28 +14,22 @@ jobs:
14
14
terraform-fmt :
15
15
runs-on : ubuntu-latest
16
16
steps :
17
- - name : checkout
18
- uses : actions/checkout@v3
19
- - name : terraform-fmt
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 in quickstarts"
27
- (terraform -chdir=quickstarts fmt -check -recursive -list=false) || error=true
28
- terraform -chdir=quickstarts fmt -diff -recursive
29
- if ${error}; then
30
- echo -e "\033[31m[ERROR]\033[0m: Some quickstarts codes has not been formatted, and please running terraform fmt --recursive command before pushing."
31
- exit 1
32
- fi
17
+ - uses : actions/checkout@v4
18
+
19
+ - uses : hashicorp/setup-terraform@v3
20
+
21
+ - name : Terraform fmt
22
+ id : fmt
23
+ run : terraform -chdir=quickstarts fmt -check -recursive
24
+
33
25
34
26
terraform-validate :
35
27
runs-on : ubuntu-latest
36
28
steps :
37
- - name : checkout
38
- uses : actions/checkout@v3
29
+ - uses : actions/checkout@v4
30
+
31
+ - uses : hashicorp/setup-terraform@v3
32
+
39
33
- name : Get changed files
40
34
id : changed-files
41
35
uses : tj-actions/changed-files@v34
@@ -46,19 +40,24 @@ jobs:
46
40
dir_names_max_depth : 3
47
41
- name : pr-check
48
42
run : |
49
- if [ ! -f /usr/local/bin/terraform ]; then
50
- wget -q https://releases.hashicorp.com/terraform/1.6.0/terraform_1.6.0_linux_amd64.zip
51
- unzip terraform_1.6.0_linux_amd64.zip -d /usr/local/bin/
52
- fi
53
43
CHANGED_FOLDERS="${{ steps.changed-files.outputs.all_changed_files }}"
54
- if [ -z "${{ github.event.number }}" ]; then
55
- CHANGED_FOLDERS=$(find ./quickstarts -maxdepth 2 -mindepth 2 -type d | tr '\n' ',')
56
- fi
57
44
if [ -z "$CHANGED_FOLDERS" ]; then
58
45
echo "No changed quickstarts found"
59
46
exit 0
60
47
fi
61
- bash scripts/terraform-validate.sh ${CHANGED_FOLDERS}
48
+
49
+ error=false
50
+ for f in ${CHANGED_FOLDERS//,/ }
51
+ do
52
+ f=$(echo $f | xargs echo -n)
53
+ echo "===> Terraform validating in" $f
54
+ terraform -chdir=$f init -upgrade
55
+ terraform -chdir=$f validate
56
+ if [[ $? -ne 0 ]]; then
57
+ echo -e "\033[31m[ERROR]\033[0m: Some quickstarts codes contain errors, and please running terraform validate command before pushing."
58
+ exit 1
59
+ fi
60
+ done
62
61
63
62
64
63
e2e-check :
0 commit comments