Print destroyed outputs when a stack is destroyed. (#3261)

This commit is contained in:
CyrusNajmabadi 2019-09-24 17:15:46 -07:00 committed by GitHub
parent 6f37982048
commit 0ea50f458e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 23 deletions

View file

@ -329,10 +329,10 @@ func renderDiffResourceOutputsEvent(
if !opts.SuppressOutputs {
// We want to hide same outputs if we're doing a read and the user didn't ask to see
// things that are the same.
hideSames := payload.Metadata.Op == deploy.OpRead && !opts.ShowSameResources
if text := engine.GetResourceOutputsPropertiesString(
payload.Metadata, indent+1, payload.Planning, payload.Debug, refresh, !hideSames); text != "" {
text := engine.GetResourceOutputsPropertiesString(
payload.Metadata, indent+1, payload.Planning,
payload.Debug, refresh, opts.ShowSameResources)
if text != "" {
header := fmt.Sprintf("%v%v--outputs:--%v\n",
payload.Metadata.Op.Color(), engine.GetIndentationString(indent+1), colors.Reset)
fprintfIgnoreError(out, opts.Color.Colorize(header))

View file

@ -739,14 +739,12 @@ func (display *ProgressDisplay) processEndSteps() {
// If we get stack outputs, display them at the end.
var wroteOutputs bool
if display.stackUrn != "" && display.seenStackOutputs && !display.opts.SuppressOutputs {
if display.stackUrn != "" && !display.opts.SuppressOutputs {
stackStep := display.eventUrnToResourceRow[display.stackUrn].Step()
// We want to hide same outputs if we're doing a read and the user didn't ask to see
// things that are the same.
hideSames := stackStep.Op == deploy.OpRead && !display.opts.ShowSameResources
props := engine.GetResourceOutputsPropertiesString(
stackStep, 1, display.isPreview, display.opts.Debug, false /* refresh */, !hideSames)
stackStep, 1, display.isPreview, display.opts.Debug,
false /* refresh */, display.opts.ShowSameResources)
if props != "" {
if !wroteDiagnosticHeader {
display.writeBlankLine()

View file

@ -242,21 +242,34 @@ func PrintObject(
// there is an old snapshot of the resource, differ from the prior old snapshot's output properties.
func GetResourceOutputsPropertiesString(
step StepEventMetadata, indent int, planning, debug, refresh, showSames bool) string {
// We should only print outputs if the outputs are known to be complete. This will be the case if we are
// During the actual update we always show all the outputs for the stack, even if they are unchanged.
if !showSames && !planning && step.URN.Type() == resource.RootStackType {
showSames = true
}
// We should only print outputs for normal resources if the outputs are known to be complete.
// This will be the case if we are:
//
// 1) not doing a preview
// 2) doing a refresh
// 3) doing a read
// 4) doing an import
//
// Technically, 2-4 are the same, since they're all bottoming out at a provider's implementation of Read, but
// the upshot is that either way we're ending up with outputs that are exactly accurate. If we are not sure that we
// are in one of the above states, we shouldn't try to print outputs.
// Technically, 2-4 are the same, since they're all bottoming out at a provider's implementation
// of Read, but the upshot is that either way we're ending up with outputs that are exactly
// accurate. If we are not sure that we are in one of the above states, we shouldn't try to
// print outputs.
//
// Note: we always show the outputs for the stack itself. These are valuable enough to want
// to always see.
if planning {
printOutputDuringPlanning := refresh ||
step.Op == deploy.OpRead ||
step.Op == deploy.OpReadReplacement ||
step.Op == deploy.OpImport ||
step.Op == deploy.OpImportReplacement
step.Op == deploy.OpImportReplacement ||
step.URN.Type() == resource.RootStackType
if !printOutputDuringPlanning {
return ""
}
@ -268,19 +281,18 @@ func GetResourceOutputsPropertiesString(
return ""
}
b := &bytes.Buffer{}
// Only certain kinds of steps have output properties associated with them.
new := step.New
if new == nil || new.Outputs == nil {
return ""
var ins resource.PropertyMap
var outs resource.PropertyMap
if step.New == nil || step.New.Outputs == nil {
ins = make(resource.PropertyMap)
outs = make(resource.PropertyMap)
} else {
ins = step.New.Inputs
outs = step.New.Outputs
}
op := step.Op
// First fetch all the relevant property maps that we may consult.
ins := new.Inputs
outs := new.Outputs
// If there was an old state associated with this step, we may have old outputs. If we do, and if they differ from
// the new outputs, we want to print the diffs.
var outputDiff *resource.ObjectDiff
@ -301,6 +313,8 @@ func GetResourceOutputsPropertiesString(
}
maxkey := maxKey(keys)
b := &bytes.Buffer{}
// Now sort the keys and enumerate each output property in a deterministic order.
for _, k := range keys {
out := outs[k]