use the new ModuleStorage in the command package

Update the command package to use the new module storage. Move the old
command output strings into the module storage itself. This could be
moved back later either by using ui callbacks, or designing a module
storage interface once we know what the final requirements will look
like.
pull/16481/head
James Bardin 8 years ago
parent 36eb40a432
commit f2a7b94692

@ -19,7 +19,6 @@ import (
"syscall"
"testing"
"github.com/hashicorp/go-getter"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/helper/logging"
"github.com/hashicorp/terraform/terraform"
@ -108,8 +107,11 @@ func testModule(t *testing.T, name string) *module.Tree {
t.Fatalf("err: %s", err)
}
s := &getter.FolderStorage{StorageDir: tempDir(t)}
if err := mod.Load(s, module.GetModeGet); err != nil {
s := &module.ModuleStorage{
StorageDir: tempDir(t),
Mode: module.GetModeGet,
}
if err := mod.Load(s); err != nil {
t.Fatalf("err: %s", err)
}

@ -81,7 +81,7 @@ func getModules(m *Meta, path string, mode module.GetMode) error {
return fmt.Errorf("Error loading configuration: %s", err)
}
err = mod.Load(m.moduleStorage(m.DataDir()), mode)
err = mod.Load(m.moduleStorage(m.DataDir(), mode))
if err != nil {
return fmt.Errorf("Error loading modules: %s", err)
}

@ -16,11 +16,11 @@ import (
"strings"
"time"
"github.com/hashicorp/go-getter"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/backend/local"
"github.com/hashicorp/terraform/command/format"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/module"
"github.com/hashicorp/terraform/helper/experiment"
"github.com/hashicorp/terraform/helper/variables"
"github.com/hashicorp/terraform/helper/wrappedstreams"
@ -368,12 +368,12 @@ 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) getter.Storage {
return &uiModuleStorage{
Storage: &getter.FolderStorage{
StorageDir: filepath.Join(root, "modules"),
},
Ui: m.Ui,
func (m *Meta) moduleStorage(root string, mode module.GetMode) *module.ModuleStorage {
return &module.ModuleStorage{
StorageDir: filepath.Join(root, "modules"),
Services: m.Services,
Ui: m.Ui,
Mode: mode,
}
}

@ -45,7 +45,7 @@ func (m *Meta) Module(path string) (*module.Tree, error) {
return nil, err
}
err = mod.Load(m.moduleStorage(m.DataDir()), module.GetModeNone)
err = mod.Load(m.moduleStorage(m.DataDir(), module.GetModeNone))
if err != nil {
return nil, errwrap.Wrapf("Error loading modules: {{err}}", err)
}

@ -1,29 +0,0 @@
package command
import (
"fmt"
"github.com/hashicorp/go-getter"
"github.com/mitchellh/cli"
)
// uiModuleStorage implements module.Storage and is just a proxy to output
// to the UI any Get operations.
type uiModuleStorage struct {
Storage getter.Storage
Ui cli.Ui
}
func (s *uiModuleStorage) Dir(key string) (string, bool, error) {
return s.Storage.Dir(key)
}
func (s *uiModuleStorage) Get(key string, source string, update bool) error {
updateStr := ""
if update {
updateStr = " (update)"
}
s.Ui.Output(fmt.Sprintf("Get: %s%s", source, updateStr))
return s.Storage.Get(key, source, update)
}

@ -1,11 +0,0 @@
package command
import (
"testing"
"github.com/hashicorp/go-getter"
)
func TestUiModuleStorage_impl(t *testing.T) {
var _ getter.Storage = new(uiModuleStorage)
}

@ -190,6 +190,14 @@ func (m ModuleStorage) getStorage(key string, src string) (string, bool, error)
StorageDir: m.StorageDir,
}
if m.Ui != nil {
update := ""
if m.Mode == GetModeUpdate {
update = " (update)"
}
m.Ui.Output(fmt.Sprintf("Get: %s%s", src, update))
}
// Get the module with the level specified if we were told to.
if m.Mode > GetModeNone {
log.Printf("[DEBUG] fetching %q with key %q", src, key)

@ -15,7 +15,6 @@ import (
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/go-getter"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/logutils"
"github.com/hashicorp/terraform/config/module"
@ -751,10 +750,11 @@ func testModule(
}
// Load the modules
modStorage := &getter.FolderStorage{
modStorage := &module.ModuleStorage{
StorageDir: filepath.Join(cfgPath, ".tfmodules"),
Mode: module.GetModeGet,
}
err = mod.Load(modStorage, module.GetModeGet)
err = mod.Load(modStorage)
if err != nil {
return nil, fmt.Errorf("Error downloading modules: %s", err)
}

Loading…
Cancel
Save