From a5f70ead2dcd18c4ec08767b3b642b1e51acb6b9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Oct 2014 16:08:50 -0700 Subject: [PATCH] command: destroy should ask for confirmation always --- command/apply.go | 40 ++++++++++++++++++----------------- command/apply_destroy_test.go | 1 + 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/command/apply.go b/command/apply.go index 4216bcac0..1870aad88 100644 --- a/command/apply.go +++ b/command/apply.go @@ -26,7 +26,7 @@ type ApplyCommand struct { } func (c *ApplyCommand) Run(args []string) int { - var refresh bool + var destroyForce, refresh bool var statePath, stateOutPath, backupPath string args = c.Meta.process(args, true) @@ -37,6 +37,9 @@ func (c *ApplyCommand) Run(args []string) int { } cmdFlags := c.Meta.flagSet(cmdName) + if c.Destroy { + cmdFlags.BoolVar(&destroyForce, "force", false, "force") + } cmdFlags.BoolVar(&refresh, "refresh", true, "refresh") cmdFlags.StringVar(&statePath, "state", DefaultStateFilename, "path") cmdFlags.StringVar(&stateOutPath, "state-out", "", "path") @@ -114,24 +117,23 @@ func (c *ApplyCommand) Run(args []string) int { "Destroy can't be called with a plan file.")) return 1 } - if c.InputEnabled() { - if c.Destroy { - v, err := c.UIInput().Input(&terraform.InputOpts{ - Id: "destroy", - Query: "Do you really want to destroy?", - Description: "Terraform will delete all your manage infrastructure.\n" + - "There is no undo. Only 'yes' will be accepted to confirm.", - }) - if err != nil { - c.Ui.Error(fmt.Sprintf("Error asking for confirmation: %s", err)) - return 1 - } - if v != "yes" { - c.Ui.Output("Destroy cancelled.") - return 1 - } + if !destroyForce && c.Destroy { + v, err := c.UIInput().Input(&terraform.InputOpts{ + Id: "destroy", + Query: "Do you really want to destroy?", + Description: "Terraform will delete all your manage infrastructure.\n" + + "There is no undo. Only 'yes' will be accepted to confirm.", + }) + if err != nil { + c.Ui.Error(fmt.Sprintf("Error asking for confirmation: %s", err)) + return 1 } - + if v != "yes" { + c.Ui.Output("Destroy cancelled.") + return 1 + } + } + if c.InputEnabled() { if !planned { if err := ctx.Input(); err != nil { c.Ui.Error(fmt.Sprintf("Error configuring: %s", err)) @@ -362,7 +364,7 @@ Options: modifying. Defaults to the "-state-out" path with ".backup" extension. Set to "-" to disable backup. - -input=true Ask for input for destroy confirmation. + -force Don't ask for input for destroy confirmation. -no-color If specified, output won't contain any color. diff --git a/command/apply_destroy_test.go b/command/apply_destroy_test.go index bde8c888c..bdc2440f0 100644 --- a/command/apply_destroy_test.go +++ b/command/apply_destroy_test.go @@ -40,6 +40,7 @@ func TestApply_destroy(t *testing.T) { // Run the apply command pointing to our existing state args := []string{ + "-force", "-state", statePath, testFixturePath("apply"), }