Improve installation instructions and make README more readable (#72)

This commit is contained in:
Maksym Vlasov 2019-10-17 14:50:16 +03:00 committed by Anton Babenko
commit eec9c884a1

View file

@ -4,21 +4,42 @@
## How to install
### Step 1
### 1. Install dependencies
On MacOSX install the `pre-commit` and `awk` (required for Terraform 0.12) package
* [`pre-commit`](http://pre-commit.com/#install)
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) (required for `terraform_docs` hooks)
* GNU `awk` (required for `terraform_docs` hooks in Terraform 0.12)
* [`TFLint`](https://github.com/wata727/tflint) (required for `terraform_tflint` hook)
##### MacOS
```bash
brew install pre-commit awk
brew install pre-commit awk terraform-docs tflint
```
For other operating systems check the [official documentation](http://pre-commit.com/#install)
##### Ubuntu
### Step 2
```bash
sudo apt install python-pip3 gawk &&\
pip3 install pre-commit
curl -L "$(curl -s https://api.github.com/repos/segmentio/terraform-docs/releases/latest | grep -o -E "https://.+?-linux-amd64")" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
curl -L "$(curl -s https://api.github.com/repos/wata727/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
```
### 2. Install the pre-commit hook globally
```bash
DIR=~/.git-template
git config --global init.templateDir ${DIR}
pre-commit init-templatedir -t pre-commit ${DIR}
```
### 3. Add configs and hooks
Step into the repository you want to have the pre-commit hooks installed and run:
```bash
git init
cat <<EOF > .pre-commit-config.yaml
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.19.0
@ -28,15 +49,7 @@ cat <<EOF > .pre-commit-config.yaml
EOF
```
### Step 3
Install the pre-commit hook
```bash
pre-commit install
```
### Step 4
### 4. Run
After pre-commit hook has been installed you can run it manually on all files in the repository
@ -47,19 +60,28 @@ pre-commit run -a
## Available Hooks
There are several [pre-commit](http://pre-commit.com/) hooks to keep Terraform configurations (both `*.tf` and `*.tfvars`) and Terragrunt configurations (`*.hcl`) in a good shape:
* `terraform_fmt` - Rewrites all Terraform configuration files to a canonical format.
* `terraform_validate` - Validates all Terraform configuration files.
* `terraform_docs` - Inserts input and output documentation into `README.md`. Recommended.
* `terraform_docs_without_aggregate_type_defaults` - Inserts input and output documentation into `README.md` without aggregate type defaults.
* `terraform_docs_replace` - Runs `terraform-docs` and pipes the output directly to README.md
* `terraform_tflint` - Validates all Terraform configuration files with [TFLint](https://github.com/wata727/tflint).
* `terragrunt_fmt` - Rewrites all Terragrunt configuration files (`*.hcl`) to a canonical format.
| Hook name | Description |
| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| `terraform_fmt` | Rewrites all Terraform configuration files to a canonical format. |
| `terraform_validate` | Validates all Terraform configuration files. |
| `terraform_docs` | Inserts input and output documentation into `README.md`. Recommended. |
| `terraform_docs_without_aggregate_type_defaults` | Inserts input and output documentation into `README.md` without aggregate type defaults. |
| `terraform_docs_replace` | Runs `terraform-docs` and pipes the output directly to README.md |
| `terraform_tflint` | Validates all Terraform configuration files with [TFLint](https://github.com/wata727/tflint). |
| `terragrunt_fmt` | Rewrites all [Terragrunt](https://github.com/gruntwork-io/terragrunt) configuration files (`*.hcl`) to a canonical format. |
Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blob/master/.pre-commit-hooks.yaml) to know arguments used for each hook.
## Notes about hooks
## Notes about terraform_docs hooks
1. `terraform_docs` and `terraform_docs_without_aggregate_type_defaults` will insert/update documentation generated by [terraform-docs](https://github.com/segmentio/terraform-docs) between markers - `<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->` and `<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->` if they are present in `README.md`. Make sure that `terraform-docs` is installed.
1. `terraform_docs` and `terraform_docs_without_aggregate_type_defaults` will insert/update documentation generated by [terraform-docs](https://github.com/segmentio/terraform-docs) framed by markers:
```txt
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
```
if they are present in `README.md`.
1. `terraform_docs_replace` replaces the entire README.md rather than doing string replacement between markers. Put your additional documentation at the top of your `main.tf` for it to be pulled in. The optional `--dest` argument lets you change the name of the file that gets created/modified.