diff --git a/command/plan.go b/command/plan.go index c9a275ade..e15f11aca 100644 --- a/command/plan.go +++ b/command/plan.go @@ -61,7 +61,7 @@ func (c *PlanCommand) Run(args []string) int { // This is going to keep track of shadow errors var shadowErr error - ctx, _, err := c.Context(contextOpts{ + ctx, planned, err := c.Context(contextOpts{ Destroy: destroy, Path: path, StatePath: c.Meta.statePath, @@ -71,6 +71,13 @@ func (c *PlanCommand) Run(args []string) int { c.Ui.Error(err.Error()) 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) if err != nil { diff --git a/command/plan_test.go b/command/plan_test.go index c4af9c141..c3805af62 100644 --- a/command/plan_test.go +++ b/command/plan_test.go @@ -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) { originalState := &terraform.State{ Modules: []*terraform.ModuleState{