Skip to content

Commit 4cd062b

Browse files
Merge pull request #1 from umotif-public/feat/git-hooks
add git hooks and update docs
2 parents e931cfa + fe0f26d commit 4cd062b

File tree

3 files changed

+57
-39
lines changed

3 files changed

+57
-39
lines changed

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.5.0
4+
hooks:
5+
- id: check-added-large-files
6+
args: ['--maxkb=500']
7+
- id: check-executables-have-shebangs
8+
- id: pretty-format-json
9+
args: ['--autofix', '--no-sort-keys', '--indent=2']
10+
- id: check-byte-order-marker
11+
- id: check-case-conflict
12+
- id: check-executables-have-shebangs
13+
- id: check-merge-conflict
14+
- id: check-symlinks
15+
- id: detect-private-key
16+
- id: check-merge-conflict
17+
- id: detect-aws-credentials
18+
args: ['--allow-missing-credentials']
19+
- id: trailing-whitespace
20+
- repo: git://github.com/antonbabenko/pre-commit-terraform
21+
rev: v1.25.0
22+
hooks:
23+
- id: terraform_fmt
24+
- id: terraform_docs
25+
- id: terraform_tflint

Makefile

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,15 @@ ifneq (,)
22
.error This Makefile requires GNU Make.
33
endif
44

5-
.PHONY: gen _gen-main _update-tf-docs
5+
.PHONY: hooks validate
66

7-
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
8-
TF_EXAMPLES = $(sort $(dir $(wildcard $(CURRENT_DIR)examples/*/)))
9-
TF_DOCS_VERSION = 0.6.0
7+
help:
8+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
109

11-
# Adjust your delimiter here or overwrite via make arguments
12-
DELIM_START = <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
13-
DELIM_CLOSE = <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
10+
hooks: ## Commit hooks setup
11+
@pre-commit install
12+
@pre-commit gc
13+
@pre-commit autoupdate
1414

15-
gen: _update-tf-docs
16-
@echo "################################################################################"
17-
@echo "# Terraform-docs generate"
18-
@echo "################################################################################"
19-
@$(MAKE) --no-print-directory _gen-main
20-
21-
_gen-main:
22-
@echo "------------------------------------------------------------"
23-
@echo "# Main module"
24-
@echo "------------------------------------------------------------"
25-
@if docker run --rm \
26-
-v $(CURRENT_DIR):/data \
27-
-e DELIM_START='$(DELIM_START)' \
28-
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
29-
cytopia/terraform-docs:$(TF_DOCS_VERSION) \
30-
terraform-docs-replace-012 --sort-inputs-by-required --with-aggregate-type-defaults md README.md; then \
31-
echo "OK"; \
32-
else \
33-
echo "Failed"; \
34-
exit 1; \
35-
fi
36-
37-
_update-tf-docs:
38-
docker pull cytopia/terraform-docs:$(TF_DOCS_VERSION)
15+
validate: ## Validate files with pre-commit hooks
16+
@pre-commit run --all-files

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Terraform 0.12. Pin module version to `~> v1.0`. Submit pull-requests to `master
1919
module "alb" {
2020
source = "umotif-public/alb/aws"
2121
version = "~> 1.0"
22-
22+
2323
name_prefix = "complete-alb"
2424
2525
load_balancer_type = "application"
@@ -80,25 +80,25 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
8080

8181
| Name | Description | Type | Default | Required |
8282
|------|-------------|:----:|:-----:|:-----:|
83-
| name\_prefix | A prefix used for naming resources. | string | n/a | yes |
84-
| subnets | A list of subnet IDs to attach to the LB. | list(string) | n/a | yes |
85-
| vpc\_id | The VPC ID. | string | n/a | yes |
8683
| access\_logs | An Access Logs block. | map(string) | `{}` | no |
8784
| cidr\_blocks\_redirect | List of CIDR ranges to allow at security group level. Defaults to 0.0.0.0/0 | list(string) | `[ "0.0.0.0/0" ]` | no |
8885
| description | The description of the all resources. | string | `"Managed by Terraform"` | no |
8986
| enable\_cross\_zone\_load\_balancing | If true, cross-zone load balancing of the load balancer will be enabled. This is a network load balancer feature. | bool | `"false"` | no |
9087
| enable\_deletion\_protection | If true, deletion of the load balancer will be disabled via the AWS API. This will prevent Terraform from deleting the load balancer. | bool | `"false"` | no |
9188
| enable\_http2 | Indicates whether HTTP/2 is enabled in application load balancers. | bool | `"true"` | no |
9289
| enable\_http\_to\_https\_redirect | Enable default redirect rule from port 80 to 443. | bool | `"false"` | no |
93-
| idle\_timeout | (Optional) The time in seconds that the connection is allowed to be idle. Only valid for Load Balancers of type application. | number | `"60"` | no |
90+
| idle\_timeout | \(Optional\) The time in seconds that the connection is allowed to be idle. Only valid for Load Balancers of type application. | number | `"60"` | no |
9491
| internal | Provision an internal load balancer. Defaults to false. | bool | `"false"` | no |
9592
| ip\_address\_type | The type of IP addresses used by the subnets for your load balancer. The possible values are ipv4 and dualstack. | string | `"ipv4"` | no |
9693
| load\_balancer\_create\_timeout | Timeout value when creating the ALB. | string | `"15m"` | no |
9794
| load\_balancer\_delete\_timeout | Timeout value when deleting the ALB. | string | `"15m"` | no |
98-
| load\_balancer\_type | Type of load balancer to provision (network or application). | string | `"application"` | no |
95+
| load\_balancer\_type | Type of load balancer to provision \(network or application\). | string | `"application"` | no |
9996
| load\_balancer\_update\_timeout | Timeout value when updating the ALB. | string | `"15m"` | no |
97+
| name\_prefix | A prefix used for naming resources. | string | n/a | yes |
10098
| subnet\_mapping | A list of subnet mapping blocks describing subnets to attach to network load balancer | list(map(string)) | `[]` | no |
101-
| tags | A map of tags (key-value pairs) passed to resources. | map(string) | `{}` | no |
99+
| subnets | A list of subnet IDs to attach to the LB. | list(string) | n/a | yes |
100+
| tags | A map of tags \(key-value pairs\) passed to resources. | map(string) | `{}` | no |
101+
| vpc\_id | The VPC ID. | string | n/a | yes |
102102

103103
## Outputs
104104

@@ -110,10 +110,25 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
110110
| name | The name of the load balancer. |
111111
| origin\_id | First part of the DNS name of the load balancer. |
112112
| security\_group\_id | The ID of the security group. |
113-
| zone\_id | The canonical hosted zone ID of the load balancer (to be used in a Route 53 Alias record). |
113+
| zone\_id | The canonical hosted zone ID of the load balancer \(to be used in a Route 53 Alias record\). |
114114

115115
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
116116

117117
## License
118118

119119
See LICENSE for full details.
120+
121+
## Pre-commit hooks
122+
123+
### Install dependencies
124+
125+
* [`pre-commit`](https://pre-commit.com/#install)
126+
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks.
127+
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.
128+
129+
#### MacOS
130+
131+
```bash
132+
brew install pre-commit terraform-docs tflint
133+
```
134+

0 commit comments

Comments
 (0)