pre-commit-terraform icon indicating copy to clipboard operation
pre-commit-terraform copied to clipboard

Support for `terraform test`

Open tasansga opened this issue 11 months ago β€’ 6 comments

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.

tasansga avatar Aug 01 '23 08:08 tasansga