Merge #17218: Add -auto-approve to "terraform destroy" for consistency
This commit is contained in:
commit
6aefa5835c
|
@ -80,7 +80,7 @@ func (b *Local) opApply(
|
||||||
dispPlan := format.NewPlan(plan)
|
dispPlan := format.NewPlan(plan)
|
||||||
trivialPlan := dispPlan.Empty()
|
trivialPlan := dispPlan.Empty()
|
||||||
hasUI := op.UIOut != nil && op.UIIn != nil
|
hasUI := op.UIOut != nil && op.UIIn != nil
|
||||||
mustConfirm := hasUI && ((op.Destroy && !op.DestroyForce) || (!op.Destroy && !op.AutoApprove && !trivialPlan))
|
mustConfirm := hasUI && ((op.Destroy && (!op.DestroyForce && !op.AutoApprove)) || (!op.Destroy && !op.AutoApprove && !trivialPlan))
|
||||||
if mustConfirm {
|
if mustConfirm {
|
||||||
var desc, query string
|
var desc, query string
|
||||||
if op.Destroy {
|
if op.Destroy {
|
||||||
|
|
|
@ -39,13 +39,11 @@ func (c *ApplyCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdFlags := c.Meta.flagSet(cmdName)
|
cmdFlags := c.Meta.flagSet(cmdName)
|
||||||
|
cmdFlags.BoolVar(&autoApprove, "auto-approve", false, "skip interactive approval of plan before applying")
|
||||||
if c.Destroy {
|
if c.Destroy {
|
||||||
cmdFlags.BoolVar(&destroyForce, "force", false, "force")
|
cmdFlags.BoolVar(&destroyForce, "force", false, "deprecated: same as auto-approve")
|
||||||
}
|
}
|
||||||
cmdFlags.BoolVar(&refresh, "refresh", true, "refresh")
|
cmdFlags.BoolVar(&refresh, "refresh", true, "refresh")
|
||||||
if !c.Destroy {
|
|
||||||
cmdFlags.BoolVar(&autoApprove, "auto-approve", false, "skip interactive approval of plan before applying")
|
|
||||||
}
|
|
||||||
cmdFlags.IntVar(
|
cmdFlags.IntVar(
|
||||||
&c.Meta.parallelism, "parallelism", DefaultParallelism, "parallelism")
|
&c.Meta.parallelism, "parallelism", DefaultParallelism, "parallelism")
|
||||||
cmdFlags.StringVar(&c.Meta.statePath, "state", "", "path")
|
cmdFlags.StringVar(&c.Meta.statePath, "state", "", "path")
|
||||||
|
@ -220,8 +218,6 @@ Options:
|
||||||
|
|
||||||
-lock-timeout=0s Duration to retry a state lock.
|
-lock-timeout=0s Duration to retry a state lock.
|
||||||
|
|
||||||
-auto-approve Skip interactive approval of plan before applying.
|
|
||||||
|
|
||||||
-input=true Ask for input for variables if not directly set.
|
-input=true Ask for input for variables if not directly set.
|
||||||
|
|
||||||
-no-color If specified, output won't contain any color.
|
-no-color If specified, output won't contain any color.
|
||||||
|
@ -267,7 +263,9 @@ Options:
|
||||||
modifying. Defaults to the "-state-out" path with
|
modifying. Defaults to the "-state-out" path with
|
||||||
".backup" extension. Set to "-" to disable backup.
|
".backup" extension. Set to "-" to disable backup.
|
||||||
|
|
||||||
-force Don't ask for input for destroy confirmation.
|
-auto-approve Skip interactive approval before destroying.
|
||||||
|
|
||||||
|
-force Deprecated: same as auto-approve.
|
||||||
|
|
||||||
-lock=true Lock the state file when locking is supported.
|
-lock=true Lock the state file when locking is supported.
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ func TestApply_destroy(t *testing.T) {
|
||||||
|
|
||||||
// Run the apply command pointing to our existing state
|
// Run the apply command pointing to our existing state
|
||||||
args := []string{
|
args := []string{
|
||||||
"-force",
|
"-auto-approve",
|
||||||
"-state", statePath,
|
"-state", statePath,
|
||||||
testFixturePath("apply"),
|
testFixturePath("apply"),
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ func TestApply_destroyLockedState(t *testing.T) {
|
||||||
|
|
||||||
// Run the apply command pointing to our existing state
|
// Run the apply command pointing to our existing state
|
||||||
args := []string{
|
args := []string{
|
||||||
"-force",
|
"-auto-approve",
|
||||||
"-state", statePath,
|
"-state", statePath,
|
||||||
testFixturePath("apply"),
|
testFixturePath("apply"),
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ func TestApply_destroyTargeted(t *testing.T) {
|
||||||
|
|
||||||
// Run the apply command pointing to our existing state
|
// Run the apply command pointing to our existing state
|
||||||
args := []string{
|
args := []string{
|
||||||
"-force",
|
"-auto-approve",
|
||||||
"-target", "test_instance.foo",
|
"-target", "test_instance.foo",
|
||||||
"-state", statePath,
|
"-state", statePath,
|
||||||
testFixturePath("apply-destroy-targeted"),
|
testFixturePath("apply-destroy-targeted"),
|
||||||
|
|
|
@ -111,7 +111,7 @@ func TestPrimarySeparatePlan(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//// DESTROY
|
//// DESTROY
|
||||||
stdout, stderr, err = tf.Run("destroy", "-force")
|
stdout, stderr, err = tf.Run("destroy", "-auto-approve")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected destroy error: %s\nstderr:\n%s", err, stderr)
|
t.Fatalf("unexpected destroy error: %s\nstderr:\n%s", err, stderr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ This command accepts all the arguments and flags that the [apply
|
||||||
command](/docs/commands/apply.html) accepts, with the exception of a plan file
|
command](/docs/commands/apply.html) accepts, with the exception of a plan file
|
||||||
argument.
|
argument.
|
||||||
|
|
||||||
If `-force` is set, then the destroy confirmation will not be shown.
|
If `-auto-approve` is set, then the destroy confirmation will not be shown.
|
||||||
|
|
||||||
The `-target` flag, instead of affecting "dependencies" will instead also
|
The `-target` flag, instead of affecting "dependencies" will instead also
|
||||||
destroy any resources that _depend on_ the target(s) specified.
|
destroy any resources that _depend on_ the target(s) specified.
|
||||||
|
|
Loading…
Reference in New Issue