command/plan: user friendly error if plan file given to plan command

This commit is contained in:
Mitchell Hashimoto 2016-12-09 11:34:38 -05:00
parent 92faace610
commit 7f87a0109b
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 31 additions and 1 deletions

View File

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

View File

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