|
1 | 1 | # |
2 | | -# Copyright (C) 2024 Appvia Ltd <[email protected]> |
3 | | -# |
4 | 2 | # This program is free software; you can redistribute it and/or |
5 | 3 | # modify it under the terms of the GNU General Public License |
6 | 4 | # as published by the Free Software Foundation; either version 2 |
|
14 | 12 | # You should have received a copy of the GNU General Public License |
15 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 14 | # |
17 | | - |
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 |
20 | 16 |
|
21 | 17 | default: all |
22 | 18 |
|
23 | 19 | all: |
24 | 20 | $(MAKE) init |
25 | 21 | $(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 |
26 | 32 | $(MAKE) lint |
27 | 33 | $(MAKE) security |
28 | 34 | $(MAKE) format |
29 | 35 | $(MAKE) documentation |
30 | 36 |
|
31 | 37 | documentation: |
32 | 38 | @echo "--> Generating documentation" |
33 | | - @terraform-docs markdown table --output-file ${PWD}/README.md --output-mode inject . |
| 39 | + @terraform-docs . |
| 40 | + $(MAKE) documentation-modules |
34 | 41 | $(MAKE) documentation-examples |
35 | 42 |
|
| 43 | +documentation-modules: |
| 44 | + @echo "--> Generating documentation for modules" |
| 45 | + @find . -type d -regex '.*/modules/[a-za-z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ |
| 46 | + echo "--> Generating documentation for module: $$dir"; \ |
| 47 | + terraform-docs $$dir; \ |
| 48 | + done; |
| 49 | + |
36 | 50 | documentation-examples: |
37 | | - @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 | + @echo "--> Generating documentation for examples" |
| 52 | + @find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null| while read -r dir; do \ |
| 53 | + echo "--> Generating documentation for example: $$dir"; \ |
| 54 | + terraform-docs $$dir; \ |
| 55 | + done; |
| 56 | + |
| 57 | +upgrade-terraform-providers: |
| 58 | + @printf "%s Upgrading Terraform providers for %-24s" "-->" "." |
| 59 | + @terraform init -upgrade >/dev/null && echo "[OK]" || echo "[FAILED]" |
| 60 | + @$(MAKE) upgrade-terraform-example-providers |
| 61 | + |
| 62 | +upgrade-terraform-example-providers: |
| 63 | + @if [ -d examples ]; then \ |
| 64 | + find examples -type d -mindepth 1 -maxdepth 1 2>/dev/null | while read -r dir; do \ |
| 65 | + printf "%s Upgrading Terraform providers for %-24s" "-->" "$$dir"; \ |
| 66 | + terraform -chdir=$$dir init -upgrade >/dev/null && echo "[OK]" || echo "[FAILED]"; \ |
| 67 | + done; \ |
| 68 | + fi |
39 | 69 |
|
40 | 70 | init: |
41 | 71 | @echo "--> Running terraform init" |
42 | 72 | @terraform init -backend=false |
| 73 | + @find . -type f -name "*.tf" -not -path '*.terraform*' -exec dirname {} \; | sort -u | while read -r dir; do \ |
| 74 | + echo "--> Running terraform init in $$dir"; \ |
| 75 | + terraform -chdir=$$dir init -backend=false; \ |
| 76 | + done; |
43 | 77 |
|
44 | | -security: |
| 78 | +security: init |
45 | 79 | @echo "--> Running Security checks" |
46 | 80 | @trivy config . |
| 81 | + $(MAKE) security-modules |
47 | 82 | $(MAKE) security-examples |
48 | 83 |
|
| 84 | +security-modules: |
| 85 | + @echo "--> Running Security checks on modules" |
| 86 | + @find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ |
| 87 | + echo "--> Validating $$dir"; \ |
| 88 | + terraform init -backend=false; \ |
| 89 | + trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \ |
| 90 | + done; |
| 91 | + |
49 | 92 | security-examples: |
50 | 93 | @echo "--> Running Security checks on examples" |
51 | | - @find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ |
| 94 | + @find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ |
52 | 95 | echo "--> Validating $$dir"; \ |
53 | | - trivy config $$dir; \ |
54 | | - done |
| 96 | + terraform init -backend=false; \ |
| 97 | + trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \ |
| 98 | + done; |
55 | 99 |
|
56 | | -validate-all: |
57 | | - @echo "--> Running all validation checks" |
58 | | - $(MAKE) validate |
59 | | - $(MAKE) validate-examples |
| 100 | +tests: |
| 101 | + @echo "--> Running Terraform Tests" |
| 102 | + @terraform test |
60 | 103 |
|
61 | 104 | validate: |
62 | 105 | @echo "--> Running terraform validate" |
63 | 106 | @terraform init -backend=false |
64 | 107 | @terraform validate |
| 108 | + $(MAKE) validate-modules |
65 | 109 | $(MAKE) validate-examples |
| 110 | + $(MAKE) validate-commits |
| 111 | + |
| 112 | +validate-modules: |
| 113 | + @echo "--> Running terraform validate on modules" |
| 114 | + @find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ |
| 115 | + echo "--> Validating Module $$dir"; \ |
| 116 | + terraform -chdir=$$dir init -backend=false; \ |
| 117 | + terraform -chdir=$$dir validate; \ |
| 118 | + done; |
66 | 119 |
|
67 | 120 | validate-examples: |
68 | 121 | @echo "--> Running terraform validate on examples" |
69 | | - @find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ |
| 122 | + @find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ |
70 | 123 | echo "--> Validating $$dir"; \ |
71 | | - terraform -chdir=$$dir init; \ |
| 124 | + terraform -chdir=$$dir init -backend=false; \ |
72 | 125 | terraform -chdir=$$dir validate; \ |
73 | | - done |
| 126 | + done; |
| 127 | + |
| 128 | +validate-commits: |
| 129 | + @echo "--> Running commitlint against the main branch" |
| 130 | + @command -v commitlint >/dev/null 2>&1 || { echo "commitlint is not installed. Please install it by running 'npm install -g commitlint'"; exit 1; } |
| 131 | + @git log --pretty=format:"%s" origin/main..HEAD | commitlint --from=origin/main |
74 | 132 |
|
75 | 133 | lint: |
76 | 134 | @echo "--> Running tflint" |
77 | 135 | @tflint --init |
78 | 136 | @tflint -f compact |
| 137 | + $(MAKE) lint-modules |
79 | 138 | $(MAKE) lint-examples |
80 | 139 |
|
| 140 | +lint-modules: |
| 141 | + @echo "--> Running tflint on modules" |
| 142 | + @find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ |
| 143 | + echo "--> Linting $$dir"; \ |
| 144 | + tflint --chdir=$$dir --init; \ |
| 145 | + tflint --chdir=$$dir -f compact; \ |
| 146 | + done; |
| 147 | + |
81 | 148 | lint-examples: |
82 | 149 | @echo "--> Running tflint on examples" |
83 | | - @find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \ |
| 150 | + @find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \ |
84 | 151 | echo "--> Linting $$dir"; \ |
85 | 152 | tflint --chdir=$$dir --init; \ |
86 | 153 | tflint --chdir=$$dir -f compact; \ |
87 | | - done |
| 154 | + done; |
88 | 155 |
|
89 | 156 | format: |
90 | 157 | @echo "--> Running terraform fmt" |
91 | 158 | @terraform fmt -recursive -write=true |
92 | 159 |
|
93 | 160 | clean: |
94 | 161 | @echo "--> Cleaning up" |
95 | | - @find . -type d -name ".terraform" | while read -r dir; do \ |
| 162 | + @find . -type d -name ".terraform" 2>/dev/null | while read -r dir; do \ |
96 | 163 | echo "--> Removing $$dir"; \ |
97 | 164 | rm -rf $$dir; \ |
98 | 165 | done |
99 | | - |
100 | | -verify-rules: |
101 | | - @echo "Validating the Suricata rules" |
102 | | - $(MAKE) verify-duplicates |
103 | | - |
104 | | -verify-duplicates: |
105 | | - @echo "Validating the Suricata rules for duplicates" |
|
0 commit comments