command: error if variables present when creating context from plan
This commit is contained in:
parent
17d085b13a
commit
79033f240f
|
@ -288,6 +288,31 @@ func TestApply_plan(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestApply_planVars(t *testing.T) {
|
||||
planPath := testPlanFile(t, &terraform.Plan{
|
||||
Config: new(config.Config),
|
||||
})
|
||||
statePath := testTempFile(t)
|
||||
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &ApplyCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state", statePath,
|
||||
"-var", "foo=bar",
|
||||
planPath,
|
||||
}
|
||||
if code := c.Run(args); code == 0 {
|
||||
t.Fatal("should've failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestApply_shutdown(t *testing.T) {
|
||||
stopped := false
|
||||
stopCh := make(chan struct{})
|
||||
|
|
|
@ -47,6 +47,14 @@ func (m *Meta) Context(path, statePath string, doPlan bool) (*terraform.Context,
|
|||
plan, err := terraform.ReadPlan(f)
|
||||
f.Close()
|
||||
if err == nil {
|
||||
if len(m.variables) > 0 {
|
||||
return nil, fmt.Errorf(
|
||||
"You can't set variables with the '-var' or '-var-file' flag\n" +
|
||||
"when you're applying a plan file. The variables used when\n" +
|
||||
"the plan was created will be used. If you wish to use different\n" +
|
||||
"variable values, create a new plan file.")
|
||||
}
|
||||
|
||||
return plan.Context(opts), nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue