command: destroy should ask for confirmation always

This commit is contained in:
Mitchell Hashimoto 2014-10-03 16:08:50 -07:00
parent 94f43ff145
commit a5f70ead2d
2 changed files with 22 additions and 19 deletions

View File

@ -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,8 +117,7 @@ func (c *ApplyCommand) Run(args []string) int {
"Destroy can't be called with a plan file."))
return 1
}
if c.InputEnabled() {
if c.Destroy {
if !destroyForce && c.Destroy {
v, err := c.UIInput().Input(&terraform.InputOpts{
Id: "destroy",
Query: "Do you really want to destroy?",
@ -131,7 +133,7 @@ func (c *ApplyCommand) Run(args []string) int {
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.

View File

@ -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"),
}