Skip to content

Commit 27daab2

Browse files
committed
chore: bringing the module inline with the template
1 parent b2b607c commit 27daab2

File tree

10 files changed

+147
-99
lines changed

10 files changed

+147
-99
lines changed

.commitlintrc.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
rules:
3+
body-leading-blank: [1, always]
4+
body-max-line-length: [2, always, 100]
5+
footer-leading-blank: [1, always]
6+
footer-max-line-length: [2, always, 100]
7+
header-max-length: [2, always, 100]
8+
subject-case:
9+
- 2
10+
- never
11+
- [sentence-case, start-case, pascal-case, upper-case]
12+
subject-empty: [2, never]
13+
subject-full-stop: [2, never, "."]
14+
type-case: [2, always, lower-case]
15+
type-empty: [2, never]
16+
type-enum:
17+
- 2
18+
- always
19+
- [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*.tfstate
66
*.tfstate.*
77

8+
# terraform lock file
9+
.terraform.lock.hcl
10+
811
# Crash log files
912
crash.log
1013
crash.*.log
@@ -30,3 +33,15 @@ terraform.rc
3033
.DS_Store
3134
todo.md
3235

36+
# Ignore vim swap files
37+
*.swp
38+
*.swo
39+
40+
# Ignore meld diff files
41+
*.orig
42+
*.backup
43+
*.rej
44+
45+
# Ignore lambda zip files and build directories
46+
*.zip
47+
builds/

.terraform-docs.yaml .terraform-docs.yml

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
formatter: markdown
21
#header-from: .header.md
32
settings:
43
anchor: true
@@ -12,10 +11,18 @@ settings:
1211
type: true
1312
lockfile: false
1413

15-
sort:
16-
enabled: true
17-
by: required
14+
formatter: "markdown table"
1815

1916
output:
2017
file: README.md
2118
mode: inject
19+
20+
sections:
21+
show:
22+
- providers
23+
- inputs
24+
- outputs
25+
26+
sort:
27+
enabled: true
28+
by: required

.terraform.lock.hcl

-25
This file was deleted.

.trivyignore

Whitespace-only changes.

Makefile

+89-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#
2-
# Copyright (C) 2024 Appvia Ltd <[email protected]>
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
@@ -14,85 +12,154 @@
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[email protected]
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

2117
default: all
2218

2319
all:
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
2935
$(MAKE) documentation
3036

3137
documentation:
3238
@echo "--> Generating documentation"
33-
@terraform-docs markdown table --output-file ${PWD}/README.md --output-mode inject .
39+
@terraform-docs .
40+
$(MAKE) documentation-modules
3441
$(MAKE) documentation-examples
3542

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+
3650
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
3969

4070
init:
4171
@echo "--> Running terraform init"
4272
@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;
4377

44-
security:
78+
security: init
4579
@echo "--> Running Security checks"
4680
@trivy config .
81+
$(MAKE) security-modules
4782
$(MAKE) security-examples
4883

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+
4992
security-examples:
5093
@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 \
5295
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;
5599

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
60103

61104
validate:
62105
@echo "--> Running terraform validate"
63106
@terraform init -backend=false
64107
@terraform validate
108+
$(MAKE) validate-modules
65109
$(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;
66119

67120
validate-examples:
68121
@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 \
70123
echo "--> Validating $$dir"; \
71-
terraform -chdir=$$dir init; \
124+
terraform -chdir=$$dir init -backend=false; \
72125
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
74132

75133
lint:
76134
@echo "--> Running tflint"
77135
@tflint --init
78136
@tflint -f compact
137+
$(MAKE) lint-modules
79138
$(MAKE) lint-examples
80139

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+
81148
lint-examples:
82149
@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 \
84151
echo "--> Linting $$dir"; \
85152
tflint --chdir=$$dir --init; \
86153
tflint --chdir=$$dir -f compact; \
87-
done
154+
done;
88155

89156
format:
90157
@echo "--> Running terraform fmt"
91158
@terraform fmt -recursive -write=true
92159

93160
clean:
94161
@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 \
96163
echo "--> Removing $$dir"; \
97164
rm -rf $$dir; \
98165
done

README.md

-19
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,12 @@ The `terraform-docs` utility is used to generate this README. Follow the below s
5252
3. Run `terraform-docs markdown table --output-file ${PWD}/README.md --output-mode inject .`
5353

5454
<!-- BEGIN_TF_DOCS -->
55-
## Requirements
56-
57-
| Name | Version |
58-
|------|---------|
59-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.7 |
60-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |
61-
6255
## Providers
6356

6457
| Name | Version |
6558
|------|---------|
6659
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0.0 |
6760

68-
## Modules
69-
70-
| Name | Source | Version |
71-
|------|--------|---------|
72-
| <a name="module_parser"></a> [parser](#module\_parser) | ./modules/rules_parser | n/a |
73-
74-
## Resources
75-
76-
| Name | Type |
77-
|------|------|
78-
| [aws_networkfirewall_rule_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/networkfirewall_rule_group) | resource |
79-
8061
## Inputs
8162

8263
| Name | Description | Type | Default | Required |

examples/basic/README.md

-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
<!-- BEGIN_TF_DOCS -->
2-
## Requirements
3-
4-
| Name | Version |
5-
|------|---------|
6-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
7-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |
8-
92
## Providers
103

114
No providers.
125

13-
## Modules
14-
15-
| Name | Source | Version |
16-
|------|--------|---------|
17-
| <a name="module_rule_group"></a> [rule\_group](#module\_rule\_group) | ../../ | n/a |
18-
19-
## Resources
20-
21-
No resources.
22-
236
## Inputs
247

258
No inputs.

examples/basic/rules/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
## Providers
3+
4+
No providers.
5+
6+
## Inputs
7+
8+
No inputs.
9+
10+
## Outputs
11+
12+
No outputs.
13+
<!-- END_TF_DOCS -->

modules/rules_parser/README.md

-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
<!-- BEGIN_TF_DOCS -->
2-
## Requirements
3-
4-
No requirements.
5-
62
## Providers
73

84
No providers.
95

10-
## Modules
11-
12-
No modules.
13-
14-
## Resources
15-
16-
No resources.
17-
186
## Inputs
197

208
| Name | Description | Type | Default | Required |

0 commit comments

Comments
 (0)