Safeguard
Security Guides•

What does terraform providers lock do, and when do you need it?

terraform providers lock writes provider checksums for several platforms into your lock file. Here is when to run it, with a short before and after.

Safeguard Security Team
3 min read

The terraform providers lock command adds provider version and checksum entries to your dependency lock file without installing the providers. Run it when your team uses mixed operating systems, or when providers come from a mirror, so that every platform verifies against the official checksums.

What problem it solves

The lock file, .terraform.lock.hcl, normally updates as a side effect of terraform init. That works if everyone runs the same platform and installs straight from the origin registry. It breaks down in two cases.

First, a mirror. When Terraform installs a provider from a filesystem or network mirror, it cannot see the official checksums for other platforms, so it records only what it can verify locally. Second, mixed platforms. If a laptop on one operating system creates the lock file and CI runs on another, the CI run may add new checksums and show a lock file change you did not expect.

The command

terraform providers lock -platform=linux_amd64 -platform=darwin_arm64

Terraform reads your configuration, finds the providers it needs, fetches information from each origin registry, and writes the selected versions plus the checksums covered by the provider developer's signature. Commit the result.

Before and after

SituationWithout the commandWith the command
Provider from a mirrorOnly the local platform is recordedOfficial checksums for each listed platform are recorded
Laptop and CI differCI may add hashes and dirty the fileHashes are already present
Mirror serves a tampered packageMay go unnoticed on first installInit compares the package to official checksums and fails on mismatch

The third row follows the HashiCorp description: after the official checksums are recorded, later terraform init runs verify that the packages in your mirror match the official ones.

What it does not do

HashiCorp's own page warns that the command prints whether each package was signed, but it cannot decide whether a provider is trustworthy or compliant with your requirements. You still choose which providers to adopt. The lock file records that choice and protects it from silent change.

Steps

  1. Run terraform init normally on a clean checkout.
  2. List every platform that runs Terraform in your team and pipelines.
  3. Run terraform providers lock with a -platform flag for each.
  4. Review the diff in the lock file like any other code change.
  5. Commit it, and repeat whenever you upgrade a provider.

Try it yourself

Click through it at your own pace, or open it full screen. Look at how each dependency is listed with its version, which is the same kind of record a lock file keeps for providers.

Quick check

Does this command install providers?

No. It updates the lock file without initializing the referenced providers.

Do I need it if I only use the public registry on one platform?

Usually not, since terraform init records what you installed. It becomes useful when you add platforms or a mirror.

Does the lock file cover modules?

No. At present the lock file tracks provider dependencies only, so pin remote module versions separately.

Safeguard offers SBOM and dependency scanning and policy gates that can block a pull request on findings, and you can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.