Skip to content

Commit 6b2eb62

Browse files
committed
Fix terraform_fmt hook and drop useless stuff
1 parent d848eb1 commit 6b2eb62

File tree

5 files changed

+32
-202
lines changed

5 files changed

+32
-202
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ on:
1010
- .github/workflows/release.yml
1111
- '**/*.py'
1212
- '**/*.sh'
13-
- Dockerfile*
13+
- Dockerfile
1414
- .pre-commit-hooks.yaml
15+
# Ignore paths
1516
- '!tests/**'
1617

18+
permissions:
19+
contents: read
1720

1821
jobs:
1922
release:

.pre-commit-hooks.yaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
files: \.(tf|tofu|tfvars|tftest\.hcl|tfmock\.hcl)$
1919
exclude: \.terraform/.*$
2020

21+
- id: terraform_fmt_docker
22+
name: Terraform fmt
23+
description: >-
24+
Rewrites all Terraform configuration files to a canonical format using Docker.
25+
# TODO: There will be ghcr.io/antonbabenko/pre-commit-terraform:latest.
26+
# TODO: pre-commit-terraform:latest is build locally from this branch
27+
entry: --entrypoint terraform_fmt.sh pre-commit-terraform:latest
28+
language: docker_image
29+
files: \.(tf|tofu|tfvars|tftest\.hcl|tfmock\.hcl)$
30+
exclude: \.terraform/.*$
31+
2132
- id: terraform_docs
2233
name: Terraform docs
2334
description: >-
@@ -180,18 +191,6 @@
180191
require_serial: true
181192

182193
# Docker-based versions of hooks (non-breaking additions)
183-
- id: terraform_fmt_docker
184-
name: Terraform fmt (Docker)
185-
description: >-
186-
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.
189-
entry: ghcr.io/antonbabenko/pre-commit-terraform-tools:latest
190-
language: docker_image
191-
args: [terraform, fmt]
192-
files: \.(tf|tofu|tfvars|tftest\.hcl|tfmock\.hcl)$
193-
exclude: \.terraform/.*$
194-
195194
- id: terraform_validate_docker
196195
name: Terraform validate (Docker)
197196
description: >-

Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ COPY tools/install/ /install/
2323
ARG PRE_COMMIT_VERSION=${PRE_COMMIT_VERSION:-latest}
2424
RUN touch /.env && \
2525
if [ "$PRE_COMMIT_VERSION" = "false" ]; then \
26-
echo "Vital software can't be skipped" && exit 1; \
26+
echo "ERROR: PRE_COMMIT_VERSION cannot be 'false' - pre-commit is required" >&2 && exit 1; \
2727
fi
2828
RUN /install/pre-commit.sh
2929

@@ -136,10 +136,10 @@ COPY --from=builder /usr/local/lib/python3.12/site-packages/ /usr/local/lib/pyth
136136
COPY --from=builder /root/ /root/
137137

138138
# Install hooks extra deps
139-
RUN if [ "$(grep -o '^terraform-docs SKIPPED$' /usr/bin/tools_versions_info)" = "" ]; then \
139+
RUN if ! grep -q '^terraform-docs SKIPPED$' /usr/bin/tools_versions_info; then \
140140
apk add --no-cache perl=~5 \
141141
; fi && \
142-
if [ "$(grep -o '^infracost SKIPPED$' /usr/bin/tools_versions_info)" = "" ]; then \
142+
if ! grep -q '^infracost SKIPPED$' /usr/bin/tools_versions_info; then \
143143
apk add --no-cache jq=~1 \
144144
; fi && \
145145
# Fix git runtime fatal:
@@ -148,6 +148,11 @@ RUN if [ "$(grep -o '^terraform-docs SKIPPED$' /usr/bin/tools_versions_info)" =
148148

149149
COPY tools/entrypoint.sh /entrypoint.sh
150150

151+
# Copy hook scripts for Docker-based hooks
152+
COPY hooks/ /usr/local/bin/
153+
COPY lib_getopt /usr/local/
154+
COPY src/pre_commit_terraform/ /usr/local/lib/python3.12/site-packages/pre_commit_terraform/
155+
151156
ENV PRE_COMMIT_COLOR=${PRE_COMMIT_COLOR:-always}
152157

153158
ENV INFRACOST_API_KEY=${INFRACOST_API_KEY:-}

Dockerfile.tools

Lines changed: 0 additions & 178 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,14 @@ Check the [source file](https://github.com/antonbabenko/pre-commit-terraform/blo
343343

344344
### Docker-based hooks (no local tool installation required)
345345

346-
For users who prefer not to install tools locally, Docker-based versions are available for most hooks. These hooks use a Docker image with all tools pre-installed and provide the same functionality as their script-based counterparts.
347-
Note: These hooks are defined with pre-commit `language: docker_image` and reference the Docker image via the `entry` field in `.pre-commit-hooks.yaml`.
348-
These hooks run inside the tools image defined by the hook itself (no image configuration needed in your `.pre-commit-config.yaml`). The image is published at `ghcr.io/antonbabenko/pre-commit-terraform-tools` and can be pinned by tag (e.g., `entry: ghcr.io/antonbabenko/pre-commit-terraform-tools:latest`) or by digest (e.g., `entry: ghcr.io/antonbabenko/pre-commit-terraform-tools@sha256:...`).
349-
Tip: `ghcr.io/antonbabenko/pre-commit-terraform` is the container image for running pre-commit itself, whereas `...-tools` is the image used by the Docker-based hooks.
346+
For users who prefer not to install tools locally, Docker-based versions are
347+
available for most hooks. These hooks use a Docker image with all tools
348+
pre-installed and provide the same functionality as their script-based
349+
counterparts.
350+
351+
> [!NOTE]
352+
> These hooks run inside the Docker image defined by the hook itself. By default, it set to
353+
`entry: ghcr.io/antonbabenko/pre-commit-terraform:latest` which is **NOT WHAT WE WANT**. Better to figure out how to pin it # TODO
350354

351355

352356
| Docker Hook ID | Equivalent Script Hook | Description |
@@ -359,9 +363,6 @@ Tip: `ghcr.io/antonbabenko/pre-commit-terraform` is the container image for runn
359363
| `terraform_trivy_docker` | `terraform_trivy` | Security analysis with Trivy using Docker |
360364
| `infracost_breakdown_docker` | `infracost_breakdown` | Infrastructure cost analysis using Docker |
361365

362-
> **Note:**
363-
> By default, `terraform_docs_docker` is configured with `pass_filenames: false` and an explicit `.` target. This documents only the root module, which is the most common use case. If you want to generate documentation for multiple modules in a monorepo, you can customize the `args` in your own `.pre-commit-config.yaml` (for example, add `--recursive` to the arguments).
364-
365366

366367
**Benefits of Docker hooks:**
367368

@@ -1354,7 +1355,7 @@ jobs:
13541355
run:
13551356
shell: bash
13561357
steps:
1357-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
1358+
- uses: actions/checkout@v5
13581359
with:
13591360
fetch-depth: 0
13601361
ref: ${{ github.event.pull_request.head.sha }}

0 commit comments

Comments
 (0)