Don't show plugin init message if there are none

Skip the message and plugin initialization if there are none in the
config.
This commit is contained in:
James Bardin 2017-06-19 10:23:58 -04:00
parent 63d4c0efe1
commit da385c4268
2 changed files with 21 additions and 12 deletions

View File

@ -155,8 +155,7 @@ func (c *InitCommand) Run(args []string) int {
// in which case we choose not to show this.
if conf.Terraform != nil && conf.Terraform.Backend != nil {
c.Ui.Output(c.Colorize().Color(fmt.Sprintf(
"[reset][bold]" +
"Initializing the backend...")))
"\n[reset][bold]Initializing the backend...")))
}
opts := &BackendOpts{
@ -185,10 +184,6 @@ func (c *InitCommand) Run(args []string) int {
return 1
}
c.Ui.Output(c.Colorize().Color(
"[reset][bold]Initializing provider plugins...",
))
err = c.getProviders(path, sMgr.State(), flagUpgrade)
if err != nil {
// this function provides its own output
@ -229,7 +224,17 @@ func (c *InitCommand) getProviders(path string, state *terraform.State, upgrade
} else {
available = c.providerPluginSet()
}
requirements := terraform.ModuleTreeDependencies(mod, state).AllPluginRequirements()
if len(requirements) == 0 {
// nothing to initialize
return nil
}
c.Ui.Output(c.Colorize().Color(
"\n[reset][bold]Initializing provider plugins...",
))
missing := c.missingPlugins(available, requirements)
var errs error

View File

@ -4,12 +4,10 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"io"
"os"
"path/filepath"
"reflect"
"runtime"
"sort"
"strings"
"testing"
@ -123,15 +121,21 @@ func TestPush_goodBackendInit(t *testing.T) {
// Expected weird behavior, doesn't affect unpackaging
".terraform/",
".terraform/",
".terraform/plugins/",
fmt.Sprintf(".terraform/plugins/%s_%s/", runtime.GOOS, runtime.GOARCH),
fmt.Sprintf(".terraform/plugins/%s_%s/lock.json", runtime.GOOS, runtime.GOARCH),
// this config contains no plugins
// TODO: we should add one or more plugins to this test config, just to
// verfy the pushed data. The expected additional files are listed below:
//
//".terraform/plugins/",
//fmt.Sprintf(".terraform/plugins/%s_%s/", runtime.GOOS, runtime.GOARCH),
//fmt.Sprintf(".terraform/plugins/%s_%s/lock.json", runtime.GOOS, runtime.GOARCH),
".terraform/terraform.tfstate",
".terraform/terraform.tfstate",
"main.tf",
}
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
t.Fatalf("expected: %#v\ngot: %#v", expected, actual)
}
variables := make(map[string]interface{})