command: destroy should ask for confirmation always
This commit is contained in:
parent
94f43ff145
commit
a5f70ead2d
|
@ -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.
|
||||
|
||||
|
|
|
@ -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"),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue