Safeguard
Developer Tools•

Terraform providers and modules: what does the lock file cover?

Terraform's lock file pins provider versions but not remote modules, which changes what a scan can know. How to pin and inventory both.

Safeguard Security Team
3 min read

The Terraform dependency lock file records provider selections, not remote module versions. So a scan reading the lock file can report providers exactly, but module versions are only as precise as the version constraints in your configuration. Pin modules explicitly if you want a scan to know what you use.

What the lock file tracks

The HashiCorp documentation states that the dependency lock file, a feature of Terraform 0.14 and later, tracks only provider dependencies at present, and that Terraform does not remember version selections for remote modules, so it always selects the newest available module version that meets the specification. It also explains that the lock file belongs to the configuration as a whole, living in the working directory with the root module, and that it lets Terraform make the same decisions again in future.

So there are two kinds of dependency with different pinning behaviour.

DependencyPinned by lock fileWhere precision comes from
ProviderYesLock file
Remote moduleNoYour version constraint
Local moduleNot applicableYour own code

Why this matters for coverage

If a module source says version = "~> 3.0", a plan today may select a different release than a plan next month. A scanner reading only configuration sees a range, not the resolved version. That is the same range problem seen in other ecosystems. See lockfile or installed packages: what the scanner actually reads.

How to pin and inventory

  1. Commit .terraform.lock.hcl to version control so provider choices are shared and reviewable.
  2. Pin remote modules to an exact version, not a range, and review changes in pull requests.
  3. For modules sourced from git, pin to a tag or commit. See does a scanner match a dependency pinned to a git commit.
  4. Produce an inventory of providers and modules with versions from your pinned configuration and keep it with each release.
  5. Update on a schedule, reading provider and module changelogs.

What scanners cover here

Two different things are scanned in Terraform work. Configuration scanners check your resources for misconfiguration. Dependency scanners check the providers and modules as software. Do not assume one does the other's job. Ask your tool which it does, and test with a canary.

Review checklist

  • Is the lock file committed and current?
  • Are remote modules pinned exactly?
  • Is there an inventory per release?
  • Do you know who updates providers, and how often?

Safeguard offers dependency scanning and a free scan at gold.safeguard.sh/scan. Check how any tool treats providers and modules before relying on it.

Quick check

Is the lock file enough to know my full Terraform dependency set?

No. It covers providers only, so pinned module versions are also needed.

Should the lock file be committed?

Yes, so provider selections are consistent across machines and visible in review.

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.