pre-commit-terraform
pre-commit-terraform copied to clipboard
feat: Allow setting custom TF binary
Put an x into the box if that apply:
- [ ] This PR introduces breaking change.
- [ ] This PR fixes a bug.
- [x] This PR adds new functionality.
- [x] This PR enhances existing functionality.
Description of your changes
Allow setting custom TF binary.
- provide per hook setting
--hook-config=--tf-path=<path_to_binary_or_binary_name> - export ENV variable
PCT_TFPATH=<path_to_binary_or_binary_name> - export ENV variable
TERRAGRUNT_TFPATH=<path_to_binary_or_binary_name> - if none of above are set defaults to
terraformbinary found in the user's $PATH - if none of above are set/available defaults to
tofubinary found in the user's $PATH - in the end, if none of above is set/available -
exit 1with error message
Side feature. Fixes bad README.md
I'm open to any suggestion and contributions.
Fixes #570
How can we test changes
Create dummy repository with a dummy terraform module test
mkdir test
cd test
git init
Add files to test/:
.pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: terraform_fmt
name: terraform_fmt
entry: /path/to/pre-commit-terraform/hooks/terraform_fmt.sh
language: script
files: \.tf$
# Uncomment these lines. Or set global ENV variables PCT_TFPATH or TERRAGRUNT_TFPATH
#args:
#- --hook-config=--tf-path=tofu
main.tf
# dummy terraform file with ugly formatting
resource "null_resource" "print_time" {
triggers = {
current_time = timestamp()
}
provisioner "local-exec" {
command = "echo Current time is ${triggers.current_time}"
}
}
Run in the test module directory:
pre-commit install
pre-commit run --verbose --files main.tf
@yermulnik if you've missed it please join group conversation in UKR slack (you know which one)
I somehow missed terraform_providers_lock.sh
@yermulnik if you've missed it please join group conversation in UKR slack (you know which one)
@den-is If this is about ukrops, then some time ago I was kicked from that Slack team w/o any decent reason by its notorious owner π€·π»
@den-is When you're done updating PR and addressing comments, please re-request review, so that we all know it's ready for another round of review and discussion. Thanks.
Also please pet shfmt (https://github.com/antonbabenko/pre-commit-terraform/actions/runs/9016122008/job/24780937313?pr=670) as it can't push to your repo/branch.
Not entirely sure, but maybe allowing maintainers to push to your branch, would allow GH workflow to push too π€
@yermulnik yes, ukrops... sad... Just @MaxymVlasov is responding there
fixed shfmt recommendations
@den-is When you're done updating PR and addressing comments, please re-request review, so that we all know it's ready for another round of review and discussion. Thanks.
@den-is Just a heads up.
JFYI: Max is on vacation and thus this PR will be reviewed by him too when he's back.
Ah, it discared full readme, not just this commit, meh, 1 min
Pushed final README fixes. Missed the broken README part the last time when I was reverting back to */
This was fixed by VSCode automatically. Will check for workaround
Add the below to config of VSCode of yours:
"[markdown]": {
"files.trimTrailingWhitespace": false
}
Other common useful settings VSCode usually is missing from what I've found from experience of others using it:
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
This was fixed by VSCode automatically. Will check for workaround
Add the below to config of VSCode of yours:
"[markdown]": { "files.trimTrailingWhitespace": false }Other common useful settings VSCode usually is missing from what I've found from experience of others using it:
"files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, "files.trimFinalNewlines": true,
lol dude... i always have this setting in all my editors... for years... you basically copy pasted my snippets which I add to different projects were noobs can't solve their whitespace issues.
Only thing I was not able to find correct settings for VSCode to fix * replacement with -. (Well I did not spend hours to find it in VSCode... just used vim to revert to your standard)
Space trimming and so on should be done by .editorconfig in the first place, as is supported by everything, including vim.
TOC is not supported by built-in MD engine, for this I use https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
With
"markdownlint.config": {
"MD029": false,
"MD012": {
"maximum": 5
}
},
"markdown.extension.toc.unorderedList.marker": "*",
"markdown.extension.toc.levels": "2..6",
I'll check vanilla VS Code settings and then will send PR which will add needed configs and/or rewrite MD file
In case if person uses VSCode, most of .editorconfig settings are supported natively. Otherwise you have to install another extension.
But yea, addined .editorconfig to you project makes it clear what formatting you require and ask to match. (from those who can't configure their IDEs with universal/common/common-sense/not-personal settings)
Only thing I was not able to find correct settings for VSCode to fix
*replacement with-. (Well I did not spend hours to find it in VSCode...
It's probably not the VSCode per se, but an extension. Like some of these: https://github.com/yzhang-gh/vscode-markdown or https://github.com/prettier/prettier-vscode
BTW FWIW: https://github.com/yzhang-gh/vscode-markdown/issues/145
just used vim to revert to your standard)
It's not ours. It's Markdown language specification. Unless you prove otherwise.
PS: I looked at markdownlint rules and they seem to prefer * over - for unordered lists in documentation β https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md π€
This PR is included in version 1.90.0 :tada: