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
This commit is contained in:
Pam Selle 2021-01-12 13:21:25 -05:00
parent 52c77ba33e
commit 9371b60d71
2 changed files with 4 additions and 3 deletions

View File

@ -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

View File

@ -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()