From 73abb6e8f4574e5ed2a3f24be924f22786baed22 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sun, 14 Oct 2018 15:33:30 -0700 Subject: [PATCH] command: Re-enable showing outputs after successful "apply" We temporarily disabled this because it needed some further work to update it for the new state models, which has now been done. We no longer need the configuration objects for the outputs because the state itself contains all of the information needed for displaying these. --- command/apply.go | 24 ++++++------------------ command/output.go | 2 +- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/command/apply.go b/command/apply.go index 5c68f36e6..4b96781bc 100644 --- a/command/apply.go +++ b/command/apply.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/config/hcl2shim" - "github.com/hashicorp/terraform/configs" "github.com/hashicorp/terraform/repl" "github.com/hashicorp/terraform/states" "github.com/hashicorp/terraform/tfdiags" @@ -201,18 +200,9 @@ func (c *ApplyCommand) Run(args []string) int { } if !c.Destroy { - // TODO: Print outputs, once this is updated to use new config types. - /* - // Get the right module that we used. If we ran a plan, then use - // that module. - if plan != nil { - mod = plan.Module - } - - if outputs := outputsAsString(op.State, terraform.RootModulePath, mod.Config().Outputs, true); outputs != "" { - c.Ui.Output(c.Colorize().Color(outputs)) - } - */ + if outputs := outputsAsString(op.State, addrs.RootModuleInstance, true); outputs != "" { + c.Ui.Output(c.Colorize().Color(outputs)) + } } return op.Result.ExitStatus() @@ -342,7 +332,7 @@ Options: return strings.TrimSpace(helpText) } -func outputsAsString(state *states.State, modPath addrs.ModuleInstance, schema map[string]*configs.Output, includeHeader bool) string { +func outputsAsString(state *states.State, modPath addrs.ModuleInstance, includeHeader bool) string { if state == nil { return "" } @@ -371,14 +361,12 @@ func outputsAsString(state *states.State, modPath addrs.ModuleInstance, schema m sort.Strings(ks) for _, k := range ks { - schema, ok := schema[k] - if ok && schema.Sensitive { + v := outputs[k] + if v.Sensitive { outputBuf.WriteString(fmt.Sprintf("%s = \n", k)) continue } - v := outputs[k] - // Our formatter still wants an old-style raw interface{} value, so // for now we'll just shim it. // FIXME: Port the formatter to work with cty.Value directly. diff --git a/command/output.go b/command/output.go index 8d83ce662..b8fed2e2c 100644 --- a/command/output.go +++ b/command/output.go @@ -158,7 +158,7 @@ func (c *OutputCommand) Run(args []string) int { c.Ui.Output(string(jsonOutputs)) return 0 } else { - c.Ui.Output(outputsAsString(state, moduleAddr, nil, false)) + c.Ui.Output(outputsAsString(state, moduleAddr, false)) return 0 } }