cli: Fix overly broad auto-approve argument
The auto-approve argument was part of the arguments.Operation type, which resulted in adding a silent -auto-approve flag to plan and refresh. This was unintended, and is fixed in this commit by moving the flag to the arguments.Apply type and updating the downstream callers.
This commit is contained in:
parent
8d9a08e3a1
commit
b7f54b30d5
|
@ -89,7 +89,7 @@ func (c *ApplyCommand) Run(rawArgs []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the operation request
|
// Build the operation request
|
||||||
opReq, opDiags := c.OperationRequest(be, view, planFile, args.Operation)
|
opReq, opDiags := c.OperationRequest(be, view, planFile, args.Operation, args.AutoApprove)
|
||||||
diags = diags.Append(opDiags)
|
diags = diags.Append(opDiags)
|
||||||
|
|
||||||
// Collect variable value and add them to the operation request
|
// Collect variable value and add them to the operation request
|
||||||
|
@ -226,7 +226,12 @@ func (c *ApplyCommand) PrepareBackend(planFile *planfile.Reader, args *arguments
|
||||||
return be, diags
|
return be, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApplyCommand) OperationRequest(be backend.Enhanced, view views.Apply, planFile *planfile.Reader, args *arguments.Operation,
|
func (c *ApplyCommand) OperationRequest(
|
||||||
|
be backend.Enhanced,
|
||||||
|
view views.Apply,
|
||||||
|
planFile *planfile.Reader,
|
||||||
|
args *arguments.Operation,
|
||||||
|
autoApprove bool,
|
||||||
) (*backend.Operation, tfdiags.Diagnostics) {
|
) (*backend.Operation, tfdiags.Diagnostics) {
|
||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
|
|
||||||
|
@ -237,7 +242,7 @@ func (c *ApplyCommand) OperationRequest(be backend.Enhanced, view views.Apply, p
|
||||||
|
|
||||||
// Build the operation
|
// Build the operation
|
||||||
opReq := c.Operation(be)
|
opReq := c.Operation(be)
|
||||||
opReq.AutoApprove = args.AutoApprove
|
opReq.AutoApprove = autoApprove
|
||||||
opReq.ConfigDir = "."
|
opReq.ConfigDir = "."
|
||||||
opReq.Destroy = c.Destroy
|
opReq.Destroy = c.Destroy
|
||||||
opReq.Hooks = view.Hooks()
|
opReq.Hooks = view.Hooks()
|
||||||
|
|
|
@ -11,6 +11,9 @@ type Apply struct {
|
||||||
Operation *Operation
|
Operation *Operation
|
||||||
Vars *Vars
|
Vars *Vars
|
||||||
|
|
||||||
|
// AutoApprove skips the manual verification step for the apply operation.
|
||||||
|
AutoApprove bool
|
||||||
|
|
||||||
// InputEnabled is used to disable interactive input for unspecified
|
// InputEnabled is used to disable interactive input for unspecified
|
||||||
// variable and backend config values. Default is true.
|
// variable and backend config values. Default is true.
|
||||||
InputEnabled bool
|
InputEnabled bool
|
||||||
|
@ -34,6 +37,7 @@ func ParseApply(args []string) (*Apply, tfdiags.Diagnostics) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdFlags := extendedFlagSet("apply", apply.State, apply.Operation, apply.Vars)
|
cmdFlags := extendedFlagSet("apply", apply.State, apply.Operation, apply.Vars)
|
||||||
|
cmdFlags.BoolVar(&apply.AutoApprove, "auto-approve", false, "auto-approve")
|
||||||
cmdFlags.BoolVar(&apply.InputEnabled, "input", true, "input")
|
cmdFlags.BoolVar(&apply.InputEnabled, "input", true, "input")
|
||||||
|
|
||||||
if err := cmdFlags.Parse(args); err != nil {
|
if err := cmdFlags.Parse(args); err != nil {
|
||||||
|
|
|
@ -16,14 +16,16 @@ func TestParseApply_basicValid(t *testing.T) {
|
||||||
"defaults": {
|
"defaults": {
|
||||||
nil,
|
nil,
|
||||||
&Apply{
|
&Apply{
|
||||||
|
AutoApprove: false,
|
||||||
InputEnabled: true,
|
InputEnabled: true,
|
||||||
PlanPath: "",
|
PlanPath: "",
|
||||||
ViewType: ViewHuman,
|
ViewType: ViewHuman,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"disabled input and plan path": {
|
"auto-approve, disabled input, and plan path": {
|
||||||
[]string{"-input=false", "saved.tfplan"},
|
[]string{"-auto-approve", "-input=false", "saved.tfplan"},
|
||||||
&Apply{
|
&Apply{
|
||||||
|
AutoApprove: true,
|
||||||
InputEnabled: false,
|
InputEnabled: false,
|
||||||
PlanPath: "saved.tfplan",
|
PlanPath: "saved.tfplan",
|
||||||
ViewType: ViewHuman,
|
ViewType: ViewHuman,
|
||||||
|
|
|
@ -45,9 +45,6 @@ type State struct {
|
||||||
// Operation describes arguments which are used to configure how a Terraform
|
// Operation describes arguments which are used to configure how a Terraform
|
||||||
// operation such as a plan or apply executes.
|
// operation such as a plan or apply executes.
|
||||||
type Operation struct {
|
type Operation struct {
|
||||||
// AutoApprove skips the manual verification step for the apply operation.
|
|
||||||
AutoApprove bool
|
|
||||||
|
|
||||||
// Parallelism is the limit Terraform places on total parallel operations
|
// Parallelism is the limit Terraform places on total parallel operations
|
||||||
// as it walks the dependency graph.
|
// as it walks the dependency graph.
|
||||||
Parallelism int
|
Parallelism int
|
||||||
|
@ -141,7 +138,6 @@ func extendedFlagSet(name string, state *State, operation *Operation, vars *Vars
|
||||||
}
|
}
|
||||||
|
|
||||||
if operation != nil {
|
if operation != nil {
|
||||||
f.BoolVar(&operation.AutoApprove, "auto-approve", false, "auto-approve")
|
|
||||||
f.IntVar(&operation.Parallelism, "parallelism", DefaultParallelism, "parallelism")
|
f.IntVar(&operation.Parallelism, "parallelism", DefaultParallelism, "parallelism")
|
||||||
f.BoolVar(&operation.Refresh, "refresh", true, "refresh")
|
f.BoolVar(&operation.Refresh, "refresh", true, "refresh")
|
||||||
f.Var((*flagStringSlice)(&operation.targetsRaw), "target", "target")
|
f.Var((*flagStringSlice)(&operation.targetsRaw), "target", "target")
|
||||||
|
|
Loading…
Reference in New Issue