Skip to content

panubo/pre-commit-hooks

Repository files navigation

Pre-Commit Hooks

This repo contains configs and plugins for the pre-commit framework.

  • bin - the plugins / pre-commit hooks.

Important

Maintained by Panubo — Cloud Native & SRE Consultants in Sydney. Work with us →

Developing

Example:

pre-commit try-repo ~/git/pre-commit-hooks tf-docs --verbose

See https://pre-commit.com/index.html#developing-hooks-interactively

tf-local-module-check

This hook checks for local Terraform module references (e.g. source = "../").

To test it locally, you can run the script directly against a file containing a local module reference, like tests/terraform/local_module.tf.

Test 'warn' behavior:

Set the TF_LOCAL_MODULE_ACTION environment variable to warn.

$ TF_LOCAL_MODULE_ACTION=warn ./bin/tf-local-module.sh tests/terraform/local_module.tf
[WARNING] Found local Terraform module reference in tests/terraform/local_module.tf
    2:  source = "./module"
    6:  source = "../another/module"

The script will print a warning and exit with 0.

Test default 'block' behavior:

Set the TF_LOCAL_MODULE_ACTION environment variable to block.

$ TF_LOCAL_MODULE_ACTION=block ./bin/tf-local-module.sh tests/terraform/local_module.tf
[WARNING] Found local Terraform module reference in tests/terraform/local_module.tf
    2:  source = "./module"
    6:  source = "../another/module"
[ERROR] Commit blocked because local Terraform module references were found.

The script will print an error and exit with 1.

Test with pre-commit:

You can also use pre-commit to run the hook against a local repository.

$ pre-commit try-repo . tf-local-module-check --files tests/terraform/local_module.tf

Important

About Panubo

This project is maintained by Panubo, a technology consultancy based in Sydney, Australia. We build reliable, scalable systems and help teams master the cloud-native ecosystem.

We are available for hire to help with:

  • SRE & Operations: Improving system reliability and incident response.
  • Platform Engineering: Building internal developer platforms that scale.
  • Kubernetes: Cluster design, security auditing, and migrations.
  • DevOps: Streamlining CI/CD pipelines and developer experience.
  • See our other services

Need a hand with your infrastructure? Let’s have a chat or email us at team@panubo.com.

About

Git pre-commit hooks

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •