From 9371b60d71e69d03d9ec643bdfb88a499a3ed76e Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Tue, 12 Jan 2021 13:21:25 -0500 Subject: [PATCH] More verbose error for whole resource move failure When running state mv with a resource source, but the destination fails, provide a hint that the source is a resource (not an instance) in case the user means to address it this way --- command/state_mv.go | 2 +- command/state_mv_test.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/command/state_mv.go b/command/state_mv.go index 818811ddf8..20282382a0 100644 --- a/command/state_mv.go +++ b/command/state_mv.go @@ -184,7 +184,7 @@ func (c *StateMvCommand) Run(args []string) int { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, msgInvalidTarget, - fmt.Sprintf("Cannot move %s to %s: the target must also be a whole resource.", addrFrom, destAddr), + fmt.Sprintf("Cannot move %s to %s: the source is a whole resource (not a resource instance) so the target must also be a whole resource.", addrFrom, destAddr), )) c.showDiagnostics(diags) return 1 diff --git a/command/state_mv_test.go b/command/state_mv_test.go index 558246b5c9..b9c21e5b76 100644 --- a/command/state_mv_test.go +++ b/command/state_mv_test.go @@ -293,8 +293,9 @@ func TestStateMv_resourceToInstanceErr(t *testing.T) { expectedErr := ` Error: Invalid target address -Cannot move test_instance.foo to test_instance.bar[0]: the target must also be -a whole resource. +Cannot move test_instance.foo to test_instance.bar[0]: the source is a whole +resource (not a resource instance) so the target must also be a whole +resource. ` errOutput := ui.ErrorWriter.String()