Skip to content

AleksaC/terraform-py

Repository files navigation

terraform-py

Add new versions Run tests

pip installable terraform binary with wrapper for pre-commit.

The mechanism by which the terraform binary is downloaded is adapted from shellcheck-py.

Getting started

Installation

This package has been built to make it more convenient to run terraform fmt terraform validate as pre-commit hooks so it hasn't been published to PyPI. However you can install it using git:

pip install git+https://github.com/AleksaC/terraform-py.git@v1.13.3

pre-commit hooks

Since terraform fmt and terraform validate take directories as inputs they can't be used as pre-commit hooks directly. Hence there are wrappers for the two commands that take list of filenames as input and run the commands on the directories they are in. To use the hooks include the following config in your .pre-commit-config.yaml file:

repos:
  - repo: https://github.com/AleksaC/terraform-py
    rev: v1.13.3
    hooks:
      - id: tf-fmt
      - id: tf-validate

Limitations

This package mirrors all terraform releases currently available on github, however fmt and validate commands weren't available on the oldest versions and worked differently in the initial releases. This shouldn't be a problem since I don't expect versions so old to be used.

Versions before 1.0.3 won't work on Macs with M1 chip since darwin arm builds weren't available for earlier versions. While x86 binaries would work I didn't want to support that edge case in the platform detection code as it won't be needed for the future releases.

terraform validate itself isn't particularly fast. In addition to that terraform init needs to be performed before it, making it even slower. In projects with lots of modules this can get quite slow, so you may need to set up additional caching beside the one for pre-commit.

Contact 🙋‍♂️

About

pip installable terraform binary with wrapper for pre-commit

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •