diff --git a/command/command.go b/command/command.go index ff39478ec..89ada2e37 100644 --- a/command/command.go +++ b/command/command.go @@ -19,6 +19,10 @@ const DefaultVarsFilename = "terraform.tfvars" // DefaultBackupExtention is added to the state file to form the path const DefaultBackupExtention = ".backup" +// DefaultDataDirectory is the directory where local state is stored +// by default. +const DefaultDataDirectory = ".terraform" + func validateContext(ctx *terraform.Context, ui cli.Ui) bool { if ws, es := ctx.Validate(); len(ws) > 0 || len(es) > 0 { ui.Output( diff --git a/command/get_test.go b/command/get_test.go index e706a7c2a..c3ea4e0ce 100644 --- a/command/get_test.go +++ b/command/get_test.go @@ -14,6 +14,7 @@ func TestGet(t *testing.T) { Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, + dataDir: tempDir(t), }, } @@ -39,6 +40,7 @@ func TestGet_multipleArgs(t *testing.T) { Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, + dataDir: tempDir(t), }, } @@ -66,6 +68,7 @@ func TestGet_noArgs(t *testing.T) { Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, + dataDir: tempDir(t), }, } @@ -89,6 +92,7 @@ func TestGet_update(t *testing.T) { Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, + dataDir: tempDir(t), }, } diff --git a/command/meta.go b/command/meta.go index cb21238b3..7ebffedb4 100644 --- a/command/meta.go +++ b/command/meta.go @@ -27,6 +27,9 @@ type Meta struct { // This can be set by the command itself to provide extra hooks. extraHooks []terraform.Hook + // This can be set by tests to change some directories + dataDir string + // Variables for the context (private) autoKey string autoVariables map[string]string @@ -95,7 +98,12 @@ func (m *Meta) Context(copts contextOpts) (*terraform.Context, bool, error) { if err != nil { return nil, false, fmt.Errorf("Error loading config: %s", err) } - err = mod.Load(m.moduleStorage(copts.Path), copts.GetMode) + + dataDir := DefaultDataDirectory + if m.dataDir != "" { + dataDir = m.dataDir + } + err = mod.Load(m.moduleStorage(dataDir), copts.GetMode) if err != nil { return nil, false, fmt.Errorf("Error downloading modules: %s", err) }