Skip to content
Snippets Groups Projects
Commit ef8ef3d4 authored by nimrod's avatar nimrod
Browse files

Allow using a different Terraform binary.

In case you're using a different CLI, like `tofu`.
parent fa7b5fb8
Branches
No related tags found
No related merge requests found
Pipeline #3696 failed
...@@ -7,16 +7,19 @@ import sys ...@@ -7,16 +7,19 @@ import sys
import hooks.utils import hooks.utils
TF_CLI = os.getenv("TF_CLI", "terraform")
def main(): def main():
"""Main entrypoint.""" """Main entrypoint."""
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", nargs="+", type=pathlib.Path) parser.add_argument("file", nargs="+", type=pathlib.Path)
args = parser.parse_args() args = parser.parse_args()
hooks.utils.check_executable("terraform") hooks.utils.check_executable(TF_CLI)
os.putenv("TF_INPUT", "0") os.putenv("TF_INPUT", "0")
os.putenv("TF_IN_AUTOMATION", "1") os.putenv("TF_IN_AUTOMATION", "1")
return hooks.utils.bulk_check( return hooks.utils.bulk_check(
lambda x: hooks.utils.check_file(["terraform", "fmt", "-diff", x]), lambda x: hooks.utils.check_file([TF_CLI, "fmt", "-diff", x]),
hooks.utils.unique_directories(args.file), hooks.utils.unique_directories(args.file),
) )
......
...@@ -7,18 +7,23 @@ import sys ...@@ -7,18 +7,23 @@ import sys
import hooks.utils import hooks.utils
def tf_validate(directory): TF_CLI = os.getenv("TF_CLI", "terraform")
def tf_validate(directory): # noqa: D213
"""Validate Terraform modules.
Also runs init -backend=false to install the providers.
"""
if ( if (
hooks.utils.check_directory( hooks.utils.check_directory(
["terraform", "init", "-backend=false"], directory=directory [TF_CLI, "init", "-backend=false"], directory=directory
) )
> 0 > 0
): ):
return 1 return 1
if ( if (
hooks.utils.check_directory( hooks.utils.check_directory([TF_CLI, "validate"], directory=directory)
["terraform", "validate"], directory=directory
)
> 0 > 0
): ):
return 1 return 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment