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".
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
- Add a
tofu initstep ahead of any plan or validate. - Keep init and plan in the same job so
.terraformpersists. - Use
tofu getonly if you need modules without full backend init.
- run: tofu init
- run: tofu planFetch modules explicitly with tofu get
When you only need module installation (no backend), tofu get downloads modules into .terraform/modules.
tofu get -updateHow to prevent it
- Always run
tofu initbefore plan, validate, or apply. - Keep init and downstream commands in the same job.
- If caching
.terraform, include the modules subdirectory.