-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
Support for terraform test
#549
Comments
I haven't used Also,
https://github.com/hashicorp/terraform/releases/tag/v1.6.0-alpha20230802 So I propose to wait with hook implementation until TF 1.6.0 release |
I'd be happy to contribute to this. |
Hi @hoangelos |
I submitted a PR for this. There's only one problem. It would run also when .tftest.hcl files are updated too and not just .tf files. However, there's a problem with the logic of files that "assumes" that the directory the files that match is the directory you want to run the command from. This is not true with test. Also, this requires terraform 1.6.x obviously. |
I haven't yet made it to employ TF tests for my use cases, hence I'm speaking more of speculatively, though I see the logic like this: 1) when any of TF Config files (tf/tfvars) are changed, run TF |
This is some feedback since I'm migrating from Kitchen-Terraform to Terraform test. I could see running unit tests as part of pre-commit helpful, but running what they are branding as integration tests would be far too long of a feedback loop in its current implementation. Each run tears down the infra, and subsequently, the next run needs to rebuild it. This makes integration tests unusable for almost everything we do or anything that takes longer than a few minutes. Tests can run a command of plan == unit test or apply == integration based on the language in their blog post. This is hardcoded in the test and can't be passed in the CLI yet (I'll check for an issue and open one if not), which presents an implementation detail as far as this issue goes. I suppose we could use separate test files but that would probably be a lot of copy/paste. Anyways, just some thoughts! |
What problem are you facing?
I want to run
terraform test
in a pre-commit hook if either the module or one of the module's tests changed.terraform test
has been around since at least 2021 and became quite usable with theprecondition
andpostcondition
blocks introduced in terraform 1.2.0, but is nevertheless still a "experimental" feature of the terraform CLI.How could pre-commit-terraform help solve your problem?
In principle
terraform test
is "just the same" as theterraform validate
hook, except that it should be only triggered if eitherdir_path
has a parent directory that is calledtests
(i.e. there is a changed test in the commit) ordir_path
has a child directory that is calledtests
(i.e. there is a change in the module). Either way,terraform test
would be run from the terraform module root directory and it should fail the commit if the tests do not pass.The text was updated successfully, but these errors were encountered: