diff --git a/internal/command/apply.go b/internal/command/apply.go index b4a3cf64c9..ad7c85d673 100644 --- a/internal/command/apply.go +++ b/internal/command/apply.go @@ -102,8 +102,19 @@ func (c *ApplyCommand) Run(rawArgs []string) int { return 1 } + loader, err := c.initConfigLoader() + if err != nil { + diags = diags.Append(err) + view.Diagnostics(diags) + return 1 + } + // Collect variable value and add them to the operation request - diags = diags.Append(c.GatherVariables(opReq, args.Vars)) + var varDiags tfdiags.Diagnostics + opReq.Variables, varDiags = args.Vars.CollectValues(func(filename string, src []byte) { + loader.Parser().ForceFileSource(filename, src) + }) + diags = diags.Append(varDiags) // Before we delegate to the backend, we'll print any warning diagnostics // we've accumulated here, since the backend will start fresh with its own @@ -296,28 +307,6 @@ func (c *ApplyCommand) OperationRequest( return opReq, diags } -func (c *ApplyCommand) GatherVariables(opReq *backendrun.Operation, args *arguments.Vars) tfdiags.Diagnostics { - var diags tfdiags.Diagnostics - - // FIXME the arguments package currently trivially gathers variable related - // arguments in a heterogenous slice, in order to minimize the number of - // code paths gathering variables during the transition to this structure. - // Once all commands that gather variables have been converted to this - // structure, we could move the variable gathering code to the arguments - // package directly, removing this shim layer. - - varArgs := args.All() - items := make([]arguments.FlagNameValue, len(varArgs)) - for i := range varArgs { - items[i].Name = varArgs[i].Name - items[i].Value = varArgs[i].Value - } - c.Meta.variableArgs = arguments.FlagNameValueSlice{Items: &items} - opReq.Variables, diags = c.collectVariableValues() - - return diags -} - func (c *ApplyCommand) Help() string { if c.Destroy { return c.helpDestroy()