diff --git a/command/init.go b/command/init.go index 03e7df9ca9..d2fd632057 100644 --- a/command/init.go +++ b/command/init.go @@ -172,7 +172,7 @@ func (c *InitCommand) Run(args []string) int { "[reset][bold]Upgrading modules..."))) } else { c.Ui.Output(c.Colorize().Color(fmt.Sprintf( - "[reset][bold]Downloading modules..."))) + "[reset][bold]Initializing modules..."))) } if err := getModules(&c.Meta, path, getMode); err != nil { diff --git a/config/module/registry.go b/config/module/registry.go index bef8b33739..10209c4bfa 100644 --- a/config/module/registry.go +++ b/config/module/registry.go @@ -123,6 +123,12 @@ func (s *Storage) lookupModuleVersions(module *regsrc.Module) (*response.ModuleV return nil, err } + for _, mod := range versions.Modules { + for _, v := range mod.Versions { + log.Printf("[DEBUG] found available version %q for %s", v.Version, mod.Source) + } + } + return &versions, nil } diff --git a/config/module/storage.go b/config/module/storage.go index 730376c62e..381650ea84 100644 --- a/config/module/storage.go +++ b/config/module/storage.go @@ -160,6 +160,7 @@ func (s Storage) moduleVersions(source string) ([]moduleRecord, error) { for _, m := range manifest.Modules { if m.Source == source && m.Version != "" { + log.Printf("[DEBUG] found local version %q for module %s", m.Version, m.Source) matching = append(matching, m) } } @@ -207,18 +208,19 @@ func (s Storage) recordModuleRoot(dir, root string) error { return s.recordModule(rec) } +func (s Storage) output(msg string) { + if s.Ui == nil || s.Mode == GetModeNone { + return + } + s.Ui.Output(msg) +} + func (s Storage) getStorage(key string, src string) (string, bool, error) { storage := &getter.FolderStorage{ StorageDir: s.StorageDir, } - if s.Ui != nil { - update := "" - if s.Mode == GetModeUpdate { - update = " (update)" - } - s.Ui.Output(fmt.Sprintf("Get: %s%s", src, update)) - } + log.Printf("[DEBUG] fetching module from %s", src) // Get the module with the level specified if we were told to. if s.Mode > GetModeNone { @@ -307,6 +309,7 @@ func (s Storage) findRegistryModule(mSource, constraint string) (moduleRecord, e if err != nil { log.Printf("[INFO] no matching version for %q<%s>, %s", mod.Module(), constraint, err) } + log.Printf("[DEBUG] matched %q version %s for %s", mod, match.Version, constraint) rec.Dir = match.Dir rec.Version = match.Version @@ -339,6 +342,9 @@ func (s Storage) findRegistryModule(mSource, constraint string) (moduleRecord, e if err != nil { return rec, err } + + s.output(fmt.Sprintf(" Found version %q of %s on %s", rec.Version, mod.Module(), mod.RawHost.Display())) + } return rec, nil } diff --git a/config/module/tree.go b/config/module/tree.go index 8deaf2d254..30c39597b6 100644 --- a/config/module/tree.go +++ b/config/module/tree.go @@ -5,6 +5,7 @@ import ( "bytes" "fmt" "log" + "path" "path/filepath" "strings" "sync" @@ -207,12 +208,16 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) { } // Determine the path to this child - path := make([]string, len(t.path), len(t.path)+1) - copy(path, t.path) - path = append(path, m.Name) + modPath := make([]string, len(t.path), len(t.path)+1) + copy(modPath, t.path) + modPath = append(modPath, m.Name) log.Printf("[TRACE] module source: %q", m.Source) + // add the module path to help indicate where modules with relative + // paths are being loaded from + s.output(fmt.Sprintf("- Module %q", path.Join(modPath...))) + // Lookup the local location of the module. // dir is the local directory where the module is stored mod, err := s.findRegistryModule(m.Source, m.Version) @@ -236,7 +241,7 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) { } } - if mod.Dir != "" { + if mod.Dir != "" && s.Mode != GetModeUpdate { // We found it locally, but in order to load the Tree we need to // find out if there was another subDir stored from detection. subDir, err := s.getModuleRoot(mod.Dir) @@ -245,20 +250,20 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) { // recordSubdir method fix it up. Any other filesystem errors // will turn up again below. log.Println("[WARN] error reading subdir record:", err) - } else { - fullDir := filepath.Join(mod.Dir, subDir) + } - child, err := NewTreeModule(m.Name, fullDir) - if err != nil { - return nil, fmt.Errorf("module %s: %s", m.Name, err) - } - child.path = path - child.parent = t - child.version = mod.Version - child.source = m.Source - children[m.Name] = child - continue + fullDir := filepath.Join(mod.Dir, subDir) + + child, err := NewTreeModule(m.Name, fullDir) + if err != nil { + return nil, fmt.Errorf("module %s: %s", m.Name, err) } + child.path = modPath + child.parent = t + child.version = mod.Version + child.source = m.Source + children[m.Name] = child + continue } // Split out the subdir if we have one. @@ -286,6 +291,9 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) { subDir = filepath.Join(detectedSubDir, subDir) } + output := fmt.Sprintf(" Getting source %q", m.Source) + s.output(output) + dir, ok, err := s.getStorage(key, source) if err != nil { return nil, err @@ -325,7 +333,7 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) { if err != nil { return nil, fmt.Errorf("module %s: %s", m.Name, err) } - child.path = path + child.path = modPath child.parent = t child.version = mod.Version child.source = m.Source