Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Describe hooks usage and improve examples #232

Merged
merged 5 commits into from
Sep 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: Unificate hooks usage examples
  • Loading branch information
MaxymVlasov committed Sep 29, 2021
commit f9160b31ca36a847cb6ce38a8e0fa29751667a7d
57 changes: 17 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ There are several [pre-commit](https://pre-commit.com/) hooks to keep Terraform

| Hook name | Description |
| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `checkov` | [checkov](https://github.com/bridgecrewio/checkov) static analysis of terraform templates to spot potential security issues. [Hook notes](#checkov) |
| `checkov` | [checkov](https://github.com/bridgecrewio/checkov) static analysis of terraform templates to spot potential security issues. [Hook notes](#checkov) |
| `terraform_docs_replace` | Runs `terraform-docs` and pipes the output directly to README.md |
| `terraform_docs_without_aggregate_type_defaults` | Inserts input and output documentation into `README.md` without aggregate type defaults. Hook notes same as for [terraform_docs](#terraform_docs) |
| `terraform_docs` | Inserts input and output documentation into `README.md`. Recommended. [Hook notes](#terraform_docs) |
| `terraform_docs_without_aggregate_type_defaults` | Inserts input and output documentation into `README.md` without aggregate type defaults. Hook notes same as for [terraform_docs](#terraform_docs) |
| `terraform_docs` | Inserts input and output documentation into `README.md`. Recommended. [Hook notes](#terraform_docs) |
| `terraform_fmt` | Rewrites all Terraform configuration files to a canonical format. [Hook notes](#terraform_docs) |
| `terraform_tflint` | Validates all Terraform configuration files with [TFLint](https://github.com/terraform-linters/tflint). [Available TFLint rules](https://github.com/terraform-linters/tflint/tree/master/docs/rules#rules). [Hook notes](#terraform_tflint). |
| `terraform_tfsec` | [TFSec](https://github.com/liamg/tfsec) static analysis of terraform templates to spot potential security issues. [Hook notes](#terraform_tfsec) |
Expand Down Expand Up @@ -236,7 +236,9 @@ Example:

```yaml
- id: terraform_docs_replace
args: ['--sort-by-required', '--dest=TEST.md']
args:
- --sort-by-required
- --dest=TEST.md
```

### terraform_tflint
Expand All @@ -245,26 +247,19 @@ Example:

Example:

```yaml
- id: terraform_tflint
args: ['--args=--deep']
```

In order to pass multiple args, try the following:

```yaml
- id: terraform_tflint
args:
- '--args=--deep'
- '--args=--enable-rule=terraform_documented_variables'
- --args=--deep
- --args=--enable-rule=terraform_documented_variables
```

3. When you have multiple directories and want to run `tflint` in all of them and share single config file it is impractical to hard-code the path to `.tflint.hcl` file. The solution is to use `__GIT_WORKING_DIR__` placeholder which will be replaced by `terraform_tflint` hooks with Git working directory (repo root) at run time. For example:
2. When you have multiple directories and want to run `tflint` in all of them and share single config file it is impractical to hard-code the path to `.tflint.hcl` file. The solution is to use `__GIT_WORKING_DIR__` placeholder which will be replaced by `terraform_tflint` hooks with Git working directory (repo root) at run time. For example:

```yaml
- id: terraform_tflint
args:
- '--args=--config=__GIT_WORKING_DIR__/.tflint.hcl'
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
```


Expand Down Expand Up @@ -300,41 +295,23 @@ Example:

### terraform_validate

1. `terraform_validate` supports custom arguments so you can pass supported no-color or json flags.

Example:

```yaml
- id: terraform_validate
args: ['--args=-json']
```

In order to pass multiple args, try the following:
1. `terraform_validate` supports custom arguments so you can pass supported no-color or json flags:

```yaml
- id: terraform_validate
args:
- '--args=-json'
- '--args=-no-color'
```

2. `terraform_validate` also supports custom environment variables passed to the pre-commit runtime

Example:

```yaml
- id: terraform_validate
args: ['--envs=AWS_DEFAULT_REGION="us-west-2"']
- --args=-json
- --args=-no-color
```

In order to pass multiple args, try the following:
2. `terraform_validate` also supports custom environment variables passed to the pre-commit runtime:

```yaml
- id: terraform_validate
args:
- '--envs=AWS_DEFAULT_REGION="us-west-2"'
- '--envs=AWS_ACCESS_KEY_ID="anaccesskey"'
- '--envs=AWS_SECRET_ACCESS_KEY="asecretkey"'
- --envs=AWS_DEFAULT_REGION="us-west-2"
- --envs=AWS_ACCESS_KEY_ID="anaccesskey"
- --envs=AWS_SECRET_ACCESS_KEY="asecretkey"
```

3. It may happen that Terraform working directory (`.terraform`) already exists but not in the best condition (eg, not initialized modules, wrong version of Terraform, etc). To solve this problem you can find and delete all `.terraform` directories in your repository using this command:
Expand Down