Skip to content

Commit 2be8fe5

Browse files
feat: Support for TFSec (antonbabenko#103)
1 parent 29fa140 commit 2be8fe5

File tree

3 files changed

+576
-1
lines changed

3 files changed

+576
-1
lines changed

.pre-commit-hooks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@
5757
language: script
5858
files: (\.hcl)$
5959
exclude: \.terraform\/.*$
60+
61+
- id: terraform_tfsec
62+
name: Terraform validate with tfsec
63+
description: Static analysis of Terraform templates to spot potential security issues.
64+
entry: terraform_tfsec.sh
65+
language: script

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
* [`pre-commit`](https://pre-commit.com/#install)
1010
* [`terraform-docs`](https://github.com/segmentio/terraform-docs) required for `terraform_docs` hooks. `GNU awk` is required if using `terraform-docs` older than 0.8.0 with Terraform 0.12.
1111
* [`TFLint`](https://github.com/terraform-linters/tflint) required for `terraform_tflint` hook.
12+
* [`TFSec`](https://github.com/liamg/tfsec) required for `terraform_tfsec` hook.
1213

1314
##### MacOS
1415

1516
```bash
16-
brew install pre-commit gawk terraform-docs tflint
17+
brew tap liamg/tfsec
18+
brew install pre-commit gawk terraform-docs tflint tfsec
1719
```
1820

1921
##### Ubuntu
@@ -23,6 +25,7 @@ sudo apt install python3-pip gawk &&\
2325
pip3 install pre-commit
2426
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/
2527
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
28+
env GO111MODULE=on go get -u github.com/liamg/tfsec/cmd/tfsec
2629
```
2730

2831
### 2. Install the pre-commit hook globally
@@ -69,6 +72,7 @@ There are several [pre-commit](https://pre-commit.com/) hooks to keep Terraform
6972
| `terraform_docs_replace` | Runs `terraform-docs` and pipes the output directly to README.md |
7073
| `terraform_tflint` | Validates all Terraform configuration files with [TFLint](https://github.com/terraform-linters/tflint). |
7174
| `terragrunt_fmt` | Rewrites all [Terragrunt](https://github.com/gruntwork-io/terragrunt) configuration files (`*.hcl`) to a canonical format. |
75+
| `terraform_tfsec` | [TFSec](https://github.com/liamg/tfsec) static analysis of terraform templates to spot potential security issues. |
7276

7377
Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blob/master/.pre-commit-hooks.yaml) to know arguments used for each hook.
7478

@@ -112,6 +116,20 @@ if they are present in `README.md`.
112116
- 'args=--enable-rule=terraform_documented_variables'
113117
```
114118

119+
## Notes about terraform_tfsec hooks
120+
121+
1. `terraform_tfsec` will recurse all directories/modules.
122+
1. To ignore specific warnings, follow the convention from the
123+
[documentation](https://github.com/liamg/tfsec#ignoring-warnings).
124+
1. Example:
125+
```hcl
126+
resource "aws_security_group_rule" "my-rule" {
127+
type = "ingress"
128+
cidr_blocks = ["0.0.0.0/0"] #tfsec:ignore:AWS006
129+
}
130+
```
131+
132+
115133
## Notes for developers
116134

117135
1. Python hooks are supported now too. All you have to do is:

0 commit comments

Comments
 (0)