cli: Fix state mv exit code for missing resource (#29839)
This commit is contained in:
parent
7a20c07cb0
commit
aed7162e9a
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue