command/apply: -init is gone

/cc @pearkes - hurray!
This commit is contained in:
Mitchell Hashimoto 2014-07-26 14:44:05 -07:00
parent 79033f240f
commit 82e7d58250
3 changed files with 6 additions and 39 deletions

View File

@ -19,13 +19,11 @@ type ApplyCommand struct {
}
func (c *ApplyCommand) Run(args []string) int {
var init bool
var statePath, stateOutPath string
args = c.Meta.process(args)
cmdFlags := c.Meta.flagSet("apply")
cmdFlags.BoolVar(&init, "init", false, "init")
cmdFlags.StringVar(&statePath, "state", DefaultStateFilename, "path")
cmdFlags.StringVar(&stateOutPath, "state-out", "", "path")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
@ -59,15 +57,8 @@ func (c *ApplyCommand) Run(args []string) int {
stateOutPath = statePath
}
// The state path to use to generate a plan. If we're initializing
// a new infrastructure, then we don't use a state path.
planStatePath := statePath
if init {
planStatePath = ""
}
// Build the context based on the arguments given
ctx, err := c.Context(configPath, planStatePath, true)
ctx, err := c.Context(configPath, statePath, true)
if err != nil {
c.Ui.Error(err.Error())
return 1
@ -192,11 +183,6 @@ Usage: terraform apply [options] [dir]
Options:
-init If specified, new infrastructure can be built (no
previous state). This is just a safety switch
to prevent accidentally spinning up a new
infrastructure.
-no-color If specified, output won't contain any color.
-state=path Path to read and save state (unless state-out

View File

@ -28,7 +28,6 @@ func TestApply(t *testing.T) {
}
args := []string{
"-init",
"-state", statePath,
testFixturePath("apply"),
}
@ -66,7 +65,6 @@ func TestApply_configInvalid(t *testing.T) {
}
args := []string{
"-init",
"-state", testTempFile(t),
testFixturePath("apply-config-invalid"),
}
@ -102,7 +100,6 @@ func TestApply_defaultState(t *testing.T) {
}
args := []string{
"-init",
testFixturePath("apply"),
}
if code := c.Run(args); code != 0 {
@ -168,7 +165,6 @@ func TestApply_error(t *testing.T) {
}
args := []string{
"-init",
"-state", statePath,
testFixturePath("apply-error"),
}
@ -220,7 +216,6 @@ func TestApply_noArgs(t *testing.T) {
}
args := []string{
"-init",
"-state", statePath,
}
if code := c.Run(args); code != 0 {
@ -373,7 +368,6 @@ func TestApply_shutdown(t *testing.T) {
}()
args := []string{
"-init",
"-state", statePath,
testFixturePath("apply-shutdown"),
}
@ -516,7 +510,6 @@ func TestApply_vars(t *testing.T) {
}
args := []string{
"-init",
"-var", "foo=bar",
"-state", statePath,
testFixturePath("apply-vars"),
@ -559,7 +552,6 @@ func TestApply_varFile(t *testing.T) {
}
args := []string{
"-init",
"-var-file", varFilePath,
"-state", statePath,
testFixturePath("apply-vars"),

View File

@ -59,26 +59,15 @@ func (m *Meta) Context(path, statePath string, doPlan bool) (*terraform.Context,
}
}
if statePath != "" {
if _, err := os.Stat(statePath); err != nil {
return nil, fmt.Errorf(
"There was an error reading the state file. The path\n"+
"and error are shown below. If you're trying to build a\n"+
"brand new infrastructure, explicitly pass the '-init'\n"+
"flag to Terraform to tell it it is okay to build new\n"+
"state.\n\n"+
"Path: %s\n"+
"Error: %s",
statePath,
err)
}
}
// Load up the state
var state *terraform.State
if statePath != "" {
f, err := os.Open(statePath)
if err == nil {
if err != nil && os.IsNotExist(err) {
// If the state file doesn't exist, it is okay, since it
// is probably a new infrastructure.
err = nil
} else if err == nil {
state, err = terraform.ReadState(f)
f.Close()
}