cli: Fix state mv exit code for missing resource (#29839)

This commit is contained in:
Pedro Belém 2022-02-14 20:20:03 +00:00 committed by GitHub
parent 7a20c07cb0
commit aed7162e9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -176,6 +176,8 @@ func (c *StateMvCommand) Run(args []string) int {
msgInvalidSource, msgInvalidSource,
fmt.Sprintf("Cannot move %s: does not match anything in the current state.", sourceAddr), fmt.Sprintf("Cannot move %s: does not match anything in the current state.", sourceAddr),
)) ))
c.showDiagnostics(diags)
return 1
} }
for _, rawAddrFrom := range sourceAddrs { for _, rawAddrFrom := range sourceAddrs {
switch addrFrom := rawAddrFrom.(type) { switch addrFrom := rawAddrFrom.(type) {

View File

@ -1685,6 +1685,34 @@ func TestStateMvHelp(t *testing.T) {
} }
} }
func TestStateMvInvalidSourceAddress(t *testing.T) {
state := states.BuildState(func(s *states.SyncState) {})
statePath := testStateFile(t, state)
p := testProvider()
ui := new(cli.MockUi)
view, _ := testView(t)
c := &StateMvCommand{
StateMeta{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
Ui: ui,
View: view,
},
},
}
args := []string{
"-state", statePath,
"foo.bar1",
"foo.bar2",
}
code := c.Run(args)
if code != 1 {
t.Fatalf("expected error code 1, got:\n%d", code)
}
}
const testStateMvOutputOriginal = ` const testStateMvOutputOriginal = `
test_instance.baz: test_instance.baz:
ID = foo ID = foo