Skip to content

Commit 1d7fbe8

Browse files
authored
add git hooks and update docs (#9)
1 parent d065576 commit 1d7fbe8

File tree

6 files changed

+79
-131
lines changed

6 files changed

+79
-131
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: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource "aws_ecs_cluster" "cluster" {
1818
module "ecs-farage" {
1919
source = "umotif-public/ecs-fargate/aws"
2020
version = "~> 1.0"
21-
21+
2222
name_prefix = "ecs-fargate-example"
2323
vpc_id = "vpc-abasdasd132"
2424
private_subnet_ids = ["subnet-abasdasd132123", "subnet-abasdasd132123132"]
@@ -61,52 +61,66 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http
6161

6262
| Name | Description | Type | Default | Required |
6363
|------|-------------|:----:|:-----:|:-----:|
64-
| cluster\_id | The Amazon Resource Name (ARN) that identifies the cluster. | string | n/a | yes |
65-
| health\_check | A health block containing health check settings for the target group. Overrides the defaults. | map(string) | n/a | yes |
66-
| lb\_arn | Arn for the LB for which the service should be attach to. | string | n/a | yes |
67-
| name\_prefix | A prefix used for naming resources. | string | n/a | yes |
68-
| private\_subnet\_ids | A list of private subnets inside the VPC | list(string) | n/a | yes |
69-
| task\_container\_image | The image used to start a container. | string | n/a | yes |
70-
| task\_container\_port | The port number on the container that is bound to the user-specified or automatically assigned host port | number | n/a | yes |
71-
| vpc\_id | The VPC ID. | string | n/a | yes |
72-
| container\_name | Optional name for the container to be used instead of name_prefix. | string | `""` | no |
73-
| deployment\_controller\_type | Type of deployment controller. Valid values: CODE_DEPLOY, ECS. | string | `"ECS"` | no |
64+
| cluster\_id | The Amazon Resource Name \(ARN\) that identifies the cluster. | string | n/a | yes |
65+
| container\_name | Optional name for the container to be used instead of name\_prefix. | string | `""` | no |
66+
| deployment\_controller\_type | Type of deployment controller. Valid values: CODE\_DEPLOY, ECS. | string | `"ECS"` | no |
7467
| deployment\_maximum\_percent | The upper limit of the number of running tasks that can be running in a service during a deployment | number | `"200"` | no |
7568
| deployment\_minimum\_healthy\_percent | The lower limit of the number of running tasks that must remain running and healthy in a service during a deployment | number | `"50"` | no |
7669
| desired\_count | The number of instances of the task definitions to place and keep running. | number | `"1"` | no |
70+
| health\_check | A health block containing health check settings for the target group. Overrides the defaults. | map(string) | n/a | yes |
7771
| health\_check\_grace\_period\_seconds | Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 7200. Only valid for services configured to use load balancers. | number | `"300"` | no |
72+
| lb\_arn | Arn for the LB for which the service should be attach to. | string | n/a | yes |
73+
| load\_balanced | Whether the task should be loadbalanced. | bool | `"true"` | no |
7874
| log\_retention\_in\_days | Number of days the logs will be retained in CloudWatch. | number | `"30"` | no |
79-
| propogate\_tags | Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION. | string | `"TASK_DEFINITION"` | no |
80-
| repository\_credentials | name or ARN of a secrets manager secret (arn:aws:secretsmanager:region:aws_account_id:secret:secret_name) | string | `""` | no |
75+
| logs\_kms\_key | The KMS key ARN to use to encrypt container logs. | string | `""` | no |
76+
| name\_prefix | A prefix used for naming resources. | string | n/a | yes |
77+
| private\_subnet\_ids | A list of private subnets inside the VPC | list(string) | n/a | yes |
78+
| propogate\_tags | Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK\_DEFINITION. | string | `"TASK_DEFINITION"` | no |
79+
| repository\_credentials | name or ARN of a secrets manager secret \(arn:aws:secretsmanager:region:aws\_account\_id:secret:secret\_name\) | string | `""` | no |
8180
| repository\_credentials\_kms\_key | key id, key ARN, alias name or alias ARN of the key that encrypted the repository credentials | string | `"alias/aws/secretsmanager"` | no |
82-
| service\_registry\_arn | ARN of aws_service_discovery_service resource | string | `""` | no |
83-
| tags | A map of tags (key-value pairs) passed to resources. | map(string) | `{}` | no |
81+
| service\_registry\_arn | ARN of aws\_service\_discovery\_service resource | string | `""` | no |
82+
| tags | A map of tags \(key-value pairs\) passed to resources. | map(string) | `{}` | no |
83+
| target\_group\_name | The name for the tasks target group | string | `""` | no |
8484
| task\_container\_assign\_public\_ip | Assigned public IP to the container. | bool | `"false"` | no |
8585
| task\_container\_command | The command that is passed to the container. | list(string) | `[]` | no |
8686
| task\_container\_environment | The environment variables to pass to a container. | map(string) | `{}` | no |
87+
| task\_container\_image | The image used to start a container. | string | n/a | yes |
88+
| task\_container\_port | The port number on the container that is bound to the user-specified or automatically assigned host port | number | n/a | yes |
8789
| task\_container\_protocol | Protocol that the container exposes. | string | `"HTTP"` | no |
8890
| task\_definition\_cpu | Amount of CPU to reserve for the task. | number | `"256"` | no |
89-
| task\_definition\_memory | The soft limit (in MiB) of memory to reserve for the container. | number | `"512"` | no |
91+
| task\_definition\_memory | The soft limit \(in MiB\) of memory to reserve for the container. | number | `"512"` | no |
9092
| task\_host\_port | The port number on the container instance to reserve for your container. | number | `"0"` | no |
91-
| target\_group\_name | The name for the tasks target group. | string | `""` | no |
92-
| load\_balanced | Whether the task should be loadbalanced. | bool | `true` | no |
93-
| logs_kms_key | The KMS key ARN to use to encrypt container logs. | string | `""` | no |
93+
| vpc\_id | The VPC ID. | string | n/a | yes |
9494

9595
## Outputs
9696

9797
| Name | Description |
9898
|------|-------------|
9999
| log\_group\_name | The name of the Cloudwatch log group for the task. |
100-
| service\_arn | The Amazon Resource Name (ARN) that identifies the ECS service. |
100+
| service\_arn | The Amazon Resource Name \(ARN\) that identifies the ECS service. |
101101
| service\_name | The name of the service. |
102-
| service\_sg\_id | The Amazon Resource Name (ARN) that identifies the service security group. |
102+
| service\_sg\_id | The Amazon Resource Name \(ARN\) that identifies the service security group. |
103103
| target\_group\_arn | The ARN of the Target Group used by Load Balancer. |
104104
| target\_group\_name | The Name of the Target Group used by Load Balancer. |
105-
| task\_role\_arn | The Amazon Resource Name (ARN) specifying the ECS service role. |
105+
| task\_role\_arn | The Amazon Resource Name \(ARN\) specifying the ECS service role. |
106106
| task\_role\_name | The name of the Fargate task service role. |
107107

108108
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
109109

110110
## License
111111

112112
See LICENSE for full details.
113+
114+
## Pre-commit hooks
115+
116+
### Install dependencies
117+
118+
* [`pre-commit`](https://pre-commit.com/#install)
119+
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks.
120+
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.
121+
122+
#### MacOS
123+
124+
```bash
125+
brew install pre-commit terraform-docs tflint
126+
```

examples/core/README.md

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,4 @@ terraform init
66
terraform validate
77
terraform plan
88
terraform apply --auto-approve
9-
```
10-
11-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
12-
## Inputs
13-
14-
| Name | Description | Type | Default | Required |
15-
|------|-------------|:----:|:-----:|:-----:|
16-
| cluster\_id | The Amazon Resource Name (ARN) that identifies the cluster. | string | n/a | yes |
17-
| health\_check | A health block containing health check settings for the target group. Overrides the defaults. | map(string) | n/a | yes |
18-
| lb\_arn | Arn for the LB for which the service should be attach to. | string | n/a | yes |
19-
| name\_prefix | A prefix used for naming resources. | string | n/a | yes |
20-
| private\_subnet\_ids | A list of private subnets inside the VPC | list(string) | n/a | yes |
21-
| task\_container\_image | The image used to start a container. | string | n/a | yes |
22-
| task\_container\_port | The port number on the container that is bound to the user-specified or automatically assigned host port | number | n/a | yes |
23-
| vpc\_id | The VPC ID. | string | n/a | yes |
24-
| container\_name | Optional name for the container to be used instead of name_prefix. | string | `""` | no |
25-
| deployment\_controller\_type | Type of deployment controller. Valid values: CODE_DEPLOY, ECS. | string | `"ECS"` | no |
26-
| deployment\_maximum\_percent | The upper limit of the number of running tasks that can be running in a service during a deployment | number | `"200"` | no |
27-
| deployment\_minimum\_healthy\_percent | The lower limit of the number of running tasks that must remain running and healthy in a service during a deployment | number | `"50"` | no |
28-
| desired\_count | The number of instances of the task definitions to place and keep running. | number | `"1"` | no |
29-
| health\_check\_grace\_period\_seconds | Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 7200. Only valid for services configured to use load balancers. | number | `"300"` | no |
30-
| log\_retention\_in\_days | Number of days the logs will be retained in CloudWatch. | number | `"30"` | no |
31-
| propogate\_tags | Specifies whether to propagate the tags from the task definition or the service to the tasks. The valid values are SERVICE and TASK_DEFINITION. | string | `"TASK_DEFINITION"` | no |
32-
| repository\_credentials | name or ARN of a secrets manager secret (arn:aws:secretsmanager:region:aws_account_id:secret:secret_name) | string | `""` | no |
33-
| repository\_credentials\_kms\_key | key id, key ARN, alias name or alias ARN of the key that encrypted the repository credentials | string | `"alias/aws/secretsmanager"` | no |
34-
| service\_registry\_arn | ARN of aws_service_discovery_service resource | string | `""` | no |
35-
| tags | A map of tags (key-value pairs) passed to resources. | map(string) | `{}` | no |
36-
| task\_container\_assign\_public\_ip | Assigned public IP to the container. | bool | `"false"` | no |
37-
| task\_container\_command | The command that is passed to the container. | list(string) | `[]` | no |
38-
| task\_container\_environment | The environment variables to pass to a container. | map(string) | `{}` | no |
39-
| task\_container\_protocol | Protocol that the container exposes. | string | `"HTTP"` | no |
40-
| task\_definition\_cpu | Amount of CPU to reserve for the task. | number | `"256"` | no |
41-
| task\_definition\_memory | The soft limit (in MiB) of memory to reserve for the container. | number | `"512"` | no |
42-
| task\_host\_port | The port number on the container instance to reserve for your container. | number | `"0"` | no |
43-
44-
## Outputs
45-
46-
| Name | Description |
47-
|------|-------------|
48-
| log\_group\_name | The name of the Cloudwatch log group for the task. |
49-
| service\_arn | The Amazon Resource Name (ARN) that identifies the ECS service. |
50-
| service\_name | The name of the service. |
51-
| service\_sg\_id | The Amazon Resource Name (ARN) that identifies the service security group. |
52-
| target\_group\_arn | The ARN of the Target Group used by Load Balancer. |
53-
| target\_group\_name | The Name of the Target Group used by Load Balancer. |
54-
| task\_role\_arn | The Amazon Resource Name (ARN) specifying the ECS service role. |
55-
| task\_role\_name | The name of the Fargate task service role. |
56-
57-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9+
```

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ resource "aws_cloudwatch_log_group" "main" {
55
name = var.name_prefix
66
retention_in_days = var.log_retention_in_days
77

8-
kms_key_id = var.logs_kms_key
9-
tags = var.tags
8+
kms_key_id = var.logs_kms_key
9+
tags = var.tags
1010
}
1111

1212
#####
@@ -74,7 +74,7 @@ resource "aws_security_group_rule" "egress_service" {
7474
# Load Balancer Target group
7575
#####
7676
resource "aws_lb_target_group" "task" {
77-
name = var.target_group_name !="" ? var.target_group_name : "${var.name_prefix}-target-${var.task_container_port}"
77+
name = var.target_group_name != "" ? var.target_group_name : "${var.name_prefix}-target-${var.task_container_port}"
7878
vpc_id = var.vpc_id
7979
protocol = var.task_container_protocol
8080
port = var.task_container_port
@@ -101,7 +101,7 @@ resource "aws_lb_target_group" "task" {
101101
tags = merge(
102102
var.tags,
103103
{
104-
Name = var.target_group_name !="" ? var.target_group_name : "${var.name_prefix}-target-${var.task_container_port}"
104+
Name = var.target_group_name != "" ? var.target_group_name : "${var.name_prefix}-target-${var.task_container_port}"
105105
},
106106
)
107107
}

variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ variable "target_group_name" {
160160
}
161161

162162
variable "load_balanced" {
163-
type = bool
164-
default = true
163+
type = bool
164+
default = true
165165
description = "Whether the task should be loadbalanced."
166166
}
167167

168168
variable "logs_kms_key" {
169-
type = string
169+
type = string
170170
description = "The KMS key ARN to use to encrypt container logs."
171-
default = ""
171+
default = ""
172172
}

0 commit comments

Comments
 (0)