-
-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add an option --tf-version
to terraform_docs, terraform_fmt, and terraform_validate
#194
Conversation
--tf-version
to terraform_docs, terraform_fmt, and terraform_validate--tf-version
to terraform_docs, terraform_fmt, and terraform_validate
…and terraform_validate Enables the use of a version parameter which is in turn used by `tfenv` to dynamically switch the version of terraform being used at runtime.
bc8cc2d
to
8910cd3
Compare
Hi @svvitale ! Thanks for the proposal. I am not sure we need to parameterize each hook separately but instead... I think we can have another hook named something like
Sample config: hooks:
- id: use_terraform_version
args: ['--tfenv --version=min-required']
# args: ['--tfswitch --version=latest']
# args: ['--tfenv --version=0.12.18']
# args: ['--tfswitch --version="^0.12"'] The final PR will be much smaller. What do you think? |
Hi @antonbabenko! Thanks so much for the quick reply, I'm glad to hear that you would get some value out of this feature as well.
I didn't realize that hooks were executed in sequential order, although that makes sense now that you highlighted it. I think this is a MUCH better approach that isolates it from current and future hook code. My only concern is that I'd like to ensure that the previously configured terraform version is restored after the hooks complete. I suppose that can be an additional (and optional) hook that users can place at the end of their hooks list. This approach would also not be compatible with the fail_fast option, but that could be called out in the docs. Let me know if you agree with the "restore" option and I'll get to work on the rest. Thanks again for taking the time to look through this. |
Perfect! There are some cases like the one you described (fail_fast) but even more often I run I agree it will be fine as long as we have |
Relates #188 |
This PR has been automatically marked as stale because it has been open 30 days |
Close as too outdated. Simpler to create a new branch with specified changes than try to resolve conflicts |
Is there any possibility to stick with |
Sure. Install Also, what you asking for is part of #570 (comment) which would be implemented by someone in the future (it can be you) |
@MaxymVlasov does docker image use latest terraform version? Im using GitLab CI/CD Pipeline and wondering if I should use a decent version or simply install required terraform version before triggering precommit:
image: ghcr.io/antonbabenko/pre-commit-terraform:latest
script:
- <----------- INSTALL TF here?
- pre-commit run --all-files Or is there other possibility to use version 1.5.7 in pipeline? |
You can build your own docker image with any tool version, including terraform Check the |
Enables the use of a version parameter which is in turn used by
tfenv
to dynamically switch the version of terraform being used at runtime.This feature is intended for users who may have more than one version of Terraform in use. Running
terraform fmt
can produce wildly different results depending on the version of Terraform being used, and by allowing the version to be set in the hook configuration, pre-commit can switch to the proper version, run the hook, and then switch back to the previously configured version to restore the original system state.Please let me know if you have any questions at all. I did modify
terraform_fmt.sh
pretty extensively to look like the other shell scripts since it now needs to accept a parameter.