{
  "id": 15574388,
  "title": "Pre-commit Hooks for Terraform and Python: 6 Tips That Stick",
  "url": "https://urgent.news/2026/10/19/pre-commit-hooks-for-terraform-and-python-6-tips-that-stick",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-19T07:01:45.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/oleksandr_kuryzhev_42873f/pre-commit-hooks-for-terraform-and-python-6-tips-that-stick-2jhp"
  },
  "original_language": "en",
  "account": "Pre-commit hooks help catch formatting issues and other problems before developers push changes to a repository, reducing noisy reviews and improving code quality. For projects that combine Terraform infrastructure code with Python scripts, such as Lambda functions or automation scripts, specific pre-commit hooks can streamline the development process.\n\nIt's essential to pin the hook revision to a specific tag or commit SHA instead of a branch name to ensure consistency across environments. Regularly updating the hooks using a pre-commit autoupdate command and reviewing the changes like any other dependency update helps maintain a stable coding environment.\n\nUsing a combination of Terraform hooks and Python linters like Ruff can help keep the codebase clean and consistent. Ruff covers multiple linting and formatting tasks, reducing the need for multiple tools and simplifying configuration. However, it's important to be aware that newer releases of Ruff may introduce new hook names, so checking the repository's README after an update is necessary to avoid errors.\n\nStarting the Terraform workflow with formatting, tflint, and generated documentation ensures that the codebase is consistent and easy to understand. Terraform_docs can automatically keep the module README in sync with the code, while terraform_validate should only be added after the basic functionality is stable, as it can be slow to run.\n\nAvoid running Terraform plans inside pre-commit hooks, as they require cloud credentials and network access, which are not available locally. Instead, manage credentials properly in the CI pipeline and run plans in the CI environment. Keep pre-commit hooks fast and avoid auto-fixing hooks, which can lead to the commit failing on purpose if the changes are not staged correctly. Running slow checks, such as security scanners or full Terraform validation, as pre-push stage checks allows developers to catch issues before pushing changes to the repository, while still running them locally during development.\n\nTo prevent the accidental inclusion of sensitive information in commits, hooks like detect-private-key and check-added-large-files can help catch secrets before they reach history. Running these checks early in the development process can save time and effort in cleaning up a leaked credential later.",
  "summary": "Originally published on kuryzhev.cloud A pull request with forty comments that all say \"run terraform fmt\" or \"remove the unused import\" is a familiar sight. Pre-commit hooks move those checks to the developer's machine, before the commit exists. The tips below target repos that mix Terraform and Python, such as infrastructure code plus Lambda handlers or automation scripts. They are independent,…",
  "key_points": [
    "Pin hook revision to specific SHA to ensure consistency",
    "Combine Terraform hooks with Python linters like Ruff",
    "Run slow checks as pre-push stage to catch issues early"
  ],
  "editors_take": "Integrating specialized hooks for both infrastructure and scripting code streamlines development workflows by catching formatting errors and security leaks before they reach the shared repository.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}