Skip to content
Latchkey

OpenTofu "Module not installed" (run tofu init) in CI

OpenTofu found a module block whose source has not been installed into .terraform/modules. A plan, validate, or apply ran before tofu init fetched the modules for this working directory.

What this error means

tofu plan or validate fails with "Error: Module not installed" and "this module is not yet installed. Run \"tofu init\" to install all modules required by this configuration".

tofu
Error: Module not installed

  on main.tf line 10:
  10: module "network" {

This module is not yet installed. Run "tofu init" to install all modules
required by this configuration.

Common causes

A plan step ran without a preceding init

The job calls tofu plan or tofu validate in a fresh checkout where .terraform/modules does not exist yet.

A cached .terraform directory was not restored

CI restored source but not the .terraform module cache, so modules referenced by the config are absent.

How to fix it

Run tofu init before plan

  1. Add a tofu init step ahead of any plan or validate.
  2. Keep init and plan in the same job so .terraform persists.
  3. Use tofu get only if you need modules without full backend init.
.github/workflows/ci.yml
- run: tofu init
- run: tofu plan

Fetch modules explicitly with tofu get

When you only need module installation (no backend), tofu get downloads modules into .terraform/modules.

Terminal
tofu get -update

How to prevent it

  • Always run tofu init before plan, validate, or apply.
  • Keep init and downstream commands in the same job.
  • If caching .terraform, include the modules subdirectory.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →