Skip to content

Commit a9d4591

Browse files
committed
add git hooks and update docs
1 parent 6631bb2 commit a9d4591

File tree

4 files changed

+65
-117
lines changed

4 files changed

+65
-117
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 & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,15 @@ ifneq (,)
22
.error This Makefile requires GNU Make.
33
endif
44

5-
.PHONY: gen _gen-main _gen-examples _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-
@$(MAKE) --no-print-directory _gen-examples
21-
22-
_gen-main:
23-
@echo "------------------------------------------------------------"
24-
@echo "# Main module"
25-
@echo "------------------------------------------------------------"
26-
@if docker run --rm \
27-
-v $(CURRENT_DIR):/data \
28-
-e DELIM_START='$(DELIM_START)' \
29-
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
30-
cytopia/terraform-docs:$(TF_DOCS_VERSION) \
31-
terraform-docs-replace-012 --sort-inputs-by-required --with-aggregate-type-defaults md README.md; then \
32-
echo "OK"; \
33-
else \
34-
echo "Failed"; \
35-
exit 1; \
36-
fi
37-
38-
_gen-examples:
39-
@$(foreach example,\
40-
$(TF_EXAMPLES),\
41-
DOCKER_PATH="examples/$(notdir $(patsubst %/,%,$(example)))"; \
42-
echo "------------------------------------------------------------"; \
43-
echo "# $${DOCKER_PATH}"; \
44-
echo "------------------------------------------------------------"; \
45-
if docker run --rm \
46-
-v $(CURRENT_DIR):/data \
47-
-e DELIM_START='$(DELIM_START)' \
48-
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
49-
cytopia/terraform-docs:$(TF_DOCS_VERSION) \
50-
terraform-docs-replace-012 --sort-inputs-by-required --with-aggregate-type-defaults md $${DOCKER_PATH}/README.md; then \
51-
echo "OK"; \
52-
else \
53-
echo "Failed"; \
54-
exit 1; \
55-
fi; \
56-
)
57-
58-
_update-tf-docs:
59-
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: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,36 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
4040

4141
| Name | Description | Type | Default | Required |
4242
|------|-------------|:----:|:-----:|:-----:|
43-
| name\_prefix | The replication group identifier. This parameter is stored as a lowercase string. | string | n/a | yes |
44-
| node\_type | The compute and memory capacity of the nodes in the node group. | string | n/a | yes |
45-
| number\_cache\_clusters | The number of cache clusters (primary and replicas) this replication group will have. | number | n/a | yes |
46-
| subnet\_ids | List of VPC Subnet IDs for the cache subnet group. | list(string) | n/a | yes |
47-
| vpc\_id | VPC Id to associate with Redis ElastiCache. | string | n/a | yes |
48-
| apply\_immediately | Specifies whether any modifications are applied immediately, or during the next maintenance window. | bool | `false` | no |
49-
| at\_rest\_encryption\_enabled | Whether to enable encryption at rest. | bool | `true` | no |
50-
| auth\_token | The password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true`. | string | `""` | no |
43+
| apply\_immediately | Specifies whether any modifications are applied immediately, or during the next maintenance window. | bool | `"false"` | no |
44+
| at\_rest\_encryption\_enabled | Whether to enable encryption at rest. | bool | `"true"` | no |
45+
| auth\_token | The password used to access a password protected server. Can be specified only if `transit\_encryption\_enabled = true`. | string | `""` | no |
5146
| auto\_minor\_version\_upgrade | | string | `"true"` | no |
52-
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | bool | `true` | no |
47+
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | bool | `"true"` | no |
5348
| description | The description of the all resources. | string | `"Managed by Terraform"` | no |
5449
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | string | `"5.0.6"` | no |
5550
| family | The family of the ElastiCache parameter group. | string | `"redis5.0"` | no |
5651
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | list(string) | `[]` | no |
57-
| kms\_key\_id | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at_rest_encryption_enabled = true` | string | `""` | no |
52+
| kms\_key\_id | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at\_rest\_encryption\_enabled = true` | string | `""` | no |
5853
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | string | `""` | no |
59-
| notification\_topic\_arn | An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic` | string | `""` | no |
54+
| name\_prefix | The replication group identifier. This parameter is stored as a lowercase string. | string | n/a | yes |
55+
| node\_type | The compute and memory capacity of the nodes in the node group. | string | n/a | yes |
56+
| notification\_topic\_arn | An Amazon Resource Name \(ARN\) of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my\_sns\_topic` | string | `""` | no |
57+
| number\_cache\_clusters | The number of cache clusters \(primary and replicas\) this replication group will have. | number | n/a | yes |
6058
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | object | `[]` | no |
61-
| port | The port number on which each of the cache nodes will accept connections. | number | `6379` | no |
59+
| port | The port number on which each of the cache nodes will accept connections. | number | `"6379"` | no |
6260
| security\_group\_ids | List of Security Groups. | list(string) | `[]` | no |
63-
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | number | `30` | no |
64-
| snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | string | `""` | no |
61+
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | number | `"30"` | no |
62+
| snapshot\_window | The daily time range \(in UTC\) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | string | `""` | no |
63+
| subnet\_ids | List of VPC Subnet IDs for the cache subnet group. | list(string) | n/a | yes |
6564
| tags | A mapping of tags to assign to all resources. | map(string) | `{}` | no |
66-
| transit\_encryption\_enabled | Whether to enable encryption in transit. | bool | `true` | no |
65+
| transit\_encryption\_enabled | Whether to enable encryption in transit. | bool | `"true"` | no |
66+
| vpc\_id | VPC Id to associate with Redis ElastiCache. | string | n/a | yes |
6767

6868
## Outputs
6969

7070
| Name | Description |
7171
|------|-------------|
72+
| elasticache\_auth\_token | The Redis Auth Token |
7273
| elasticache\_parameter\_group\_id | The ElastiCache parameter group name. |
7374
| elasticache\_replication\_group\_id | The ID of the ElastiCache Replication Group. |
7475
| elasticache\_replication\_group\_member\_clusters | The identifiers of all the nodes that are part of this replication group. |
@@ -87,3 +88,17 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](http
8788
## License
8889

8990
See LICENSE for full details.
91+
92+
## Pre-commit hooks
93+
94+
### Install dependencies
95+
96+
* [`pre-commit`](https://pre-commit.com/#install)
97+
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks.
98+
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.
99+
100+
#### MacOS
101+
102+
```bash
103+
brew install pre-commit terraform-docs tflint
104+
```

examples/core/README.md

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,4 @@ terraform init
55
terraform validate
66
terraform plan
77
terraform apply --auto-approve
8-
```
9-
10-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
11-
## Inputs
12-
13-
| Name | Description | Type | Default | Required |
14-
|------|-------------|:----:|:-----:|:-----:|
15-
| name\_prefix | The replication group identifier. This parameter is stored as a lowercase string. | string | n/a | yes |
16-
| node\_type | The compute and memory capacity of the nodes in the node group. | string | n/a | yes |
17-
| number\_cache\_clusters | The number of cache clusters (primary and replicas) this replication group will have. | string | n/a | yes |
18-
| subnet\_ids | List of VPC Subnet IDs for the cache subnet group. | list(string) | n/a | yes |
19-
| vpc\_id | VPC Id to associate with Redis ElastiCache. | string | n/a | yes |
20-
| apply\_immediately | Specifies whether any modifications are applied immediately, or during the next maintenance window. | string | `"false"` | no |
21-
| at\_rest\_encryption\_enabled | Whether to enable encryption at rest. | string | `"true"` | no |
22-
| auth\_token | The password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true`. | string | `""` | no |
23-
| auto\_minor\_version\_upgrade | | string | `"true"` | no |
24-
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | string | `"true"` | no |
25-
| description | The description of the all resources. | string | `"Managed by Terraform"` | no |
26-
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | string | `"5.0.6"` | no |
27-
| family | The family of the ElastiCache parameter group. | string | `"redis5.0"` | no |
28-
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | list(string) | `[]` | no |
29-
| kms\_key\_id | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at_rest_encryption_enabled = true` | string | `""` | no |
30-
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | string | `""` | no |
31-
| notification\_topic\_arn | An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: `arn:aws:sns:us-east-1:012345678999:my_sns_topic` | string | `""` | no |
32-
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | object | `[]` | no |
33-
| port | The port number on which each of the cache nodes will accept connections. | string | `"6379"` | no |
34-
| security\_group\_ids | List of Security Groups. | list(string) | `[]` | no |
35-
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | string | `"30"` | no |
36-
| snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | string | `""` | no |
37-
| tags | A mapping of tags to assign to all resources. | map(string) | `{}` | no |
38-
| transit\_encryption\_enabled | Whether to enable encryption in transit. | string | `"true"` | no |
39-
40-
## Outputs
41-
42-
| Name | Description |
43-
|------|-------------|
44-
| elasticache\_parameter\_group\_id | The ElastiCache parameter group name. |
45-
| elasticache\_replication\_group\_id | The ID of the ElastiCache Replication Group. |
46-
| elasticache\_replication\_group\_member\_clusters | The identifiers of all the nodes that are part of this replication group. |
47-
| elasticache\_replication\_group\_primary\_endpoint\_address | The address of the endpoint for the primary node in the replication group. |
48-
| security\_group\_arn | The ARN of the Redis ElastiCache security group. |
49-
| security\_group\_description | The description of the Redis ElastiCache security group. |
50-
| security\_group\_egress | The egress rules of the Redis ElastiCache security group. |
51-
| security\_group\_id | The ID of the Redis ElastiCache security group. |
52-
| security\_group\_ingress | The ingress rules of the Redis ElastiCache security group. |
53-
| security\_group\_name | The name of the Redis ElastiCache security group. |
54-
| security\_group\_owner\_id | The owner ID of the Redis ElastiCache security group. |
55-
| security\_group\_vpc\_id | The VPC ID of the Redis ElastiCache security group. |
56-
57-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
8+
```

0 commit comments

Comments
 (0)