mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
initwd: NewModuleInstaller takes package fetcher as dependency arg
Earlier work started to reshape this API to follow the dependency inversion style, but didn't go so far as treating the package fetcher as an argument because so far it hasn't offered any customizable policy anyway. In future commits we will be introducing some policy arguments for the package fetcher, and so this is some preparation work where we move the responsibility for calling getmodules.NewPackageFetcher() out into the caller of initwd.NewModuleInstaller(). This changes the API consumed by a bunch of unit testing helpers, so splitting this out into its own commit should hopefully make future commits more focused. The module installer now explicitly supports being instantiated without a registry client or a remote package fetcher and will in that case return an error if it's asked to install from anywhere other than local relative directories. Most of our existing tests are comfortable running under that constraint and so will not need any further work in later commits that will change the signature of getmodules.NewPackageFetcher. However, a couple tests in package initwd _itself_ were making use of the esoteric legacy support for treating an absolute filesystem path as a funny sort of remote source, and so for now those will instantiate their own package fetcher. Future commits that change the NewPackageFetcher signature will need to offer a concession for those two tests. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
@@ -96,7 +96,7 @@ func DirFromModule(ctx context.Context, loader *configload.Loader, rootDir, modu
|
||||
}
|
||||
|
||||
instDir := filepath.Join(rootDir, ".terraform/init-from-module")
|
||||
inst := NewModuleInstaller(instDir, loader, reg)
|
||||
inst := NewModuleInstaller(instDir, loader, reg, getmodules.NewPackageFetcher())
|
||||
log.Printf("[DEBUG] installing modules in %s to initialize working directory from %q", instDir, sourceAddrStr)
|
||||
os.RemoveAll(instDir) // if this fails then we'll fail on MkdirAll below too
|
||||
err := os.MkdirAll(instDir, os.ModePerm)
|
||||
|
||||
Reference in New Issue
Block a user