You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-17Lines changed: 5 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,8 @@ supported hooks are:
10
10
***terraform-fmt**: Automatically run `terraform fmt` on all Terraform code (`*.tf` files).
11
11
***terraform-validate**: Automatically run `terraform validate` on all Terraform code (`*.tf` files).
12
12
***packer-validate**: Automatically run `packer validate` on all Packer code (`*.pkr.*` files).
13
-
***terragrunt-hclfmt**: Automatically run `terragrunt hclfmt` on all Terragrunt configurations.
13
+
***terragrunt-hclfmt**: Automatically run `terragrunt hclfmt` on all Terragrunt configurations (deprecated, use `terragrunt-hcl-fmt` instead if you are using Terragrunt 0.77.22 or later).
14
+
***terragrunt-hcl-fmt**: Automatically run `terragrunt hcl fmt` on all Terragrunt configurations (requires Terragrunt 0.77.22 or later).
14
15
***tflint**: Automatically run [`tflint`](https://github.com/terraform-linters/tflint) on all OpenTofu/Terraform code (`*.tf`, `*.tofu` files).
15
16
***shellcheck**: Run [`shellcheck`](https://www.shellcheck.net/) to lint files that contain a bash [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)).
16
17
***gofmt**: Automatically run `gofmt` on all Golang code (`*.go` files).
@@ -23,10 +24,6 @@ supported hooks are:
23
24
markdown doc files.
24
25
***sentinel-fmt**: Automatically run `sentinel fmt` on all Sentinel code (`*.sentinel.*` files).
25
26
26
-
27
-
28
-
29
-
30
27
## General Usage
31
28
32
29
In each of your repos, add a file called `.pre-commit-config.yaml` with the following contents:
@@ -44,19 +41,15 @@ repos:
44
41
- id: golint
45
42
```
46
43
47
-
Next, have every developer:
44
+
Next, have every developer:
48
45
49
46
1. Install [pre-commit](http://pre-commit.com/). E.g. `brew install pre-commit`.
50
47
1. Run `pre-commit install` in the repo.
51
48
52
49
That’s it! Now every time you commit a code change (`.tf` file), the hooks in the `hooks:` config will execute.
53
50
54
-
55
-
56
-
57
51
## Running Against All Files At Once
58
52
59
-
60
53
### Example: Formatting all files
61
54
62
55
If you'd like to format all of your code at once (rather than one file at a time), you can run:
@@ -65,8 +58,6 @@ If you'd like to format all of your code at once (rather than one file at a time
65
58
pre-commit run tofu-fmt --all-files
66
59
```
67
60
68
-
69
-
70
61
### Example: Enforcing in CI
71
62
72
63
If you'd like to enforce all your hooks, you can configure your CI build to fail if the code doesn't pass checks by
@@ -81,9 +72,6 @@ pre-commit run --all-files
81
72
If all the hooks pass, the last command will exit with an exit code of 0. If any of the hooks make changes (e.g.,
82
73
because files are not formatted), the last command will exit with a code of 1, causing the build to fail.
83
74
84
-
85
-
86
-
87
75
## Helm Lint Caveats
88
76
89
77
### Detecting charts
@@ -129,7 +117,7 @@ containerImage: nginx
129
117
130
118
Now when the pre-commit hook runs, it will call `helm lint` with both `linter_values.yaml` and `values.yaml`:
131
119
132
-
```
120
+
```bash
133
121
helm lint -f values.yaml -f linter_values.yaml .
134
122
```
135
123
@@ -153,7 +141,7 @@ repos:
153
141
154
142
With the introduction of `--chdir` into tflint, the `--config` argument is now bound to whatever subdirectory you are
155
143
running the check against. For mono-repos this isn't ideal as you may have a central configuration file you'd like to
156
-
use. If this matches your use-case, you can specify the placeholder `__GIT_ROOT__` value in the `--config` argument
144
+
use. If this matches your use-case, you can specify the placeholder `__GIT_ROOT__` value in the `--config` argument
157
145
that will evaluate to the root of the repository you are in.
0 commit comments