command/*: only Plan on the Apply

This commit is contained in:
Mitchell Hashimoto 2014-07-14 11:48:03 -07:00
parent ad3c0593a3
commit 6c8c09c784
5 changed files with 9 additions and 7 deletions

View File

@ -64,7 +64,7 @@ func (c *ApplyCommand) Run(args []string) int {
}
// Build the context based on the arguments given
ctx, err := c.Context(configPath, planStatePath)
ctx, err := c.Context(configPath, planStatePath, true)
if err != nil {
c.Ui.Error(err.Error())
return 1

View File

@ -40,7 +40,7 @@ func (c *GraphCommand) Run(args []string) int {
}
}
ctx, err := c.Context(path, "")
ctx, err := c.Context(path, "", false)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error loading Terraform: %s", err))
return 1

View File

@ -30,7 +30,7 @@ func (m *Meta) Colorize() *colorstring.Colorize {
// Context returns a Terraform Context taking into account the context
// options used to initialize this meta configuration.
func (m *Meta) Context(path, statePath string) (*terraform.Context, error) {
func (m *Meta) Context(path, statePath string, doPlan bool) (*terraform.Context, error) {
opts := m.contextOpts()
// First try to just read the plan directly from the path given.
@ -84,8 +84,10 @@ func (m *Meta) Context(path, statePath string) (*terraform.Context, error) {
opts.State = state
ctx := terraform.NewContext(opts)
if _, err := ctx.Plan(nil); err != nil {
return nil, fmt.Errorf("Error running plan: %s", err)
if doPlan {
if _, err := ctx.Plan(nil); err != nil {
return nil, fmt.Errorf("Error running plan: %s", err)
}
}
return ctx, nil

View File

@ -59,7 +59,7 @@ func (c *PlanCommand) Run(args []string) int {
}
}
ctx, err := c.Context(path, statePath)
ctx, err := c.Context(path, statePath, false)
if err != nil {
c.Ui.Error(err.Error())
return 1

View File

@ -78,7 +78,7 @@ func (c *RefreshCommand) Run(args []string) int {
}
// Build the context based on the arguments given
ctx, err := c.Context(configPath, statePath)
ctx, err := c.Context(configPath, statePath, false)
if err != nil {
c.Ui.Error(err.Error())
return 1