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
Fixing errors like this? Get 500 free DevOps AI prompts
500 copy-paste AI prompts for the stack you actually run — one PDF, free.
Overview
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.
Symptoms
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.
Common Root 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.
How to diagnose
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
Fixes
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
What to watch out for
.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
- 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
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.