Skip to content

Commit

Permalink
chore: bringing the module inline with the template
Browse files Browse the repository at this point in the history
  • Loading branch information
gambol99 committed Jan 10, 2025
1 parent b2b607c commit 27daab2
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 99 deletions.
19 changes: 19 additions & 0 deletions .commitlintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
rules:
body-leading-blank: [1, always]
body-max-line-length: [2, always, 100]
footer-leading-blank: [1, always]
footer-max-line-length: [2, always, 100]
header-max-length: [2, always, 100]
subject-case:
- 2
- never
- [sentence-case, start-case, pascal-case, upper-case]
subject-empty: [2, never]
subject-full-stop: [2, never, "."]
type-case: [2, always, lower-case]
type-empty: [2, never]
type-enum:
- 2
- always
- [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*.tfstate
*.tfstate.*

# terraform lock file
.terraform.lock.hcl

# Crash log files
crash.log
crash.*.log
Expand All @@ -30,3 +33,15 @@ terraform.rc
.DS_Store
todo.md

# Ignore vim swap files
*.swp
*.swo

# Ignore meld diff files
*.orig
*.backup
*.rej

# Ignore lambda zip files and build directories
*.zip
builds/
15 changes: 11 additions & 4 deletions .terraform-docs.yaml → .terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
formatter: markdown
#header-from: .header.md
settings:
anchor: true
Expand All @@ -12,10 +11,18 @@ settings:
type: true
lockfile: false

sort:
enabled: true
by: required
formatter: "markdown table"

output:
file: README.md
mode: inject

sections:
show:
- providers
- inputs
- outputs

sort:
enabled: true
by: required
25 changes: 0 additions & 25 deletions .terraform.lock.hcl

This file was deleted.

Empty file added .trivyignore
Empty file.
111 changes: 89 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#
# Copyright (C) 2024 Appvia Ltd <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
Expand All @@ -14,85 +12,154 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
AUTHOR_EMAIL[email protected]

.PHONY: all security lint format documentation documentation-examples validate-all validate validate-examples init
.PHONY: all security lint format documentation documentation-examples validate-all validate validate-examples init examples tests

default: all

all:
$(MAKE) init
$(MAKE) validate
$(MAKE) tests
$(MAKE) lint
$(MAKE) security
$(MAKE) format
$(MAKE) documentation

examples:
$(MAKE) validate-examples
$(MAKE) tests
$(MAKE) lint-examples
$(MAKE) lint
$(MAKE) security
$(MAKE) format
$(MAKE) documentation

documentation:
@echo "--> Generating documentation"
@terraform-docs markdown table --output-file ${PWD}/README.md --output-mode inject .
@terraform-docs .
$(MAKE) documentation-modules
$(MAKE) documentation-examples

documentation-modules:
@echo "--> Generating documentation for modules"
@find . -type d -regex '.*/modules/[a-za-z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
echo "--> Generating documentation for module: $$dir"; \
terraform-docs $$dir; \
done;

documentation-examples:
@echo "--> Generating documentation examples"
@find examples -type d -mindepth 1 -maxdepth 1 -exec terraform-docs markdown table --output-file README.md --output-mode inject {} \;
@echo "--> Generating documentation for examples"
@find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null| while read -r dir; do \
echo "--> Generating documentation for example: $$dir"; \
terraform-docs $$dir; \
done;

upgrade-terraform-providers:
@printf "%s Upgrading Terraform providers for %-24s" "-->" "."
@terraform init -upgrade >/dev/null && echo "[OK]" || echo "[FAILED]"
@$(MAKE) upgrade-terraform-example-providers

upgrade-terraform-example-providers:
@if [ -d examples ]; then \
find examples -type d -mindepth 1 -maxdepth 1 2>/dev/null | while read -r dir; do \
printf "%s Upgrading Terraform providers for %-24s" "-->" "$$dir"; \
terraform -chdir=$$dir init -upgrade >/dev/null && echo "[OK]" || echo "[FAILED]"; \
done; \
fi

init:
@echo "--> Running terraform init"
@terraform init -backend=false
@find . -type f -name "*.tf" -not -path '*.terraform*' -exec dirname {} \; | sort -u | while read -r dir; do \
echo "--> Running terraform init in $$dir"; \
terraform -chdir=$$dir init -backend=false; \
done;

security:
security: init
@echo "--> Running Security checks"
@trivy config .
$(MAKE) security-modules
$(MAKE) security-examples

security-modules:
@echo "--> Running Security checks on modules"
@find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
echo "--> Validating $$dir"; \
terraform init -backend=false; \
trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \
done;

security-examples:
@echo "--> Running Security checks on examples"
@find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
@find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
echo "--> Validating $$dir"; \
trivy config $$dir; \
done
terraform init -backend=false; \
trivy config --format table --exit-code 1 --severity CRITICAL,HIGH --ignorefile .trivyignore $$dir; \
done;

validate-all:
@echo "--> Running all validation checks"
$(MAKE) validate
$(MAKE) validate-examples
tests:
@echo "--> Running Terraform Tests"
@terraform test

validate:
@echo "--> Running terraform validate"
@terraform init -backend=false
@terraform validate
$(MAKE) validate-modules
$(MAKE) validate-examples
$(MAKE) validate-commits

validate-modules:
@echo "--> Running terraform validate on modules"
@find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
echo "--> Validating Module $$dir"; \
terraform -chdir=$$dir init -backend=false; \
terraform -chdir=$$dir validate; \
done;

validate-examples:
@echo "--> Running terraform validate on examples"
@find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
@find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
echo "--> Validating $$dir"; \
terraform -chdir=$$dir init; \
terraform -chdir=$$dir init -backend=false; \
terraform -chdir=$$dir validate; \
done
done;

validate-commits:
@echo "--> Running commitlint against the main branch"
@command -v commitlint >/dev/null 2>&1 || { echo "commitlint is not installed. Please install it by running 'npm install -g commitlint'"; exit 1; }
@git log --pretty=format:"%s" origin/main..HEAD | commitlint --from=origin/main

lint:
@echo "--> Running tflint"
@tflint --init
@tflint -f compact
$(MAKE) lint-modules
$(MAKE) lint-examples

lint-modules:
@echo "--> Running tflint on modules"
@find . -type d -regex '.*/modules/[a-zA-Z\-_$$]*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
echo "--> Linting $$dir"; \
tflint --chdir=$$dir --init; \
tflint --chdir=$$dir -f compact; \
done;

lint-examples:
@echo "--> Running tflint on examples"
@find examples -type d -mindepth 1 -maxdepth 1 | while read -r dir; do \
@find . -type d -path '*/examples/*' -not -path '*.terraform*' 2>/dev/null | while read -r dir; do \
echo "--> Linting $$dir"; \
tflint --chdir=$$dir --init; \
tflint --chdir=$$dir -f compact; \
done
done;

format:
@echo "--> Running terraform fmt"
@terraform fmt -recursive -write=true

clean:
@echo "--> Cleaning up"
@find . -type d -name ".terraform" | while read -r dir; do \
@find . -type d -name ".terraform" 2>/dev/null | while read -r dir; do \
echo "--> Removing $$dir"; \
rm -rf $$dir; \
done
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,12 @@ The `terraform-docs` utility is used to generate this README. Follow the below s
3. Run `terraform-docs markdown table --output-file ${PWD}/README.md --output-mode inject .`

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |

## Providers

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

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_parser"></a> [parser](#module\_parser) | ./modules/rules_parser | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_networkfirewall_rule_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/networkfirewall_rule_group) | resource |

## Inputs

| Name | Description | Type | Default | Required |
Expand Down
17 changes: 0 additions & 17 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0.0 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_rule_group"></a> [rule\_group](#module\_rule\_group) | ../../ | n/a |

## Resources

No resources.

## Inputs

No inputs.
Expand Down
13 changes: 13 additions & 0 deletions examples/basic/rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- BEGIN_TF_DOCS -->
## Providers

No providers.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END_TF_DOCS -->
12 changes: 0 additions & 12 deletions modules/rules_parser/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

No modules.

## Resources

No resources.

## Inputs

| Name | Description | Type | Default | Required |
Expand Down

0 comments on commit 27daab2

Please sign in to comment.