terraform/configs/configload
Martin Atkins fc0e28b2b4 configload: Don't download the same module source multiple times
It is common for the same module source package to be referenced multiple
times in the same configuration, either because there are literally
multiple instances of the same module source or because a single package
(or repository) contains multiple modules in sub-directories and many
of them are referenced.

To optimize this, here we introduce a simple caching behavior where the
module installer will detect if it's asked to install multiple times from
the same source and produce the second and subsequent directories by
copying the first, rather than by downloading again over the network.

This optimization is applied once all of the go-getter detection has
completed and sub-directory portions have been trimmed, so it is also
able to normalize differently-specified source addresses that all
ultimately detect to the same resolved address. When installing, we
always extract the entire specified package (or repository) and then
reference the specified sub-directory, so we can safely re-use existing
directories when the base package is the same, even if the sub-directory
is different.

However, as a result we do not yet address the fact that the same package
will be stored multiple times _on disk_, which may still be problematic
when referencing large repositories multiple times in
disk-storage-constrained environments. We could address this in a
subsequent change by investigating the use of symlinks where possible.

Since the Registry installer is implemented just as an extra resolution
step in front of go-getter, this optimization applies to registry
modules too. This does not apply to local relative references, which will
continue to just resolve into the already-prepared directory of their
parent module.

The cache of previously installed paths lives only for the duration of
one call to InstallModules, so we will never re-use directories that
were created by previous runs of "terraform init" and there is no risk
that older versions will pollute the cache when attempting an upgrade
from a source address that doesn't explicitly specify a version.

No additional tests are added here because the existing module installer
tests (when TF_ACC=1) already cover the case of installing multiple
modules from the same source.
2018-10-16 18:50:29 -07:00
..
test-fixtures configs/configload: installer tests inspect their result 2018-02-15 15:56:39 -08:00
copy_dir.go configs/configload: installation from registry and go-getter 2018-02-15 15:56:39 -08:00
doc.go configs/configload: package for loading configurations 2018-02-15 15:56:38 -08:00
getter.go configload: Don't download the same module source multiple times 2018-10-16 18:50:29 -07:00
inode.go configs/configload: installation from registry and go-getter 2018-02-15 15:56:39 -08:00
inode_freebsd.go configs/configload: installation from registry and go-getter 2018-02-15 15:56:39 -08:00
inode_windows.go configs/configload: installation from registry and go-getter 2018-02-15 15:56:39 -08:00
loader.go configs/configload: Helper for recognizing a config dir (or not) 2018-10-16 18:24:47 -07:00
loader_init_from_module.go configload: Don't download the same module source multiple times 2018-10-16 18:50:29 -07:00
loader_init_from_module_test.go configs/configload: InitDirFromModule 2018-02-15 15:56:39 -08:00
loader_install.go configload: Don't download the same module source multiple times 2018-10-16 18:50:29 -07:00
loader_install_hooks.go configs/configload: installation of local modules 2018-02-15 15:56:38 -08:00
loader_install_test.go configs/configload: installer tests inspect their result 2018-02-15 15:56:39 -08:00
loader_load.go configs/configload: package for loading configurations 2018-02-15 15:56:38 -08:00
loader_load_test.go configs/configload: package for loading configurations 2018-02-15 15:56:38 -08:00
loader_snapshot.go configload: Configuration snapshots 2018-10-16 18:50:29 -07:00
loader_snapshot_test.go configload: Configuration snapshots 2018-10-16 18:50:29 -07:00
loader_test.go configs/configload: installation from registry and go-getter 2018-02-15 15:56:39 -08:00
module_manifest.go configs: use addrs.Module for module path, rather than []string 2018-10-16 18:46:46 -07:00
module_mgr.go Add a `CredentialsForHost` method to disco.Disco 2018-08-03 11:29:11 +02:00
source_addr.go configs/configload: installation from registry and go-getter 2018-02-15 15:56:39 -08:00
testing.go configload: helper functions for tests 2018-10-16 18:24:47 -07:00