diff --git a/command/command_test.go b/command/command_test.go index e867ae45d..a789eebab 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -107,7 +107,7 @@ func testModule(t *testing.T, name string) *module.Tree { t.Fatalf("err: %s", err) } - s := &module.ModuleStorage{ + s := &module.Storage{ StorageDir: tempDir(t), Mode: module.GetModeGet, } diff --git a/command/meta.go b/command/meta.go index 24493116e..b00c80d48 100644 --- a/command/meta.go +++ b/command/meta.go @@ -368,8 +368,8 @@ func (m *Meta) flagSet(n string) *flag.FlagSet { // moduleStorage returns the module.Storage implementation used to store // modules for commands. -func (m *Meta) moduleStorage(root string, mode module.GetMode) *module.ModuleStorage { - return &module.ModuleStorage{ +func (m *Meta) moduleStorage(root string, mode module.GetMode) *module.Storage { + return &module.Storage{ StorageDir: filepath.Join(root, "modules"), Services: m.Services, Ui: m.Ui, diff --git a/config/module/module_test.go b/config/module/module_test.go index cee27bc42..13614736c 100644 --- a/config/module/module_test.go +++ b/config/module/module_test.go @@ -41,7 +41,7 @@ func testConfig(t *testing.T, n string) *config.Config { return c } -func testStorage(t *testing.T) *ModuleStorage { +func testStorage(t *testing.T) *Storage { t.Helper() - return &ModuleStorage{StorageDir: tempDir(t)} + return &Storage{StorageDir: tempDir(t)} } diff --git a/config/module/storage.go b/config/module/storage.go index 9280ce9ae..6bec91be9 100644 --- a/config/module/storage.go +++ b/config/module/storage.go @@ -55,19 +55,23 @@ type moduleRecord struct { registry bool } -// ModuleStorage implements methods to record and fetch metadata about the +// Storage implements methods to record and fetch metadata about the // modules that have been fetched and stored locally. The getter.Storgae // abstraction doesn't provide the information needed to know which versions of // a module have been stored, or their location. -type ModuleStorage struct { +type Storage struct { + // StorageDir is the directory where all modules will be stored. StorageDir string - Services *disco.Disco - Ui cli.Ui - Mode GetMode + // Services is a *Disco which ay have services and credentials pre-loaded. + Services *disco.Disco + // Ui is an optional cli.Ui for user output + Ui cli.Ui + // Mode is the GetMode that will be used for various operations. + Mode GetMode } // loadManifest returns the moduleManifest file from the parent directory. -func (m ModuleStorage) loadManifest() (moduleManifest, error) { +func (m Storage) loadManifest() (moduleManifest, error) { manifest := moduleManifest{} manifestPath := filepath.Join(m.StorageDir, manifestName) @@ -90,7 +94,7 @@ func (m ModuleStorage) loadManifest() (moduleManifest, error) { // root directory. The storage method loads the entire file and rewrites it // each time. This is only done a few times during init, so efficiency is // not a concern. -func (m ModuleStorage) recordModule(rec moduleRecord) error { +func (m Storage) recordModule(rec moduleRecord) error { manifest, err := m.loadManifest() if err != nil { // if there was a problem with the file, we will attempt to write a new @@ -127,7 +131,7 @@ func (m ModuleStorage) recordModule(rec moduleRecord) error { // load the manifest from dir, and return all module versions matching the // provided source. Records with no version info will be skipped, as they need // to be uniquely identified by other means. -func (m ModuleStorage) moduleVersions(source string) ([]moduleRecord, error) { +func (m Storage) moduleVersions(source string) ([]moduleRecord, error) { manifest, err := m.loadManifest() if err != nil { return manifest.Modules, err @@ -144,7 +148,7 @@ func (m ModuleStorage) moduleVersions(source string) ([]moduleRecord, error) { return matching, nil } -func (m ModuleStorage) moduleDir(key string) (string, error) { +func (m Storage) moduleDir(key string) (string, error) { manifest, err := m.loadManifest() if err != nil { return "", err @@ -160,7 +164,7 @@ func (m ModuleStorage) moduleDir(key string) (string, error) { } // return only the root directory of the module stored in dir. -func (m ModuleStorage) getModuleRoot(dir string) (string, error) { +func (m Storage) getModuleRoot(dir string) (string, error) { manifest, err := m.loadManifest() if err != nil { return "", err @@ -176,7 +180,7 @@ func (m ModuleStorage) getModuleRoot(dir string) (string, error) { // record only the Root directory for the module stored at dir. // TODO: remove this compatibility function to store the full moduleRecord. -func (m ModuleStorage) recordModuleRoot(dir, root string) error { +func (m Storage) recordModuleRoot(dir, root string) error { rec := moduleRecord{ Dir: dir, Root: root, @@ -185,7 +189,7 @@ func (m ModuleStorage) recordModuleRoot(dir, root string) error { return m.recordModule(rec) } -func (m ModuleStorage) getStorage(key string, src string) (string, bool, error) { +func (m Storage) getStorage(key string, src string) (string, bool, error) { storage := &getter.FolderStorage{ StorageDir: m.StorageDir, } @@ -213,7 +217,7 @@ func (m ModuleStorage) getStorage(key string, src string) (string, bool, error) } // find a stored module that's not from a registry -func (m ModuleStorage) findModule(key string) (string, error) { +func (m Storage) findModule(key string) (string, error) { if m.Mode == GetModeUpdate { return "", nil } @@ -222,7 +226,7 @@ func (m ModuleStorage) findModule(key string) (string, error) { } // find a registry module -func (m ModuleStorage) findRegistryModule(mSource, constraint string) (moduleRecord, error) { +func (m Storage) findRegistryModule(mSource, constraint string) (moduleRecord, error) { rec := moduleRecord{ Source: mSource, } diff --git a/config/module/testing.go b/config/module/testing.go index 0a78e66d0..6f1ff050d 100644 --- a/config/module/testing.go +++ b/config/module/testing.go @@ -24,7 +24,7 @@ func TestTree(t *testing.T, path string) (*Tree, func()) { } // Get the child modules - s := &ModuleStorage{StorageDir: dir, Mode: GetModeGet} + s := &Storage{StorageDir: dir, Mode: GetModeGet} if err := mod.Load(s); err != nil { t.Fatalf("err: %s", err) return nil, nil diff --git a/config/module/tree.go b/config/module/tree.go index 484c62189..1ed03d07c 100644 --- a/config/module/tree.go +++ b/config/module/tree.go @@ -52,7 +52,7 @@ func NewEmptyTree() *Tree { // We do this dummy load so that the tree is marked as "loaded". It // should never fail because this is just about a no-op. If it does fail // we panic so we can know its a bug. - if err := t.Load(&ModuleStorage{Mode: GetModeGet}); err != nil { + if err := t.Load(&Storage{Mode: GetModeGet}); err != nil { panic(err) } @@ -169,7 +169,7 @@ func (t *Tree) Name() string { // module trees inherently require the configuration to be in a reasonably // sane state: no circular dependencies, proper module sources, etc. A full // suite of validations can be done by running Validate (after loading). -func (t *Tree) Load(s *ModuleStorage) error { +func (t *Tree) Load(s *Storage) error { t.lock.Lock() defer t.lock.Unlock() @@ -196,7 +196,7 @@ func (t *Tree) Load(s *ModuleStorage) error { return nil } -func (t *Tree) getChildren(s *ModuleStorage) (map[string]*Tree, error) { +func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) { children := make(map[string]*Tree) // Go through all the modules and get the directory for them. diff --git a/config/module/tree_test.go b/config/module/tree_test.go index 9470203dc..780023b7d 100644 --- a/config/module/tree_test.go +++ b/config/module/tree_test.go @@ -121,7 +121,7 @@ func TestTreeLoad_duplicate(t *testing.T) { func TestTreeLoad_copyable(t *testing.T) { dir := tempDir(t) - storage := &ModuleStorage{ + storage := &Storage{ StorageDir: dir, Mode: GetModeGet, } @@ -167,7 +167,7 @@ func TestTreeLoad_copyable(t *testing.T) { } tree := NewTree("", cfg) - storage := &ModuleStorage{ + storage := &Storage{ StorageDir: dir2, Mode: GetModeNone, } @@ -287,7 +287,7 @@ func TestTree_recordManifest(t *testing.T) { } defer os.RemoveAll(td) - storage := ModuleStorage{StorageDir: td} + storage := Storage{StorageDir: td} dir := filepath.Join(td, "0131bf0fef686e090b16bdbab4910ddf") @@ -792,7 +792,7 @@ func TestTreeLoad_changeIntermediateSource(t *testing.T) { if err := os.MkdirAll(".terraform/modules", 0777); err != nil { t.Fatal(err) } - storage := &ModuleStorage{StorageDir: ".terraform/modules"} + storage := &Storage{StorageDir: ".terraform/modules"} cfg, err := config.LoadDir("./") if err != nil { t.Fatal(err) diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 20fc0145b..9766ff57a 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -750,7 +750,7 @@ func testModule( } // Load the modules - modStorage := &module.ModuleStorage{ + modStorage := &module.Storage{ StorageDir: filepath.Join(cfgPath, ".tfmodules"), Mode: module.GetModeGet, } diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 56af0ff3a..15e920796 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -96,7 +96,7 @@ func testModule(t *testing.T, name string) *module.Tree { t.Fatalf("err: %s", err) } - s := &module.ModuleStorage{ + s := &module.Storage{ StorageDir: tempDir(t), Mode: module.GetModeGet, } @@ -146,7 +146,7 @@ func testModuleInline(t *testing.T, config map[string]string) *module.Tree { } // Load the modules - modStorage := &module.ModuleStorage{ + modStorage := &module.Storage{ StorageDir: filepath.Join(cfgPath, ".tfmodules"), Mode: module.GetModeGet, }