Skip to content

Commit

Permalink
Add helper suggestion when failed registry err
Browse files Browse the repository at this point in the history
When someone has a failed registry error on init in the default
namespace, remind them that they should have required_providers in
every module
  • Loading branch information
pselle committed Mar 8, 2021
1 parent 98899df commit 2202fa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions command/e2etest/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ func TestInitProviderNotFound(t *testing.T) {
│ Could not retrieve the list of available versions for provider
│ hashicorp/nonexist: provider registry registry.terraform.io does not have a
│ provider named registry.terraform.io/hashicorp/nonexist
│ If you meant to install a provider from the registry that is not in the
│ hashicorp namespace, the required_providers block for your module is not
│ optional. All modules should specify their required_providers so that
│ external consumers will get the correct providers when using a module.
`
Expand Down
7 changes: 7 additions & 0 deletions command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,13 @@ func (c *InitCommand) getProviders(config *configs.Config, state *states.State,
"\n\nDid you intend to use %s? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on %s, run the following command:\n terraform providers",
alternative.ForDisplay(), provider.ForDisplay(),
)
} else if provider.IsDefault() {
// If the provider uses the default namespace let's give a suggestion that the user may want
// to use required_providers. (all modules should do this, but the default namespace behavior
// was intended to allow a smoother transition)
// In the future, it would be helpful if this could suggest providers based on existing known
// non-default domain [hashicorp] providers
suggestion = "\n\nIf you meant to install a provider from the registry that is not in the hashicorp namespace, the required_providers block for your module is not optional. All modules should specify their required_providers so that external consumers will get the correct providers when using a module."
}

diags = diags.Append(tfdiags.Sourceless(
Expand Down

0 comments on commit 2202fa6

Please sign in to comment.