@@ -375,7 +375,7 @@ const (
375375// The method downloads any missing providers that aren't already downloaded and then returns
376376// dependency lock data based on the configuration.
377377// The dependency lock file itself isn't updated here.
378- func (c * InitCommand ) getProvidersFromConfig (ctx context.Context , config * configs.Config , upgrade bool , pluginDirs []string , flagLockfile string , view views.Init ) (output bool , resultingLocks * depsfile.Locks , safeInitAction SafeInitAction , diags tfdiags.Diagnostics ) {
378+ func (c * InitCommand ) getProvidersFromConfig (ctx context.Context , config * configs.Config , upgrade bool , pluginDirs []string , flagLockfile string , view views.Init ) (output bool , resultingLocks * depsfile.Locks , safeInitAction SafeInitAction , authResult * getproviders. PackageAuthenticationResult , diags tfdiags.Diagnostics ) {
379379 ctx , span := tracer .Start (ctx , "install providers from config" )
380380 defer span .End ()
381381
@@ -391,7 +391,7 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
391391 reqs , hclDiags := config .ProviderRequirements ()
392392 diags = diags .Append (hclDiags )
393393 if hclDiags .HasErrors () {
394- return false , nil , SafeInitActionInvalid , diags
394+ return false , nil , SafeInitActionInvalid , nil , diags
395395 }
396396
397397 reqs = c .removeDevOverrides (reqs )
@@ -409,7 +409,7 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
409409 }
410410 }
411411 if diags .HasErrors () {
412- return false , nil , SafeInitActionInvalid , diags
412+ return false , nil , SafeInitActionInvalid , nil , diags
413413 }
414414
415415 var inst * providercache.Installer
@@ -435,10 +435,14 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
435435 // These allow us to send output to the terminal as events happen, catch
436436 // diagnostics, etc.
437437 //
438- // One of the things we capture via these callbacks is the location of
438+ // The callbacks help create diagnostics based on installation events, output
439+ // messages to the user,
440+ //
441+ // of the things we capture via these callbacks is the location of
439442 // providers as we install them. This allows the calling code to determine
440443 // what 'safe init' actions need to take place.
441444 providerLocations := make (map [addrs.Provider ]getproviders.PackageLocation )
445+ var stateStoreProviderAuthResult * getproviders.PackageAuthenticationResult
442446
443447 initMsg := views .InitializingProviderPluginFromConfigMessage
444448 reuseMsg := views .ReusingPreviousVersionInfo
@@ -674,6 +678,13 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
674678 }
675679 },
676680 FetchPackageSuccess : func (provider addrs.Provider , version getproviders.Version , localDir string , authResult * getproviders.PackageAuthenticationResult ) {
681+ // 1. Capture auth result if this provider is used for state storage.
682+ if config .Module .StateStore != nil && provider .Equals (config .Module .StateStore .ProviderAddr ) {
683+ log .Printf ("[TRACE] getProvidersFromConfig: state storage provider %s (%q) auth result: %q" , config .Module .StateStore .ProviderAddr .Type , config .Module .StateStore .ProviderAddr .ForDisplay (), stateStoreProviderAuthResult .String ())
684+ stateStoreProviderAuthResult = authResult
685+ }
686+
687+ // 2. Log a message about the installed provider.
677688 var keyID string
678689 if authResult != nil && authResult .ThirdPartySigned () {
679690 keyID = authResult .KeyID
@@ -739,7 +750,7 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
739750 if flagLockfile == "readonly" {
740751 diags = diags .Append (fmt .Errorf ("The -upgrade flag conflicts with -lockfile=readonly." ))
741752 view .Diagnostics (diags )
742- return true , nil , SafeInitActionInvalid , diags
753+ return true , nil , SafeInitActionInvalid , nil , diags
743754 }
744755
745756 mode = providercache .InstallUpgrades
@@ -749,7 +760,7 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
749760 previousLocks , moreDiags := c .lockedDependencies ()
750761 diags = diags .Append (moreDiags )
751762 if diags .HasErrors () {
752- return false , nil , SafeInitActionInvalid , diags
763+ return false , nil , SafeInitActionInvalid , nil , diags
753764 }
754765
755766 // Determine which required providers are already downloaded, and download any
@@ -758,7 +769,7 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
758769 if ctx .Err () == context .Canceled {
759770 diags = diags .Append (fmt .Errorf ("Provider installation was canceled by an interrupt signal." ))
760771 view .Diagnostics (diags )
761- return true , nil , SafeInitActionInvalid , diags
772+ return true , nil , SafeInitActionInvalid , nil , diags
762773 }
763774 if err != nil {
764775 // The errors captured in "err" should be redundant with what we
@@ -768,7 +779,7 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
768779 diags = diags .Append (err )
769780 }
770781
771- return true , nil , SafeInitActionInvalid , diags
782+ return true , nil , SafeInitActionInvalid , nil , diags
772783 }
773784
774785 // Return advice to the calling code about what to do regarding safe init feature related to state storage providers
@@ -804,7 +815,7 @@ func (c *InitCommand) getProvidersFromConfig(ctx context.Context, config *config
804815 }
805816 }
806817
807- return true , configLocks , safeInitAction , diags
818+ return true , configLocks , safeInitAction , authResult , diags
808819}
809820
810821// getProvidersFromState determines what providers are required by the given state data.
0 commit comments