@@ -56,19 +56,7 @@ func (c *InitCommand) Run(args []string) int {
5656
5757 view := views .NewInit (initArgs .ViewType , c .View )
5858
59- loader , err := c .initConfigLoader ()
60- if err != nil {
61- diags = diags .Append (err )
62- view .Diagnostics (diags )
63- return 1
64- }
65-
66- var varDiags tfdiags.Diagnostics
67- c .VariableValues , varDiags = initArgs .Vars .CollectValues (func (filename string , src []byte ) {
68- loader .Parser ().ForceFileSource (filename , src )
69- })
70- diags = diags .Append (varDiags )
71-
59+ diags = diags .Append (c .Validate (initArgs ))
7260 if diags .HasErrors () {
7361 view .Diagnostics (diags )
7462 return 1
@@ -294,6 +282,23 @@ func (c *InitCommand) initBackend(ctx context.Context, root *configs.Module, ini
294282 return back , true , diags
295283}
296284
285+ func (c * InitCommand ) Validate (args * arguments.Init ) (diags tfdiags.Diagnostics ) {
286+ loader , err := c .initConfigLoader ()
287+ if err != nil {
288+ diags = diags .Append (err )
289+ return diags
290+ }
291+
292+ var varDiags tfdiags.Diagnostics
293+ c .VariableValues , varDiags = args .Vars .CollectValues (func (filename string , src []byte ) {
294+ loader .Parser ().ForceFileSource (filename , src )
295+ })
296+ diags = diags .Append (varDiags )
297+
298+ diags = diags .Append (validatePolicyPaths (args .PolicyPaths , c .AllowExperimentalFeatures ))
299+ return diags
300+ }
301+
297302func (c * InitCommand ) earlyValidateBackend (root * configs.Module , initArgs * arguments.Init ) (diags tfdiags.Diagnostics ) {
298303 switch {
299304 case root .StateStore != nil && root .Backend != nil :
@@ -517,18 +522,18 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
517522
518523 // Determine which required providers are already downloaded, and download any
519524 // new providers or newer versions of providers
520- configLocks , installErr := inst .EnsureProviderVersions (ctx , previousLocks , reqs , mode , installerHook )
525+ configLocks , err := inst .EnsureProviderVersions (ctx , previousLocks , reqs , mode , installerHook )
521526 if ctx .Err () == context .Canceled {
522527 diags = diags .Append (fmt .Errorf ("Provider installation was canceled by an interrupt signal." ))
523- view .Diagnostics (diags ) // TODO: Why is the output viewed here?
528+ view .Diagnostics (diags )
524529 return true , nil , SafeInitActionInvalid , nil , diags
525530 }
526- if installErr != nil {
527- // The errors captured in "installErr " should be redundant with what we
531+ if err != nil {
532+ // The errors captured in "err " should be redundant with what we
528533 // received via the InstallerEvents callbacks above, so we'll
529534 // just return those as long as we have some.
530535 if ! diags .HasErrors () {
531- diags = diags .Append (installErr )
536+ diags = diags .Append (err )
532537 }
533538
534539 return true , nil , SafeInitActionInvalid , nil , diags
0 commit comments