command/plan: user friendly error if plan file given to plan command
This commit is contained in:
parent
92faace610
commit
7f87a0109b
|
@ -61,7 +61,7 @@ func (c *PlanCommand) Run(args []string) int {
|
||||||
// This is going to keep track of shadow errors
|
// This is going to keep track of shadow errors
|
||||||
var shadowErr error
|
var shadowErr error
|
||||||
|
|
||||||
ctx, _, err := c.Context(contextOpts{
|
ctx, planned, err := c.Context(contextOpts{
|
||||||
Destroy: destroy,
|
Destroy: destroy,
|
||||||
Path: path,
|
Path: path,
|
||||||
StatePath: c.Meta.statePath,
|
StatePath: c.Meta.statePath,
|
||||||
|
@ -71,6 +71,13 @@ func (c *PlanCommand) Run(args []string) int {
|
||||||
c.Ui.Error(err.Error())
|
c.Ui.Error(err.Error())
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
if planned {
|
||||||
|
c.Ui.Error(
|
||||||
|
"The plan command cannot be called with a saved plan file.\n\n" +
|
||||||
|
"The plan command expects a configuration directory as an argument.",
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
err = terraform.SetDebugInfo(DefaultDataDir)
|
err = terraform.SetDebugInfo(DefaultDataDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -37,6 +37,29 @@ func TestPlan(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPlan_plan(t *testing.T) {
|
||||||
|
tmp, cwd := testCwd(t)
|
||||||
|
defer testFixCwd(t, tmp, cwd)
|
||||||
|
|
||||||
|
planPath := testPlanFile(t, &terraform.Plan{
|
||||||
|
Module: testModule(t, "apply"),
|
||||||
|
})
|
||||||
|
|
||||||
|
p := testProvider()
|
||||||
|
ui := new(cli.MockUi)
|
||||||
|
c := &PlanCommand{
|
||||||
|
Meta: Meta{
|
||||||
|
ContextOpts: testCtxConfig(p),
|
||||||
|
Ui: ui,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{planPath}
|
||||||
|
if code := c.Run(args); code != 1 {
|
||||||
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPlan_destroy(t *testing.T) {
|
func TestPlan_destroy(t *testing.T) {
|
||||||
originalState := &terraform.State{
|
originalState := &terraform.State{
|
||||||
Modules: []*terraform.ModuleState{
|
Modules: []*terraform.ModuleState{
|
||||||
|
|
Loading…
Reference in New Issue