OpenTofu Error: 'Module not installed' — Cause, Fix, and Troubleshooting Guide
Fix OpenTofu 'Error: Module not installed' by running tofu init to download modules, and persisting .terraform across CI steps.
- #opentofu
- #iac
- #troubleshooting
- #errors
Stuck on this OpenTofu error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
What this error means
OpenTofu downloads and records every module block’s source under .terraform/modules/ during tofu init. If you run plan/apply before init, or in a fresh checkout where .terraform/ is absent, OpenTofu cannot find the module code and stops:
Error: Module not installed
on main.tf line 12:
12: module "vpc" {
This module is not yet installed. Run "tofu init" to install all modules
required by this configuration.
When it appears
tofu plan/applyfails withModule not installedand points at amoduleblock.- Always appears in a clean clone or a CI runner that skipped
init. - Also appears after adding a new
moduleblock without re-runninginit. - May accompany “Module source has changed” if you edited a
source.
Configuration causes
tofu initnever ran in this working directory / runner.- New module added to config but init not re-run to fetch it.
.terraform/not persisted between CI stages (plan stage vs apply stage).sourcechanged (registry version, git ref, path) requiring re-install.- Corrupted
.terraform/modules/from an interrupted download.
Validating the configuration
Check whether the module cache exists and what it contains:
ls -la .terraform/modules/
cat .terraform/modules/modules.json | jq '.Modules[].Key'
Reproduce with a clean init to see what gets installed:
tofu init
Confirm the module source addresses you declared:
grep -nA4 'module "' *.tf
Resolution
Just initialize — this downloads all modules and providers:
tofu init
tofu plan
After adding or changing a module, re-init (use -upgrade to pull newer registry/git refs):
tofu init -upgrade
In CI, always init before plan/apply and, if you split stages, either re-init in each or persist .terraform/:
tofu init -input=false
tofu plan -input=false -out=tfplan
# later stage (same runner/artifact):
tofu apply -input=false tfplan
Recover a corrupt cache by removing it and re-installing (safe — it is local only):
rm -rf .terraform/modules
tofu init
Keeping definitions valid
.terraform/is machine-specific — never commit it; runtofu initin every environment instead.- If you split plan and apply into separate CI jobs, carry the
.terraform/directory and the saved plan as artifacts, or re-init in the apply job. - Changing a module
sourceor version requiresinitagain;init -upgradefor newer refs. - Use
-input=falsein automation so a prompt never silently hangs the pipeline.
Related configuration errors
- OpenTofu Error: ‘Failed to query available provider packages’ — Cause, Fix, and Troubleshooting Guide
- OpenTofu Error: ‘Backend configuration changed’ — Cause, Fix, and Troubleshooting Guide
- OpenTofu Error: ‘Inconsistent dependency lock file’ — Cause, Fix, and Troubleshooting Guide
Fixed it? Get 500 OpenTofu & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Did this fix your issue?
Trending errors this week
The error guides other engineers are actually reading right now.
- 1mount: wrong fs type, bad option, bad superblock
- 2Docker 'failed to set up container networking': Fix the Bridge and IP Pool
- 3Docker 'failed to create shim task': How to Fix the containerd Runtime Error
- 4modprobe: FATAL: Module not found
- 5mount: wrong fs type, bad option, bad superblock
- 6Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.