Merge pull request #27502 from hashicorp/pselle/untaint-missing

Add name to untaint missing warning
This commit is contained in:
Pam Selle 2021-01-14 10:04:39 -05:00 committed by GitHub
commit 4ffacc8d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -236,7 +236,7 @@ func (c *UntaintCommand) allowMissingExit(name addrs.AbsResourceInstance) int {
c.showDiagnostics(tfdiags.Sourceless( c.showDiagnostics(tfdiags.Sourceless(
tfdiags.Warning, tfdiags.Warning,
"No such resource instance", "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 return 0
} }

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/states" "github.com/hashicorp/terraform/states"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
@ -385,6 +386,18 @@ func TestUntaint_missingAllow(t *testing.T) {
if code := c.Run(args); code != 0 { if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) 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 TestUntaint_stateOut(t *testing.T) { func TestUntaint_stateOut(t *testing.T) {