Supply chain and lockfile integrity
Understand what you are trusting
Terraform configuration can cause executable code to run. Providers are native plugins; external data sources and provisioners may run other processes; modules may introduce all of these. Review dependency provenance, not only the top-level HCL. An official, partner or community designation describes distribution or publisher context, not an independent proof of safety. A version pin protects repeatability, not correctness. A compromised trusted release can still satisfy its published hash.
Review provider selection and hashes
Keep the reviewed dependency lock file in version control. The provider constraint is the allowed range; the selected version is the particular release; the hash list records accepted package representations. Terraform checks downloaded packages against recorded hashes. The lockfile uses h1 and zh hash schemes; do not equate arbitrary SHA-256 text with a valid h1 entry. A hash mismatch is a reason to investigate the origin, platform, mirror and lock history. Do not delete the lockfile or add an unverified checksum to make the installation succeed.
Before: provider inventory/tool 2.4.1, approved hash AAfter: provider inventory/tool 2.4.1, unknown hash BDecision: hold the change; verify package provenance.These symbolic hashes are deliberately not HCL or valid provider hashes. A new platform can legitimately add a hash, but it needs evidence. A valid publisher signature links the signed data to a signing key; review the key identity and your trust policy. It does not prove that the binary is benign.
Control where packages are obtained
A protected internal mirror can distribute reviewed artifacts and support restricted-network runners. Keep the mirror write permissions separate from the jobs consuming it. In this example the explicit installation method permits only the named provider from a local mirror. No direct method is included. This is a static CLI config, and the path is illustrative; do not install it as your global configuration.
# Illustrative CLI configuration, not a .tf module.provider_installation { filesystem_mirror { path = "/opt/approved-providers" include = ["registry.terraform.io/hashicorp/random"] }}A cache is not an approval process. A network mirror with valid TLS can still supply an unsafe artifact. In an authorized dependency staging environment, the following command can obtain lock information for two target platforms. It may contact registries and writes the dependency lockfile, so it is not part of the offline lab.
terraform providers lock -platform=linux_amd64 -platform=darwin_arm64Review the resulting signatures, versions and hashes, including the actual platform packages, before distributing them. Keep a documented emergency upgrade and revocation process.
Pin and review module sources separately
The provider lockfile does not record remote module selections. Use an exact Registry module version or a reviewed immutable Git commit identifier for reproducibility; a moving branch or tag is a weaker control. Review the module and its transitive dependencies before permitting it in a privileged runner. Restrict who can publish a replacement version and record a separately verified content digest if your organization requires it.
# Fictional registry; do not initialize.module "inventory" { source = "registry.example.test/platform/inventory/local" version = "2.4.1"}This reserved example host and version are fictional. Never initialize it. The optional local example below uses only a built-in resource; it demonstrates that an ordinary review record need not download a third-party plugin. It does not test signatures or mirrors.
terraform { required_version = "= 1.14.8"}resource "terraform_data" "review" { input = { component = "inventory" approval = "synthetic-review" }}output "review" { value = terraform_data.review.output}In a fresh authorized local copy, check the provisional CLI version, initialize with a trusted CLI configuration, validate and review a plan. The expected output after an approved local apply contains the synthetic component and approval strings. No native run has been performed.
Practice a dependency update review
Compare the old and new lock summaries, check the planned version, publisher trust, platform coverage and module pin. Verify license and release/security notes before approval. Review the actual plan after any dependency update. If provenance cannot be established, hold the release and report the missing evidence. Complete the six synthetic package cases. Next: policy as code and guardrails.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Supply chain and lockfile integrity — knowledge check
Review identity and dependency trust boundaries.
What does a provider lockfile hash establish?
What should you do when an unexpected hash appears?
Does the provider lockfile pin remote module versions?
What can a valid package signature show?
Why use a controlled mirror?