Terraform rules for Bazel
rules_terraform
are Bazel rules for running terraform
as part of your build workflow. These rules currently support grouping files in
a directory as a module, as well as planning & applying these modules.
git_repository(
name = "io_bazel_rules_terraform",
commit = "<latest commit sha>",
remote = "https://github.com/tommyknows/rules_terraform",
)
load("@io_bazel_rules_terraform//terraform:deps.bzl", "terraform_dependencies")
terraform_dependencies(version = "1.0.1")
terraform_module
can be used to create a single terraform module.
Attributes:
srcs
: a list of files that make up this module. All files should be in the same directory.modules
: a list of otherterraform_modules
that are used within this module.
This rule / macro creates three targets:
<target-name>
: a simple wrapper for modules<target-name>.apply
: target to runterraform apply
on this module. Executable throughbazel run //<target-name>.apply
<target-name>.plan
: target to runterraform plan
on this module. Executable throughbazel run //<target-name>.plan
The terraform_toolchain
rule can be used to register a custom binary for
terraform. There is a single attribute binary
, which needs to be executable on
the host.
Usually, this rule shouldn't be used, and specific version should be specified
through the terraform_dependencies
instead.
In general, all version of terraform are supported through the version
parameter in terraform_dependencies
. However, most versions will require the
user to specify a sha256 sum to terraform_dependencies
, like so:
terraform_dependencies(
version = "1.0.0",
sha256 = ""
)
This sha256 sum is the digest of the SHA256 checksum file from terraform, which is then in turn used to download the terraform binaries and verify their checksums.
This file can be found at Terraform's download page
Pull Requests that add new versions & their digests are highly welcome!
State management cannot be done through Bazel - the state file would be an input and output to a build action, which is a cyclic dependency - and needs to be done by a remote state.
Currently, terraform providers cannot be fetched through these rules. However, it is highly recommended to use the official Provider Requirements instead.
See the examples directory for a simple example on how to use these rules.