-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give suggestions & remind users to use required_providers when provider not in registry #28014
Conversation
048ca4d
to
2202fa6
Compare
When someone has a failed registry error on init in the default namespace, remind them that they should have required_providers in every module
2202fa6
to
99380f8
Compare
Codecov Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM if it fits with the product goals. I agree it's hard to do something more specific here, so at least having a hint at required_providers
is nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good improvement to me!
I haven't fully thought through the consequences of this, but did you decide against a type-based lookup of similar providers based on the requirements? For example, we could add something like this right after the call to getproviders.MissingProviderSuggestion
:
if alternative == provider && provider.IsDefault() {
for req := range reqs {
if req != provider && req.Type == provider.Type {
alternative = req
break
}
}
}
This results in the "Did you intend to use …?" message being printed in cases like #27920:
@alisdair Thanks Alisdair! Seeing it in practice ... it does look pretty good, and could be a nice addition to the default here. I got stuck thinking I needed to provide a working provider suggestion ... using (thinking: if we found a req that matched, but then that req failed, we'd give an error on both and in one of those errors, we would be suggesting to use the other erroring provider 🙃 ) |
Ah, yes, I hadn't thought of that, and trying to only recommend providers which successfully installed would be much harder. The case you describe is unfortunate and the result is not very clear, but to me it's not worse than what we have now. For example, if I misspell the
|
Yeah, indeed my thinking with what I was considering in that comment over in #27920 is that if there's a non- By structuring this a bit differently I suppose we could consider only providers that successfully installed, but we'd need to do it as a followup extra message at the end of the whole install process rather than as part of the main error message, because we might not have tried to install the non- While a single message covering both problems would be ideal, I agree with @alisdair that the pair of error messages is still an improvement over what happens today, and I think the worst case if someone takes it totally literally is that they put the typo source address in their other module too and then they will still get the other error about the provider not existing to prompt a second debugging step. With that said, I think it would be most effective if we include something like the heuristic I described in my comment over there so that we only produce this additional hint in the case where the failing provider is a default provider and there's another provider of the same type elsewhere in the configuration, because then the extra hint would appear only on the error message it applies to and not be a red herring for the secondary problem:
I'd hope that by not including the "did you mean" in the first of these we won't bias the user towards thinking that a missing dependency is the problem, and thus give them more room to consider the possibility of a typo as the cause. |
c9222fe
to
6315789
Compare
Suggest another provider on a registry error, from the list of requirements we have on init. This skips the legacy lookup process if there is a similar provider existing in requirements.
6315789
to
0d7aa81
Compare
Thanks for the comments @alisdair and @apparentlymart! I've added the suggestion and integrated the addition into the tests. I am leaving the "You need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ from me!
I was a bit surprised to see the switch from IsDefault
to directly inspecting the provider addr namespace. More details in an inline comment, but it's totally possible I'm missing something and I'm leaving a checkmark in case that's so.
A user cannot use a non-default registry and end up with the default namespace, because by definition, their required_providers tells us the registry they are using, and they must use that to have a non-default registry
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
When a user has any module, or child module, that has a
ErrRegistryProviderNotKnown
error, users are often confused why they don't get inheritance from other modules.Because Terraform explicitly loads modules as units with their own provider requirements (
required_providers
), and adds a suggestion of a provider "did you mean" if they have a provider of the same type (but not the default namespace) in their requirements.This is what the new suggestion looks like in practice (with suggestion):
This is what the new suggestion looks like in practice (without suggestion/no existing provider requirements):
Open to comments on improving this suggestion to be more user-friendly (for lack of a better term)
My hope is that this can address the (very valid!) concerns and comments surrounding issues like #27920 and #27701 . In #27920, Martin suggests an improvement where we could suggest a similar-name provider we may know about, but because of how the code is currently structured, I don't have confidence in picking an accurate (successful) name, so I am suggesting a more general suggestion here.
Fixes #27920
Fixes #27701