tfmodcache
pip install tfmodcache==0.1.0
A local, shared module cache for Terraform and OpenTofu. terraform init downloads the same modules again for every repository and every CI job; tfmodcache keeps one copy on disk and lays it out where Terraform looks, so the second run and every run after it costs no network at all.
There is a plugin cache for providers (TF_PLUGIN_CACHE_DIR). There is none for modules. This is that missing cache, and nothing else.
Use it
Warm the cache and run init in one step:
$ tfmodcache init
linked 4 modules (4 downloaded, 0 already cached)
tfmodcache: running terraform init
Terraform's own output follows, unaffected by this tool.
Run it again, in this repository or in any other one that uses the same modules:
$ tfmodcache init
linked 4 modules (0 downloaded, 4 already cached)
Commands
tfmodcache init [DIR] [-- ARGS]lays the modules out from the cache, then runsterraform initwithARGS.tfmodcache link [DIR]lays the modules out and writes the manifest, without running anything.tfmodcache warm [DIR]fills the cache only, and touches nothing inside the project.tfmodcache list [--json]shows what the cache holds.tfmodcache purge --allandtfmodcache purge --older-than DAYSremove cached modules.tfmodcache pathprints the cache directory.
Useful flags: --offline never touches the network, --cache-dir PATH moves the cache, --symlink links modules instead of copying them, --binary tofu picks OpenTofu.
In continuous integration
The cache is one directory, so any CI cache action can keep it between runs.
- uses: actions/cache@v4
with:
path: ~/.cache/tfmodcache
key: tfmodcache-${{ hashFiles('**/*.tf') }}
- run: pip install tfmodcache==0.1.0
- run: tfmodcache init -- -input=false
What it caches, and what it leaves alone
Cached: registry modules (namespace/name/provider, public or private registry, exact version) and git modules (git::, github.com/..., git@..., with or without ?ref= and //subdir). Nested modules are followed, including modules declared inside a cached module.
Left to Terraform, on purpose, with a message on stderr saying so:
- version constraints that are not one exact version, such as
~> 5.0. Terraform owns constraint solving, and a cache that quietly resolved a range differently would be worse than no cache. - source kinds this tool does not implement, such as
s3::orgcs::. - providers.
TF_PLUGIN_CACHE_DIRalready covers them, and this tool never touches them. .tf.jsonconfiguration files.
Anything left alone is downloaded by Terraform exactly as before. The worst case of installing this tool is the behaviour you already had.
Limits
The module layout and the manifest this tool writes follow the format Terraform documents. The module registry protocol has been checked against a real registry. Running terraform init itself against the manifest this tool produces has not been verified end to end yet. If the manifest is ever wrong, Terraform falls back to downloading the module itself, so the worst case stays the behaviour you had before installing this tool.
Where things live
The cache defaults to ~/.cache/tfmodcache, or $XDG_CACHE_HOME/tfmodcache, or $TFMODCACHE_HOME when set. Inside a project, tfmodcache writes only .terraform/modules, which is the directory Terraform itself owns.
Requirements
Python 3.9 or newer, no third party dependencies. git on PATH is needed for git module sources.
Licence
MIT. Written by Younes Z.
Metadata
Release files for tfmodcache 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tfmodcache-0.1.0.tar.gz | 25.6 kB | Without provenance | Details for tfmodcache-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tfmodcache-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tfmodcache-0.1.0-py3-none-any.whl |
Total release size: 46.7 kB
Release files / tfmodcache-0.1.0.tar.gz
| Download URL | tfmodcache-0.1.0.tar.gz |
|---|---|
| Size | 25.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3dc63e4cd56bd8b4cdeeac10e9a9ef421b7a38a66711cf452d21fec92b60984
|
|
BLAKE2b-256 checksum How to use checksums |
42fdcafcef529cde1dc72e6ab1df85f4041059138a3e52c4e826b075a0d12c3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / tfmodcache-0.1.0-py3-none-any.whl
| Download URL | tfmodcache-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a697a3ce7872771cfa219c206e70434283bf79e342ad3d715941e79f818d03b
|
|
BLAKE2b-256 checksum How to use checksums |
4f2943bf395d6b82462c10cbea40dd64db8acf627468f421ca7892a59f423b90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for tfmodcache 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.