Merge pull request #27609 from hashicorp/alisdair/remove-output-module-option

cli: Remove dead code for output -module flag
This commit is contained in:
Alisdair McDiarmid 2021-01-27 15:51:27 -05:00 committed by GitHub
commit 7cb5685037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 67 deletions

View File

@ -6,7 +6,6 @@ import (
"sort"
"strings"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/repl"
"github.com/hashicorp/terraform/states"
@ -178,7 +177,7 @@ func (c *ApplyCommand) Run(args []string) int {
}
if !c.Destroy {
if outputs := outputsAsString(op.State, addrs.RootModuleInstance, true); outputs != "" {
if outputs := outputsAsString(op.State, true); outputs != "" {
c.Ui.Output(c.Colorize().Color(outputs))
}
}
@ -315,16 +314,12 @@ Options:
return strings.TrimSpace(helpText)
}
func outputsAsString(state *states.State, modPath addrs.ModuleInstance, includeHeader bool) string {
func outputsAsString(state *states.State, includeHeader bool) string {
if state == nil {
return ""
}
ms := state.Module(modPath)
if ms == nil {
return ""
}
ms := state.RootModule()
outputs := ms.OutputValues
outputBuf := new(bytes.Buffer)
if len(outputs) > 0 {

View File

@ -9,7 +9,6 @@ import (
"github.com/zclconf/go-cty/cty/convert"
ctyjson "github.com/zclconf/go-cty/cty/json"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/repl"
"github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/tfdiags"
@ -27,13 +26,12 @@ type OutputCommand struct {
func (c *OutputCommand) Run(args []string) int {
args = c.Meta.process(args)
var module, statePath string
var statePath string
var jsonOutput, rawOutput bool
cmdFlags := c.Meta.defaultFlagSet("output")
cmdFlags.BoolVar(&jsonOutput, "json", false, "json")
cmdFlags.BoolVar(&rawOutput, "raw", false, "raw")
cmdFlags.StringVar(&statePath, "state", "", "path")
cmdFlags.StringVar(&module, "module", "", "module")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
c.Ui.Error(fmt.Sprintf("Error parsing command-line flags: %s\n", err.Error()))
@ -101,35 +99,12 @@ func (c *OutputCommand) Run(args []string) int {
return 1
}
moduleAddr := addrs.RootModuleInstance
if module != "" {
// This option was supported prior to 0.12.0, but no longer supported
// because we only persist the root module outputs in state.
// (We could perhaps re-introduce this by doing an eval walk here to
// repopulate them, similar to how "terraform console" does it, but
// that requires more thought since it would imply this command
// supporting remote operations, which is a big change.)
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Unsupported option",
"The -module option is no longer supported since Terraform 0.12, because now only root outputs are persisted in the state.",
))
c.showDiagnostics(diags)
return 1
}
state := stateStore.State()
if state == nil {
state = states.NewState()
}
mod := state.Module(moduleAddr)
if mod == nil {
c.Ui.Error(fmt.Sprintf(
"The module %s could not be found. There is nothing to output.",
module))
return 1
}
mod := state.RootModule()
if !jsonOutput && (state.Empty() || len(mod.OutputValues) == 0) {
diags = diags.Append(tfdiags.Sourceless(
@ -190,7 +165,7 @@ func (c *OutputCommand) Run(args []string) int {
c.Ui.Output(string(jsonOutputs))
return 0
} else {
c.Ui.Output(outputsAsString(state, moduleAddr, false))
c.Ui.Output(outputsAsString(state, false))
return 0
}
}

View File

@ -268,35 +268,6 @@ func TestOutput_jsonEmptyOutputs(t *testing.T) {
}
}
func TestMissingModuleOutput(t *testing.T) {
originalState := states.BuildState(func(s *states.SyncState) {
s.SetOutputValue(
addrs.OutputValue{Name: "foo"}.Absolute(addrs.RootModuleInstance),
cty.StringVal("bar"),
false,
)
})
statePath := testStateFile(t, originalState)
ui := new(cli.MockUi)
c := &OutputCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(testProvider()),
Ui: ui,
},
}
args := []string{
"-state", statePath,
"-module", "not_existing_module",
"blah",
}
if code := c.Run(args); code != 1 {
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
}
}
func TestOutput_badVar(t *testing.T) {
originalState := states.BuildState(func(s *states.SyncState) {
s.SetOutputValue(

View File

@ -4,7 +4,6 @@ import (
"fmt"
"strings"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/tfdiags"
)
@ -96,7 +95,7 @@ func (c *RefreshCommand) Run(args []string) int {
return op.Result.ExitStatus()
}
if outputs := outputsAsString(op.State, addrs.RootModuleInstance, true); outputs != "" {
if outputs := outputsAsString(op.State, true); outputs != "" {
c.Ui.Output(c.Colorize().Color(outputs))
}