If a provider changes namespace in the registry, we can detect this when
running the 0.13upgrade command. As long as there is a version matching
the user's constraints, we now use the provider's new source address.
Otherwise, warn the user that the provider has moved and a version
upgrade is necessary to move to it.
// If something goes wrong with the registry lookup here, fall
// back to the non-redirect provider
iferr!=nil{
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Warning,
"Failed to query available provider packages",
fmt.Sprintf("Could not retrieve the list of available versions for provider %s: %s",
moved.ForDisplay(),err),
))
continueproviders
}
// Walk backwards to consider newer versions first
fori:=len(available)-1;i>=0;i--{
ifacceptable.Has(available[i]){
// Success! Provider redirect target has a version
// meeting our constraints, so we can use it
rp.Type=moved
continueproviders
}
}
// Find the last version available at the old location
oldAvailable,_,err:=source.AvailableVersions(p)
iferr!=nil{
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Warning,
"Failed to query available provider packages",
fmt.Sprintf("Could not retrieve the list of available versions for provider %s: %s",
p.ForDisplay(),err),
))
continueproviders
}
lastAvailable:=oldAvailable[len(oldAvailable)-1]
// If we fall through here, no versions at the target meet our
// version constraints, so warn the user
diags=diags.Append(tfdiags.Sourceless(
tfdiags.Warning,
"Provider has moved",
fmt.Sprintf(
"Provider %q has moved to %q. No action is required to continue using %q (%s), but if you want to upgrade beyond version %s, you must also update the source.",
ifaddr.Hostname!=defaultRegistryHost{// condition above assures namespace is also "-"
// Legacy providers must always belong to the default registry host.
returnaddrs.Provider{}, fmt.Errorf("invalid provider type %q: legacy provider addresses must always belong to %s",addr,defaultRegistryHost)
returnaddrs.Provider{},addrs.Provider{},fmt.Errorf("invalid provider type %q: legacy provider addresses must always belong to %s",addr,defaultRegistryHost)
}
// Now we need to derive a suitable *RegistrySource from the given source,
// based on the CLI configuration, which isn't necessarily true but
// is true in all cases where this error message will ultimately be
// presented to an end-user, so good enough for now.
returnaddrs.Provider{}, fmt.Errorf("unqualified provider type %q cannot be resolved because direct installation from %s is disabled in the CLI configuration; declare an explicit provider namespace for this provider",addr.Type,addr.Hostname)
returnaddrs.Provider{},addrs.Provider{},fmt.Errorf("unqualified provider type %q cannot be resolved because direct installation from %s is disabled in the CLI configuration; declare an explicit provider namespace for this provider",addr.Type,addr.Hostname)