Skip to content
DevOps AI ToolKit
Newsletter
All guides
AI for OpenTofu By James Joyner IV · · 8 min read

OpenTofu Error: 'Module not installed' — Cause, Fix, and Troubleshooting Guide

Quick answer

Fix OpenTofu 'Error: Module not installed' by running tofu init to download modules, and persisting .terraform across CI steps.

  • #opentofu
  • #iac
  • #troubleshooting
  • #errors
Free toolkit

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/apply fails with Module not installed and points at a module block.
  • Always appears in a clean clone or a CI runner that skipped init.
  • Also appears after adding a new module block without re-running init.
  • May accompany “Module source has changed” if you edited a source.

Common Root Causes

  • tofu init never 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).
  • source changed (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; run tofu init in 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 source or version requires init again; init -upgrade for newer refs.
  • Use -input=false in automation so a prompt never silently hangs the pipeline.
Free download · 368-page PDF

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.