From 67853d8fa8a3b360dccf12a731d29de27ed408a7 Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Wed, 13 Jan 2021 14:58:12 -0500 Subject: [PATCH] Show resource name in taint -allow-missing warning Show the resource name in the warning when allow-missing is used and no resource matches --- command/taint.go | 2 +- command/taint_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/command/taint.go b/command/taint.go index 70d3710df..c53326eb9 100644 --- a/command/taint.go +++ b/command/taint.go @@ -267,7 +267,7 @@ func (c *TaintCommand) allowMissingExit(name addrs.AbsResourceInstance) int { c.showDiagnostics(tfdiags.Sourceless( tfdiags.Warning, "No such resource instance", - "Resource instance %s was not found, but this is not an error because -allow-missing was set.", + fmt.Sprintf("Resource instance %s was not found, but this is not an error because -allow-missing was set.", name), )) return 0 } diff --git a/command/taint_test.go b/command/taint_test.go index e09a0c336..f76d5cc25 100644 --- a/command/taint_test.go +++ b/command/taint_test.go @@ -5,6 +5,7 @@ import ( "strings" "testing" + "github.com/google/go-cmp/cmp" "github.com/mitchellh/cli" "github.com/hashicorp/terraform/addrs" @@ -357,6 +358,18 @@ func TestTaint_missingAllow(t *testing.T) { if code := c.Run(args); code != 0 { t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) } + + // Check for the warning + actual := strings.TrimSpace(ui.ErrorWriter.String()) + expected := strings.TrimSpace(` +Warning: No such resource instance + +Resource instance test_instance.bar was not found, but this is not an error +because -allow-missing was set. +`) + if diff := cmp.Diff(expected, actual); diff != "" { + t.Fatalf("wrong output\n%s", diff) + } } func TestTaint_stateOut(t *testing.T) {