Skip to content

Commit

Permalink
Show resource name in taint -allow-missing warning
Browse files Browse the repository at this point in the history
Show the resource name in the warning when allow-missing
is used and no resource matches
  • Loading branch information
pselle committed Jan 13, 2021
1 parent 61f9d21 commit 67853d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion command/taint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 13 additions & 0 deletions command/taint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@ import (
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/mitchellh/cli"

"github.com/hashicorp/terraform/addrs"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 67853d8

Please sign in to comment.