// MissingProviderSuggestion takes a provider address that failed installation
// due to the remote registry reporting that it didn't exist, and attempts
// to find another provider that the user might have meant to select.
//
// If the result is equal to the given address then that indicates that there
// is no suggested alternative to offer, either because the function
// successfully determined there is no recorded alternative or because the
// lookup failed somehow. We don't consider a failure to find a suggestion
// as an installation failure, because the caller should already be reporting
// that the provider didn't exist anyway and this is only extra context for
// that error message.
//
// The result of this is a best effort, so any UI presenting it should be
// careful to give it only as a possibility and not necessarily a suitable
// replacement for the given provider.
//
// In practice today this function only knows how to suggest alternatives for
// "default" providers, which is to say ones that are in the hashicorp
// namespace in the Terraform registry. It will always return no result for
// any other provider. That might change in future if we introduce other ways
// to discover provider suggestions.
//
// If the given context is cancelled then this function might not return a
// renaming suggestion even if one would've been available for a completed
// request.
MissingProviderSuggestion takes a provider address that failed installation
due to the remote registry reporting that it didn't exist, and attempts
to find another provider that the user might have meant to select.

If the result is equal to the given address then that indicates that there
is no suggested alternative to offer, either because the function
successfully determined there is no recorded alternative or because the
lookup failed somehow. We don't consider a failure to find a suggestion
as an installation failure, because the caller should already be reporting
that the provider didn't exist anyway and this is only extra context for
that error message.

The result of this is a best effort, so any UI presenting it should be
careful to give it only as a possibility and not necessarily a suitable
replacement for the given provider.

In practice today this function only knows how to suggest alternatives for
"default" providers, which is to say ones that are in the hashicorp
namespace in the Terraform registry. It will always return no result for
any other provider. That might change in future if we introduce other ways
to discover provider suggestions.

If the given context is cancelled then this function might not return a
renaming suggestion even if one would've been available for a completed
request.
// MissingProviderSuggestion takes a provider address that failed installation // due to the remote registry reporting that it didn ' t exist and attempts // to find another provider that the user might have meant to select . // // If the result is equal to the given address then that indicates that there // is no suggested alternative to offer either because the function // successfully determined there is no recorded alternative or because the // lookup failed somehow . We don ' t consider a failure to find a suggestion // as an installation failure because the caller should already be reporting // that the provider didn ' t exist anyway and this is only extra context for // that error message . // // The result of this is a best effort so any UI presenting it should be // careful to give it only as a possibility and not necessarily a suitable // replacement for the given provider . // // In practice today this function only knows how to suggest alternatives for // " default " providers which is to say ones that are in the hashicorp // namespace in the Terraform registry . It will always return no result for // any other provider . That might change in future if we introduce other ways // to discover provider suggestions . // // If the given context is cancelled then this function might not return a // renaming suggestion even if one would ' ve been available for a completed // request .
func MissingProviderSuggestion(ctx context.Context, addr addrs.Provider, source Source) addrs.Provider {
	if !addr.IsDefault() {
		return addr
	}
	 To achieve that, we need to find the direct registry client in
	 particular from the given source, because that is the only Source
	 implementation that can actually handle a legacy provider lookup.
	regSource := findLegacyProviderLookupSource(addr.Hostname, source)
	if regSource == nil {
		 If there's no direct registry source in the installation config
		 then we can't provide a renaming suggestion.
		return addr
	}
	defaultNS, redirectNS, err := regSource.lookupLegacyProviderNamespace(ctx, addr.Hostname, addr.Type)
	if err != nil {
		return addr
	}
	switch {
	case redirectNS != "":
		return addrs.Provider{
			Hostname:  addr.Hostname,
			Namespace: redirectNS,
			Type:      addr.Type,
		}
	default:
		return addrs.Provider{
			Hostname:  addr.Hostname,
			Namespace: defaultNS,
			Type:      addr.Type,
		}
	}
}
func MissingProviderSuggestion ( ctx context . Context , addr addrs . Provider , source Source ) addrs . Provider { if ! addr . IsDefault ( ) { return addr } regSource := findLegacyProviderLookupSource ( addr . Hostname , source ) if regSource == nil { return addr } defaultNS , redirectNS , err := regSource . lookupLegacyProviderNamespace ( ctx , addr . Hostname , addr . Type ) if err != nil { return addr } switch { case redirectNS != " " : return addrs . Provider { Hostname : addr . Hostname , Namespace : redirectNS , Type : addr . Type , } default : return addrs . Provider { Hostname : addr . Hostname , Namespace : defaultNS , Type : addr . Type , } } }
MissingProviderSuggestion takes a provider address that failed installation
due to the remote registry reporting that it didn't exist, and attempts
to find another provider that the user might have meant to select.
MissingProviderSuggestion takes a provider address that failed installation due to the remote registry reporting that it didn ' t exist and attempts to find another provider that the user might have meant to select .
// Our strategy here, for a default provider, is to use the default // registry's special API for looking up "legacy" providers and try looking // for a legacy provider whose type name matches the type of the given // provider. This should then find a suitable answer for any provider // that was originally auto-installable in v0.12 and earlier but moved // into a non-default namespace as part of introducing the heirarchical // provider namespace. // // To achieve that, we need to find the direct registry client in // particular from the given source, because that is the only Source // implementation that can actually handle a legacy provider lookup. // If there's no direct registry source in the installation config // then we can't provide a renaming suggestion.