update init output

Change "Downloading" to 'Initializing" to match the provider loading
dialog.

List each module being loaded.

If a regisry module is being downloaded, list the registry host, and the
version discovered.

Show the source string from the config that is being fetched, rather
than the go-getter url. The full source can be found in the logs for
debugging.

Add much more extensive logging
This commit is contained in:
James Bardin 2017-11-02 18:53:05 -04:00
parent 002200b8f1
commit 9c334fe012
4 changed files with 46 additions and 26 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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,21 +250,21 @@ 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.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.
// Terraform keeps the entire requested tree, so that modules can
@ -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