11#
2- # Copyright (C) 2024 Appvia Ltd <info@appvia.io>
3- #
42# This program is free software; you can redistribute it and/or
53# modify it under the terms of the GNU General Public License
64# as published by the Free Software Foundation; either version 2
1412# You should have received a copy of the GNU General Public License
1513# along with this program. If not, see <http://www.gnu.org/licenses/>.
1614#
17- AUTHOR_EMAIL =info@appvia.io
18-
19- .PHONY : all security lint format documentation documentation-examples validate-all validate validate-examples init
15+ .PHONY : all security lint format documentation documentation-examples validate-all validate validate-examples init examples tests
2016
2117default : all
2218
2319all :
2420 $(MAKE ) init
2521 $(MAKE ) validate
22+ $(MAKE ) tests
23+ $(MAKE ) lint
24+ $(MAKE ) security
25+ $(MAKE ) format
26+ $(MAKE ) documentation
27+
28+ examples :
29+ $(MAKE ) validate-examples
30+ $(MAKE ) tests
31+ $(MAKE ) lint-examples
2632 $(MAKE ) lint
2733 $(MAKE ) security
2834 $(MAKE ) format
3137documentation :
3238 @echo " --> Generating documentation"
3339 @terraform-docs markdown table --output-file ${PWD} /README.md --output-mode inject .
40+ $(MAKE ) documentation-modules
3441 $(MAKE ) documentation-examples
3542
43+ documentation-modules :
44+ @echo " --> Generating documentation for modules"
45+ @if [ -d modules ]; then \
46+ find modules -type d -mindepth 1 -maxdepth 1 -exec terraform-docs markdown table --output-file README.md --output-mode inject {} \; ; \
47+ fi
48+
3649documentation-examples :
3750 @echo " --> Generating documentation examples"
38- @find examples -type d -mindepth 1 -maxdepth 1 -exec terraform-docs markdown table --output-file README.md --output-mode inject {} \;
51+ @if [ -d examples ]; then \
52+ find examples -type d -mindepth 1 -maxdepth 1 -exec terraform-docs markdown table --output-file README.md --output-mode inject {} \; ; \
53+ fi
54+
55+ upgrade-terraform-providers :
56+ @printf " %s Upgrading Terraform providers for %-24s" " -->" " ."
57+ @terraform init -upgrade > /dev/null && echo " [OK]" || echo " [FAILED]"
58+ @$(MAKE ) upgrade-terraform-example-providers
59+
60+ upgrade-terraform-example-providers :
61+ @if [ -d examples ]; then \
62+ find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
63+ printf " %s Upgrading Terraform providers for %-24s" " -->" " $$ dir" ; \
64+ terraform -chdir=$$ dir init -upgrade > /dev/null && echo " [OK]" || echo " [FAILED]" ; \
65+ done ; \
66+ fi
3967
4068init :
4169 @echo " --> Running terraform init"
@@ -44,47 +72,87 @@ init:
4472security :
4573 @echo " --> Running Security checks"
4674 @trivy config .
75+ $(MAKE ) security-modules
4776 $(MAKE ) security-examples
4877
78+ security-modules :
79+ @echo " --> Running Security checks on modules"
80+ @if [ -d modules ]; then \
81+ find modules -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
82+ echo " --> Validating $$ dir" ; \
83+ trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$ dir; \
84+ done ; \
85+ fi
86+
4987security-examples :
5088 @echo " --> Running Security checks on examples"
51- @find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
52- echo " --> Validating $$ dir" ; \
53- trivy config $$ dir; \
54- done
89+ @if [ -d examples ]; then \
90+ find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
91+ echo " --> Validating $$ dir" ; \
92+ trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$ dir; \
93+ done ; \
94+ fi
5595
56- validate-all :
57- @echo " --> Running all validation checks"
58- $(MAKE ) validate
59- $(MAKE ) validate-examples
96+ tests :
97+ @echo " --> Running Terraform Tests"
98+ @terraform test
6099
61100validate :
62101 @echo " --> Running terraform validate"
63102 @terraform init -backend=false
64103 @terraform validate
104+ $(MAKE ) validate-modules
65105 $(MAKE ) validate-examples
66106
107+ validate-modules :
108+ @echo " --> Running terraform validate on modules"
109+ @if [ -d modules ]; then \
110+ find modules -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
111+ echo " --> Validating $$ dir" ; \
112+ terraform -chdir=$$ dir init -backend=false; \
113+ terraform -chdir=$$ dir validate; \
114+ done ; \
115+ fi
116+
67117validate-examples :
68118 @echo " --> Running terraform validate on examples"
69- @find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
70- echo " --> Validating $$ dir" ; \
71- terraform -chdir=$$ dir init; \
72- terraform -chdir=$$ dir validate; \
73- done
119+ @if [ -d examples ]; then \
120+ find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
121+ echo " --> Validating $$ dir" ; \
122+ terraform -chdir=$$ dir init -backend=false; \
123+ terraform -chdir=$$ dir validate; \
124+ done ; \
125+ fi
126+
127+ validate-commits :
128+ @echo " --> Running commitlint against the "
74129
75130lint :
76131 @echo " --> Running tflint"
77132 @tflint --init
78133 @tflint -f compact
134+ $(MAKE ) lint-modules
79135 $(MAKE ) lint-examples
80136
137+ lint-modules :
138+ @echo " --> Running tflint on modules"
139+ @if [ -d modules ]; then \
140+ find modules -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
141+ echo " --> Linting $$ dir" ; \
142+ tflint --chdir=$$ dir --init; \
143+ tflint --chdir=$$ dir -f compact; \
144+ done ; \
145+ fi
146+
81147lint-examples :
82148 @echo " --> Running tflint on examples"
83- @find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
84- echo " --> Linting $$ dir" ; \
85- tflint --chdir=$$ dir --init; \
86- tflint --chdir=$$ dir -f compact; \
87- done
149+ @if [ -d examples ]; then \
150+ find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
151+ echo " --> Linting $$ dir" ; \
152+ tflint --chdir=$$ dir --init; \
153+ tflint --chdir=$$ dir -f compact; \
154+ done ; \
155+ fi
88156
89157format :
90158 @echo " --> Running terraform fmt"
0 commit comments