From b428746cfdbbb57841f9b50f3263dfeb708ce6ed Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 4 Sep 2018 16:51:22 -0700 Subject: [PATCH] command: UiHook to report when it gets incorrect values For PreApply hook purposes we only actually use the Delete, Create, and Update actions, because other actions are handled in different ways than a direct call to ApplyResourceChange. However, if there's a bug in core that causes it to pass a different action, it's better for us to mark it as being explicitly unknown in the UI rather than simply defaulting to "Modifying...", which can thus obscure the problem and make for a confusing result. --- command/hook_ui.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/command/hook_ui.go b/command/hook_ui.go index 9c94a5077..e90573042 100644 --- a/command/hook_ui.go +++ b/command/hook_ui.go @@ -64,6 +64,11 @@ const ( func (h *UiHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (terraform.HookAction, error) { h.once.Do(h.init) + dispAddr := addr.String() + if gen != states.CurrentGen { + dispAddr = fmt.Sprintf("%s (%s)", dispAddr, gen) + } + var operation string var op uiResourceOp switch action { @@ -73,9 +78,14 @@ func (h *UiHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, case plans.Create: operation = "Creating..." op = uiResourceCreate - default: + case plans.Update: operation = "Modifying..." op = uiResourceModify + default: + // We don't expect any other actions in here, so anything else is a + // bug in the caller but we'll ignore it in order to be robust. + h.ui.Output(fmt.Sprintf("(Unknown action %s for %s)", action, dispAddr)) + return terraform.HookActionContinue, nil } attrBuf := new(bytes.Buffer) @@ -135,7 +145,7 @@ func (h *UiHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, h.ui.Output(h.Colorize.Color(fmt.Sprintf( "[reset][bold]%s: %s%s[reset]%s", - addr, + dispAddr, operation, stateIdSuffix, attrString,