1
+ #! /bin/bash
2
+
3
+ # # NOTE: paths may differ when running in a managed task. To ensure behavior is consistent between
4
+ # managed and local tasks always use these variables for the project and project type path
5
+ PROJECT_PATH=${BASE_PATH} /project
6
+ PROJECT_TYPE_PATH=${BASE_PATH} /projecttype
7
+
8
+
9
+ echo " Starting Static Tests"
10
+
11
+ # ********** Terraform Validate *************
12
+ cd ${PROJECT_PATH}
13
+ terraform init
14
+ terraform validate
15
+ if [ $? -eq 0 ]
16
+ then
17
+ echo " Success - Terraform validate"
18
+ else
19
+ echo " Failure - Terraform validate"
20
+ exit 1
21
+ fi
22
+
23
+ # ********** tflint ********************
24
+ echo ' Starting tflint'
25
+ tflint --init --config ${PROJECT_PATH} /.config/.tflint.hcl
26
+ MYLINT=$( tflint --force --config ${PROJECT_PATH} /.config/.tflint.hcl)
27
+ if [ -z " $MYLINT " ]
28
+ then
29
+ echo " Success - tflint found no linting issues!"
30
+ else
31
+ echo " Failure - tflint found linting issues!"
32
+ echo " $MYLINT "
33
+ exit 1
34
+ fi
35
+
36
+ # ********** tfsec *********************
37
+ echo ' Starting tfsec'
38
+ MYTFSEC=$( tfsec . --config-file ${PROJECT_PATH} /.config/.tfsec.yml --custom-check-dir ${PROJECT_PATH} /.config/.tfsec)
39
+ if [[ $MYTFSEC == * " No problems detected!" * ]];
40
+ then
41
+ echo " Success - tfsec found no security issues!"
42
+ echo " $MYTFSEC "
43
+ else
44
+ echo " Failure - tfsec found security issues!"
45
+ echo " $MYTFSEC "
46
+ exit 1
47
+ fi
48
+
49
+ # ********** Checkov Analysis *************
50
+ echo " Running Checkov Analysis"
51
+ checkov --config-file ${PROJECT_PATH} /.config/.checkov.yml
52
+ if [ $? -eq 0 ]
53
+ then
54
+ echo " Success - Checkov found no issues!"
55
+ else
56
+ echo " Failure - Checkov found issues!"
57
+ exit 1
58
+ fi
59
+
60
+ # ********** Markdown Lint **************
61
+ echo ' Starting markdown lint'
62
+ MYMDL=$( mdl --config ${PROJECT_PATH} /.config/.mdlrc .header.md examples/* /.header.md)
63
+ if [ -z " $MYMDL " ]
64
+ then
65
+ echo " Success - markdown lint found no linting issues!"
66
+ else
67
+ echo " Failure - markdown lint found linting issues!"
68
+ echo " $MYMDL "
69
+ exit 1
70
+ fi
71
+
72
+ # ********** Terraform Docs *************
73
+ echo ' Starting terraform-docs'
74
+ TDOCS=" $( terraform-docs --config ${PROJECT_PATH} /.config/.terraform-docs.yaml --lockfile=false ./) "
75
+ git add -N README.md
76
+ GDIFF=" $( git diff --compact-summary) "
77
+ if [ -z " $GDIFF " ]
78
+ then
79
+ echo " Success - Terraform Docs creation verified!"
80
+ else
81
+ echo " Failure - Terraform Docs creation failed, ensure you have precommit installed and running before submitting the Pull Request. TIPS: false error may occur if you have unstaged files in your repo"
82
+ echo " $GDIFF "
83
+ exit 1
84
+ fi
85
+
86
+ # ***************************************
87
+ echo " End of Static Tests"
0 commit comments