Skip to content

Commit d1629ba

Browse files
committed
chore: Improved documentation for pre-commit
1 parent 70a37a8 commit d1629ba

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

.pre-commit-hooks.yaml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,54 +184,62 @@
184184
name: Terraform fmt (Docker)
185185
description: >-
186186
Rewrites all Terraform configuration files to a canonical format using Docker.
187+
NOTE: Requires Docker to be available. Use 'skip' in .pre-commit-config.yaml
188+
if running on pre-commit.ci or other environments without Docker.
187189
entry: ghcr.io/actuarysailor/pre-commit-terraform-tools:latest
188190
language: docker_image
189191
args: [terraform, fmt]
190192
files: \.(tf|tofu|tfvars|tftest\.hcl|tfmock\.hcl)$
191193
exclude: \.terraform/.*$
192-
default: false
193194

194195
- id: terraform_validate_docker
195196
name: Terraform validate (Docker)
196-
description: Validates all Terraform configuration files using Docker.
197+
description: >-
198+
Validates all Terraform configuration files using Docker.
199+
NOTE: Requires Docker to be available. Use 'skip' in .pre-commit-config.yaml
200+
if running on pre-commit.ci or other environments without Docker.
197201
require_serial: true
198202
entry: ghcr.io/actuarysailor/pre-commit-terraform-tools:latest
199203
language: docker_image
200204
args: [terraform, validate]
201205
pass_filenames: false
202206
files: \.(tf|tofu|tfvars|terraform\.lock\.hcl)$
203207
exclude: \.terraform/.*$
204-
default: false
205208

206209
- id: terraform_tflint_docker
207210
name: Terraform validate with tflint (Docker)
208-
description: Validates all Terraform configuration files with TFLint using
209-
Docker.
211+
description: >-
212+
Validates all Terraform configuration files with TFLint using Docker.
213+
NOTE: Requires Docker to be available. Use 'skip' in .pre-commit-config.yaml
214+
if running on pre-commit.ci or other environments without Docker.
210215
require_serial: true
211216
entry: ghcr.io/actuarysailor/pre-commit-terraform-tools:latest
212217
language: docker_image
213218
args: [tflint, --chdir=.]
214219
pass_filenames: false
215220
files: \.(tf|tofu|tfvars)$
216221
exclude: \.terraform/.*$
217-
default: false
218222

219223
- id: terraform_docs_docker
220224
name: Terraform docs (Docker)
221225
description: >-
222226
Inserts input and output documentation into README.md using Docker.
227+
NOTE: Requires Docker to be available. Use 'skip' in .pre-commit-config.yaml
228+
if running on pre-commit.ci or other environments without Docker.
223229
require_serial: true
224230
entry: ghcr.io/actuarysailor/pre-commit-terraform-tools:latest
225231
language: docker_image
226232
args: [terraform-docs, markdown, table, ., --output-file, README.md]
227233
pass_filenames: false
228234
files: \.(tf|tofu|terraform\.lock\.hcl)$
229235
exclude: \.terraform/.*$
230-
default: false
231236

232237
- id: terraform_checkov_docker
233238
name: Checkov (Docker)
234-
description: Runs checkov on Terraform templates using Docker.
239+
description: >-
240+
Runs checkov on Terraform templates using Docker.
241+
NOTE: Requires Docker to be available. Use 'skip' in .pre-commit-config.yaml
242+
if running on pre-commit.ci or other environments without Docker.
235243
entry: ghcr.io/actuarysailor/pre-commit-terraform-tools:latest
236244
language: docker_image
237245
args: [checkov, -d, .]
@@ -240,30 +248,32 @@
240248
files: \.(tf|tofu)$
241249
exclude: \.terraform/.*$
242250
require_serial: true
243-
default: false
244251

245252
- id: terraform_trivy_docker
246253
name: Terraform validate with trivy (Docker)
247254
description: >-
248255
Static analysis of Terraform templates to spot potential security issues
249256
using Docker.
257+
NOTE: Requires Docker to be available. Use 'skip' in .pre-commit-config.yaml
258+
if running on pre-commit.ci or other environments without Docker.
250259
require_serial: true
251260
entry: ghcr.io/actuarysailor/pre-commit-terraform-tools:latest
252261
language: docker_image
253262
args: [trivy, config, .]
254263
pass_filenames: false
255264
files: \.(tf|tofu|tfvars)$
256265
exclude: \.terraform/.*$
257-
default: false
258266

259267
- id: infracost_breakdown_docker
260268
name: Infracost breakdown (Docker)
261-
description: Check terraform infrastructure cost using Docker.
269+
description: >-
270+
Check terraform infrastructure cost using Docker.
271+
NOTE: Requires Docker to be available. Use 'skip' in .pre-commit-config.yaml
272+
if running on pre-commit.ci or other environments without Docker.
262273
entry: ghcr.io/actuarysailor/pre-commit-terraform-tools:latest
263274
language: docker_image
264275
args: [infracost, breakdown, --path, .]
265276
pass_filenames: false
266277
require_serial: true
267278
files: \.(tf|tofu|tfvars|hcl)$
268279
exclude: \.terraform/.*$
269-
default: false

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ TAG=latest
9494
docker pull ghcr.io/antonbabenko/pre-commit-terraform:$TAG
9595
```
9696

97-
All available tags [here](https://github.com/antonbabenko/pre-commit-terraform/pkgs/container/pre-commit-terraform/versions).
97+
All available tags are [available on GitHub Container Registry](https://github.com/antonbabenko/pre-commit-terraform/pkgs/container/pre-commit-terraform/versions).
9898

9999
Check [About Docker image security](#about-docker-image-security) section to learn more about possible security issues and why you probably want to build and maintain your own image.
100100

@@ -362,6 +362,22 @@ For users who prefer not to install tools locally, Docker-based versions are ava
362362
* Faster CI/CD execution (tools are pre-installed in the image)
363363
* Simplified dependency management
364364

365+
**Requirements and limitations:**
366+
367+
* Docker must be installed and accessible
368+
* For pre-commit.ci users: At this time, these hooks must be skipped as pre-commit.ci agents do not have Docker available.
369+
* _Note: pre-commit has a Docker setup for hooks, so Docker support may be added in the future._
370+
* **You can still use Docker-based hooks in CI/CD pipelines** (such as GitHub Actions, GitLab CI, etc.) by running `pre-commit run --all-files` (or `pre-commit run -a`) on a self-hosted or GitHub-hosted runner where Docker is available. This allows you to enforce the same checks in CI as locally, even if pre-commit.ci does not support Docker yet.
371+
372+
**Skipping Docker hooks on pre-commit.ci:**
373+
374+
If you use pre-commit.ci, add this to your `.pre-commit-config.yaml`:
375+
376+
```yaml
377+
ci:
378+
skip: [terraform_fmt_docker, terraform_validate_docker, terraform_tflint_docker, terraform_docs_docker, terraform_checkov_docker, terraform_trivy_docker, infracost_breakdown_docker]
379+
```
380+
365381
**Example usage:**
366382
367383
```yaml
@@ -410,8 +426,9 @@ You can specify environment variables that will be passed to the hook at runtime
410426

411427
> [!IMPORTANT]
412428
> Variable values are exported _verbatim_:
413-
> - No interpolation or expansion are applied
414-
> - The enclosing double quotes are removed if they are provided
429+
>
430+
> * No interpolation or expansion are applied
431+
> * The enclosing double quotes are removed if they are provided
415432

416433
Config example:
417434

@@ -523,7 +540,7 @@ Note that `terraform_checkov` runs recursively during `-d .` usage. That means,
523540
- --args=--skip-check CKV2_AWS_8
524541
```
525542

526-
Check all available arguments [here](https://www.checkov.io/2.Basics/CLI%20Command%20Reference.html).
543+
Check all available arguments in the [Checkov CLI Command Reference](https://www.checkov.io/2.Basics/CLI%20Command%20Reference.html).
527544

528545
For deprecated hook you need to specify each argument separately:
529546

examples/.pre-commit-config-docker.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Example .pre-commit-config.yaml for using Docker-based hooks
22
# This configuration uses Docker containers instead of requiring local tool installation
33

4+
# Skip Docker hooks on pre-commit.ci (which doesn't support Docker)
5+
ci:
6+
skip: [terraform_fmt_docker, terraform_validate_docker, terraform_tflint_docker,
7+
terraform_docs_docker, terraform_checkov_docker, terraform_trivy_docker,
8+
infracost_breakdown_docker]
9+
410
repos:
511
- repo: https://github.com/actuarysailor/pre-commit-terraform
612
rev: v1.96.1 # Use a stable release version

0 commit comments

Comments
 (0)