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

View File

@ -4,12 +4,10 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime"
"sort" "sort"
"strings" "strings"
"testing" "testing"
@ -123,15 +121,21 @@ func TestPush_goodBackendInit(t *testing.T) {
// Expected weird behavior, doesn't affect unpackaging // Expected weird behavior, doesn't affect unpackaging
".terraform/", ".terraform/",
".terraform/", ".terraform/",
".terraform/plugins/",
fmt.Sprintf(".terraform/plugins/%s_%s/", runtime.GOOS, runtime.GOARCH), // this config contains no plugins
fmt.Sprintf(".terraform/plugins/%s_%s/lock.json", runtime.GOOS, runtime.GOARCH), // 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",
".terraform/terraform.tfstate", ".terraform/terraform.tfstate",
"main.tf", "main.tf",
} }
if !reflect.DeepEqual(actual, expected) { if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual) t.Fatalf("expected: %#v\ngot: %#v", expected, actual)
} }
variables := make(map[string]interface{}) variables := make(map[string]interface{})