Lock-file rules for .terraform.lock.hcl.

terraform_providers_lock regenerates the multi-platform lock file; terraform_providers_lock_test catches drift against the module's required_providers blocks; terraform_lock_diff_test structurally diffs the init-aspect output against a checked-in golden.

External Terraform registry modules are resolved live by the terraform.modules(...) bzlmod extension — no separate lock file, no updater rule. See docs/src/index.md.

Rules

terraform_lock_diff_test

load("@rules_terraform//terraform:terraform_modules_lock.bzl", "terraform_lock_diff_test")

terraform_lock_diff_test(name, golden, regenerate_hint, target)

Diffs the init-aspect-generated .terraform.lock.hcl for target against a checked-in golden produced by real terraform init / tofu init. Verifies same provider set, same version+constraints per provider, same zh: set, and at least one h1: overlap.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
goldenA .terraform.lock.hcl produced by real terraform/tofu init.Labelrequired
regenerate_hintCommand shown in the failure message telling users how to refresh the golden.Stringoptional""
targetA terraform_module target. The init aspect runs against it to produce the lock under test.Labelrequired

terraform_providers_lock

load("@rules_terraform//terraform:terraform_modules_lock.bzl", "terraform_providers_lock")

terraform_providers_lock(name, output, platforms, target)

Regenerates .terraform.lock.hcl for a terraform_module by running real terraform providers lock -platform=<all> under the toolchain-fetched terraform binary. bazel run writes the multi-platform result back to source — the one path that produces hashes for platforms Bazel didn't resolve for the current build.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
outputWhere to write the multi-platform .terraform.lock.hcl, relative to this BUILD file's package. Diff-test companions should point golden = "<same-path>".Stringrequired
platformsos_arch platforms to record hashes for. Defaults to the common set.List of stringsoptional[]
targetThe terraform_module whose .tf sources drive the lock resolution.Labelrequired

terraform_providers_lock_test

load("@rules_terraform//terraform:terraform_modules_lock.bzl", "terraform_providers_lock_test")

terraform_providers_lock_test(name, lock, target)

Fails the test if .terraform.lock.hcl doesn't cover every provider declared in terraform { required_providers { ... } } blocks reachable from target (and vice versa). Network-free presence check.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
lockThe .terraform.lock.hcl file being verified.Labelrequired
targetThe terraform_module whose transitive sources are being checked.Labelrequired