windows - 在 windows 上为 terraform 预先提交

标签 windows terraform pre-commit pre-commit.com

尝试在 Windows 上启动并运行预提交,尝试一个简单的 terraform fmt 命令,但没有太多关于如何运行 exe 的示例将它们拼凑在一起,我有以下内容:

我的.pre-commit-config.yaml

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.1.0  # Use the ref you want to point at
    hooks:
    - id: detect-aws-credentials
    - id: detect-private-key  

-   repo: local
    hooks:
    - id: terraform-fmt
      name: terraform fmt
      description: runs terraform fmt
      entry: terraform fmt 
      args: [-recursive]
      language: system
    
    

但是我从 pre-commit run -a 得到以下错误:

Detect AWS Credentials...................................................Passed
Detect Private Key.......................................................Passed
terraform fmt............................................................Failed
- hook id: terraform-fmt
- exit code: 1

The fmt command expects at most one argument.
Usage: terraform fmt [options] [DIR]

然后它看起来像是多次运行 terraform fmt,因为我一直在循环中收到错误。知道我缺少什么吗?

最佳答案

使用https://github.com/antonbabenko/pre-commit-terraform 可能会有更好的运气

就是说,我相信您可以使用以下方法让您的示例正常工作:

-   repo: local
    hooks:
    - id: terraform-fmt
      name: terraform fmt
      description: runs terraform fmt
      entry: terraform fmt -recursive
      language: system
      pass_filenames: false

请注意,我已经做了几件事:

  • pass_filenames: false -- 预提交通常通过将文件名传递给 Hook 来工作,这就是为什么你的东西被多次调用的原因
  • 我删除了 args(它是不必要的,而且只对远程存储库有用)并将其与 entry 合并

请注意,使用它作为本地 Hook 通常会比使用上面的存储库更糟糕,因为它总是针对所有文件运行,而不仅仅是您更改的文件(通常会慢得多!)


免责声明:我是预提交的作者

关于windows - 在 windows 上为 terraform 预先提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62583380/

相关文章:

Terraform 资源继承

node.js - git 预提交 |文件未提交

django - 预提交 Hook 以检查 django 迁移

linux - 生成0's and 1's的随机文件

windows - 安装似乎已损坏[不支持]-Visual Studio代码

c# - VSTO Windows Hook keydown 事件调用 10 次

c++ - WIN32 select() 报告 listen() 套接字异常; WSAGetLastError() = 0?

google-cloud-platform - Cloud Composer v2 API 服务代理扩展角色可能缺失

azure - Azure 上的 Terraform Snowpipe 集成时出现错误

delphi - 主要项目首次提交至 Mercurial