diff --git a/command/apply.go b/command/apply.go index a6641d1cf..4e832a129 100644 --- a/command/apply.go +++ b/command/apply.go @@ -89,7 +89,7 @@ func (c *ApplyCommand) Run(rawArgs []string) int { } // 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) // 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 } -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) { var diags tfdiags.Diagnostics @@ -237,7 +242,7 @@ func (c *ApplyCommand) OperationRequest(be backend.Enhanced, view views.Apply, p // Build the operation opReq := c.Operation(be) - opReq.AutoApprove = args.AutoApprove + opReq.AutoApprove = autoApprove opReq.ConfigDir = "." opReq.Destroy = c.Destroy opReq.Hooks = view.Hooks() diff --git a/command/arguments/apply.go b/command/arguments/apply.go index 5f4e98bcb..0db576b18 100644 --- a/command/arguments/apply.go +++ b/command/arguments/apply.go @@ -11,6 +11,9 @@ type Apply struct { Operation *Operation Vars *Vars + // AutoApprove skips the manual verification step for the apply operation. + AutoApprove bool + // InputEnabled is used to disable interactive input for unspecified // variable and backend config values. Default is true. InputEnabled bool @@ -34,6 +37,7 @@ func ParseApply(args []string) (*Apply, tfdiags.Diagnostics) { } 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") if err := cmdFlags.Parse(args); err != nil { diff --git a/command/arguments/apply_test.go b/command/arguments/apply_test.go index bed0ed5b3..65dfae472 100644 --- a/command/arguments/apply_test.go +++ b/command/arguments/apply_test.go @@ -16,14 +16,16 @@ func TestParseApply_basicValid(t *testing.T) { "defaults": { nil, &Apply{ + AutoApprove: false, InputEnabled: true, PlanPath: "", ViewType: ViewHuman, }, }, - "disabled input and plan path": { - []string{"-input=false", "saved.tfplan"}, + "auto-approve, disabled input, and plan path": { + []string{"-auto-approve", "-input=false", "saved.tfplan"}, &Apply{ + AutoApprove: true, InputEnabled: false, PlanPath: "saved.tfplan", ViewType: ViewHuman, diff --git a/command/arguments/extended.go b/command/arguments/extended.go index 1b345b9c9..48b83cab5 100644 --- a/command/arguments/extended.go +++ b/command/arguments/extended.go @@ -45,9 +45,6 @@ type State struct { // Operation describes arguments which are used to configure how a Terraform // operation such as a plan or apply executes. 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 // as it walks the dependency graph. Parallelism int @@ -141,7 +138,6 @@ func extendedFlagSet(name string, state *State, operation *Operation, vars *Vars } if operation != nil { - f.BoolVar(&operation.AutoApprove, "auto-approve", false, "auto-approve") f.IntVar(&operation.Parallelism, "parallelism", DefaultParallelism, "parallelism") f.BoolVar(&operation.Refresh, "refresh", true, "refresh") f.Var((*flagStringSlice)(&operation.targetsRaw), "target", "target")