Skip to content

Commit

Permalink
add pre-commit hooks + docs update (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcincuber committed Jan 31, 2020
1 parent 80020af commit ff33b82
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 38 deletions.
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: check-added-large-files
args: ['--maxkb=500']
- id: check-executables-have-shebangs
- id: pretty-format-json
args: ['--autofix', '--no-sort-keys', '--indent=2']
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-symlinks
- id: detect-private-key
- id: check-merge-conflict
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
- id: trailing-whitespace
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.25.0
hooks:
- id: terraform_fmt
- id: terraform_docs
- id: terraform_tflint
40 changes: 9 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,15 @@ ifneq (,)
.error This Makefile requires GNU Make.
endif

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

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

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

gen: _update-tf-docs
@echo "################################################################################"
@echo "# Terraform-docs generate"
@echo "################################################################################"
@$(MAKE) --no-print-directory _gen-main

_gen-main:
@echo "------------------------------------------------------------"
@echo "# Main module"
@echo "------------------------------------------------------------"
@if docker run --rm \
-v $(CURRENT_DIR):/data \
-e DELIM_START='$(DELIM_START)' \
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
cytopia/terraform-docs:$(TF_DOCS_VERSION) \
terraform-docs-replace-012 --sort-inputs-by-required --with-aggregate-type-defaults md README.md; then \
echo "OK"; \
else \
echo "Failed"; \
exit 1; \
fi

_update-tf-docs:
docker pull cytopia/terraform-docs:$(TF_DOCS_VERSION)
validate: ## Validate files with pre-commit hooks
@pre-commit run --all-files
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Terraform 0.12. Pin module version to `~> v1.0`. Submit pull-requests to `master
module "eks-node-group" {
source = "umotif-public/eks-node-group/aws"
version = "~> 1.0"
enabled = true
cluster_name = aws_eks_cluster.cluster.id
Expand Down Expand Up @@ -57,22 +57,22 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| cluster\_name | The name of the EKS cluster | string | n/a | yes |
| desired\_size | Desired number of worker nodes | number | n/a | yes |
| max\_size | Maximum number of worker nodes | number | n/a | yes |
| min\_size | Minimum number of worker nodes | number | n/a | yes |
| subnet\_ids | A list of subnet IDs to launch resources in | list(string) | n/a | yes |
| ami\_release\_version | AMI version of the EKS Node Group. Defaults to latest version for Kubernetes version | string | `"null"` | no |
| ami\_type | Type of Amazon Machine Image \(AMI\) associated with the EKS Node Group. Defaults to `AL2\_x86\_64`. Valid values: `AL2\_x86\_64`, `AL2\_x86\_64\_GPU`. Terraform will only perform drift detection if a configuration value is provided | string | `"AL2_x86_64"` | no |
| cluster\_name | The name of the EKS cluster | string | n/a | yes |
| create\_iam\_role | Create IAM role for node group. Set to false if pass `node\_role\_arn` as an argument | bool | `"true"` | no |
| desired\_size | Desired number of worker nodes | number | n/a | yes |
| disk\_size | Disk size in GiB for worker nodes. Defaults to 20. Terraform will only perform drift detection if a configuration value is provided | number | `"20"` | no |
| ec2\_ssh\_key | SSH key name that should be used to access the worker nodes | string | `"null"` | no |
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | bool | `"true"` | no |
| instance\_types | Set of instance types associated with the EKS Node Group. Defaults to \["t3.medium"\]. Terraform will only perform drift detection if a configuration value is provided | list(string) | `[ "t3.medium" ]` | no |
| kubernetes\_labels | Key-value mapping of Kubernetes labels. Only labels that are applied with the EKS API are managed by this argument. Other Kubernetes labels applied to the EKS Node Group will not be managed | map(string) | `{}` | no |
| kubernetes\_version | Kubernetes version. Defaults to EKS Cluster Kubernetes version. Terraform will only perform drift detection if a configuration value is provided | string | `"null"` | no |
| max\_size | Maximum number of worker nodes | number | n/a | yes |
| min\_size | Minimum number of worker nodes | number | n/a | yes |
| node\_role\_arn | IAM role arn that will be used by managed node group | string | `""` | no |
| source\_security\_group\_ids | Set of EC2 Security Group IDs to allow SSH access \(port 22\) from on the worker nodes. If you specify `ec2\_ssh\_key`, but do not specify this configuration when you create an EKS Node Group, port 22 on the worker nodes is opened to the Internet \(0.0.0.0/0\) | list(string) | `[]` | no |
| subnet\_ids | A list of subnet IDs to launch resources in | list(string) | n/a | yes |
| tags | A map of tags \(key-value pairs\) passed to resources. | map(string) | `{}` | no |

## Outputs
Expand All @@ -88,3 +88,17 @@ Module managed by [Marcin Cuber](https://github.com/marcincuber) [LinkedIn](http
## License

See LICENSE for full details.

## Pre-commit hooks

### Install dependencies

* [`pre-commit`](https://pre-commit.com/#install)
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks.
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.

##### MacOS

```bash
brew install pre-commit terraform-docs tflint
```
2 changes: 1 addition & 1 deletion examples/multiaz-node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSServicePolicy" {

#####
# EKS Node Group per availability zone
# If you are running a stateful application across multiple Availability Zones that is backed by Amazon EBS volumes and using the Kubernetes Cluster Autoscaler,
# If you are running a stateful application across multiple Availability Zones that is backed by Amazon EBS volumes and using the Kubernetes Cluster Autoscaler,
# you should configure multiple node groups, each scoped to a single Availability Zone. In addition, you should enable the --balance-similar-node-groups feature.
#
# In this setup you can configure a single IAM Role that is attached to multiple node groups.
Expand Down

0 comments on commit ff33b82

Please sign in to comment.