use pre-existing loaders where possible

This commit is contained in:
Daniel Schmidt 2026-02-18 10:15:03 +01:00
parent 4e921a8eae
commit fd8d61ac9b
6 changed files with 7 additions and 50 deletions

View file

@ -102,17 +102,10 @@ 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
var varDiags tfdiags.Diagnostics
opReq.Variables, varDiags = args.Vars.CollectValues(func(filename string, src []byte) {
loader.Parser().ForceFileSource(filename, src)
opReq.ConfigLoader.Parser().ForceFileSource(filename, src)
})
diags = diags.Append(varDiags)

View file

@ -80,18 +80,10 @@ func (c *ConsoleCommand) Run(args []string) int {
}
{
loader, err := c.initConfigLoader()
if err != nil {
diags = diags.Append(err)
c.showDiagnostics(diags)
return 1
}
// Collect variable value and add them to the operation request
var varDiags tfdiags.Diagnostics
opReq.Variables, varDiags = parsedArgs.Vars.CollectValues(func(filename string, src []byte) {
loader.Parser().ForceFileSource(filename, src)
opReq.ConfigLoader.Parser().ForceFileSource(filename, src)
})
diags = diags.Append(varDiags)
if varDiags.HasErrors() {

View file

@ -179,19 +179,12 @@ func (c *ImportCommand) Run(args []string) int {
return 1
}
opReq.Hooks = []terraform.Hook{c.uiHook()}
{
loader, err := c.initConfigLoader()
if err != nil {
diags = diags.Append(err)
c.showDiagnostics(diags)
return 1
}
// Collect variable value and add them to the operation request
var varDiags tfdiags.Diagnostics
opReq.Variables, varDiags = parsedArgs.Vars.CollectValues(func(filename string, src []byte) {
loader.Parser().ForceFileSource(filename, src)
opReq.ConfigLoader.Parser().ForceFileSource(filename, src)
})
diags = diags.Append(varDiags)

View file

@ -86,17 +86,10 @@ func (c *PlanCommand) 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
var varDiags tfdiags.Diagnostics
opReq.Variables, varDiags = args.Vars.CollectValues(func(filename string, src []byte) {
loader.Parser().ForceFileSource(filename, src)
opReq.ConfigLoader.Parser().ForceFileSource(filename, src)
})
diags = diags.Append(varDiags)

View file

@ -125,17 +125,10 @@ func (c *QueryCommand) 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
var varDiags tfdiags.Diagnostics
opReq.Variables, varDiags = args.Vars.CollectValues(func(filename string, src []byte) {
loader.Parser().ForceFileSource(filename, src)
opReq.ConfigLoader.Parser().ForceFileSource(filename, src)
})
diags = diags.Append(varDiags)

View file

@ -82,17 +82,10 @@ func (c *RefreshCommand) 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
var varDiags tfdiags.Diagnostics
opReq.Variables, varDiags = args.Vars.CollectValues(func(filename string, src []byte) {
loader.Parser().ForceFileSource(filename, src)
opReq.ConfigLoader.Parser().ForceFileSource(filename, src)
})
diags = diags.Append(varDiags)