Description
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 the precondition
and postcondition
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 the terraform validate
hook, except that it should be only triggered if either dir_path
has a parent directory that is called tests
(i.e. there is a changed test in the commit) or dir_path
has a child directory that is called tests
(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.