-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.sh
More file actions
100 lines (78 loc) · 2.1 KB
/
pipe.sh
File metadata and controls
100 lines (78 loc) · 2.1 KB
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
#!/usr/bin/env bash
set -e
source "$(dirname "$0")/common.sh"
# Required parameters
TF_MODULE_PATH=${TF_MODULE_PATH:?"TF_MODULE_PATH env variable is required"}
# Default values
DEBUG=${DEBUG:="false"}
RUN_TFLINT=${RUN_TFLINT:="true"}
RUN_TRIVY=${RUN_TRIVY:="true"}
RUN_VALIDATE=${RUN_VALIDATE:="true"}
RUN_FMT=${RUN_FMT:="true"}
RUN_DOCS=${RUN_DOCS:="true"}
enable_debug() {
if [[ "${DEBUG}" == "true" ]]; then
info "Enabling debug mode."
set -x
fi
}
enable_debug
info "Running module tests for ${TF_MODULE_PATH}"
TERRAFORM_DOCS_CONFIG_OPTS=""
if [[ -f .terraform-docs.yml ]]; then
info "Found repo .terraform-docs.yml file, using it for terraform-docs configuration"
TERRAFORM_DOCS_CONFIG_OPTS="--config $(pwd)/.terraform-docs.yml"
fi
cd ${TF_MODULE_PATH}
if [[ -f .terraform-docs.yml ]]; then
info "Found module .terraform-docs.yml file, using it for terraform-docs configuration"
TERRAFORM_DOCS_CONFIG_OPTS="--config $(pwd)/.terraform-docs.yml"
fi
terraform init
if [[ "${RUN_FMT}" == "true" ]]; then
info "Checking module formatting"
run terraform fmt -check -diff
if [[ "${status}" == "0" ]]; then
success "Success!"
else
fail "Error!"
fi
fi
if [[ "${RUN_VALIDATE}" == "true" ]]; then
info "Checking module validation"
run terraform validate
if [[ "${status}" == "0" ]]; then
success "Success!"
else
fail "Error!"
fi
fi
if [[ "${RUN_TFLINT}" == "true" ]]; then
info "Checking module linting"
run tflint
if [[ "${status}" == "0" ]]; then
success "Success!"
else
fail "Error!"
fi
fi
if [[ "${RUN_TRIVY}" == "true" ]]; then
info "Checking module vulnerabilities"
run trivy config .
if [[ "${status}" == "0" ]]; then
success "Success!"
else
fail "Error!"
fi
fi
if [[ "${RUN_DOCS}" == "true" ]]; then
info "Checking module documentation"
touch README.md && cp README.md README.md.new
run terraform-docs markdown table ${TERRAFORM_DOCS_CONFIG_OPTS} --output-file README.md.new . && diff -bw README.md README.md.new
if [[ "${status}" == "0" ]]; then
success "Success!"
else
fail "Error!"
fi
rm -f README.md.new
fi