Skip to content

Commit

Permalink
test: run tofu linting using pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Jun 27, 2024
1 parent 54e402d commit 1c8f886
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 21 deletions.
26 changes: 5 additions & 21 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@ on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: opentofu/setup-opentofu@v1
with:
tofu_version: v1.7.2 # renovate: datasource=github-releases depName=opentofu/opentofu
tofu_wrapper: false

- run: |
tofu init
tofu validate
tofu fmt
- name: Check uncommitted changes
run: git diff --exit-code

- if: failure()
run: echo "::error::Check failed, please run 'tofu validate; tofu fmt' and commit the changes."

pre-commit:
runs-on: ubuntu-latest
steps:
Expand All @@ -37,6 +16,11 @@ jobs:
with:
python-version: 3.x

- uses: opentofu/setup-opentofu@v1
with:
tofu_version: v1.7.2 # renovate: datasource=github-releases depName=opentofu/opentofu
tofu_wrapper: false

- name: Install dependencies
run: pip install pre-commit

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.terraform/
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,23 @@ repos:
- id: prettier
files: \.(md|ya?ml)$
exclude: ^CHANGELOG.md$

- repo: local
hooks:
- id: tofu fmt
name: tofu fmt
description: Format Terraform files.
require_serial: true
pass_filenames: false
entry: make fmt
language: system
files: (\.tf|\.tfvars)$

- id: tofu validate
name: tofu validate
description: Validates Terraform files.
require_serial: true
pass_filenames: false
entry: make validate
language: system
files: (\.tf|\.tfvars)$
114 changes: 114 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SHELL = bash

.terraform:
tofu init -backend=false

fmt: .terraform
tofu fmt -recursive

validate: .terraform
tofu validate
3 changes: 3 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ env.auto.tfvars:
.terraform:
tofu init

validate: .terraform
tofu validate

up: .terraform env.auto.tfvars
tofu apply -auto-approve
$(MAKE) port-forward
Expand Down

0 comments on commit 1c8f886

Please sign in to comment.