diff --git a/command/init.go b/command/init.go index 995ec6179..b81109ec2 100644 --- a/command/init.go +++ b/command/init.go @@ -71,10 +71,11 @@ func (c *InitCommand) Run(args []string) int { c.getPlugins = false } - // set getProvider if we don't have a test version already + // set providerInstaller if we don't have a test version already if c.providerInstaller == nil { c.providerInstaller = &discovery.ProviderInstaller{ - Dir: c.pluginDir(), + Dir: c.pluginDir(), + Cache: c.pluginCache(), PluginProtocolVersion: plugin.Handshake.ProtocolVersion, SkipVerify: !flagVerifyPlugins, Ui: c.Ui, diff --git a/command/meta.go b/command/meta.go index 8028c3fe6..4412929c7 100644 --- a/command/meta.go +++ b/command/meta.go @@ -55,6 +55,10 @@ type Meta struct { // the specific commands being run. RunningInAutomation bool + // PluginCacheDir, if non-empty, enables caching of downloaded plugins + // into the given directory. + PluginCacheDir string + //---------------------------------------------------------- // Protected: commands can set these //---------------------------------------------------------- diff --git a/command/plugins.go b/command/plugins.go index ce26b0f85..ba034a2a9 100644 --- a/command/plugins.go +++ b/command/plugins.go @@ -168,6 +168,17 @@ func (m *Meta) pluginDirs(includeAutoInstalled bool) []string { return dirs } +func (m *Meta) pluginCache() discovery.PluginCache { + dir := m.PluginCacheDir + if dir == "" { + return nil // cache disabled + } + + dir = filepath.Join(dir, pluginMachineName) + + return discovery.NewLocalPluginCache(dir) +} + // providerPluginSet returns the set of valid providers that were discovered in // the defined search paths. func (m *Meta) providerPluginSet() discovery.PluginMetaSet {