Skip to content
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

terraform: improve provider config related error messages #27261

Merged
merged 2 commits into from
Dec 11, 2020

Conversation

mildwonkey
Copy link
Contributor

If there is no "provider" block present in the configuration at all,
errors related to missing required arguments lack source information or
even a reference to the provider in question. This PR adds more specific
error messages in three of these situations:

  • ValidateProvider
  • ConfigureProvider: provider.PrepareProviderConfig
  • ConfigureProvider: ctx.ConfigureProvider

To test the last case I added a ConfigureProviderFn to the MockContext.

Screen Shot 2020-12-11 at 9 08 44 AM

Closes #20121, #26707, #23087

config

If there is no provider configuration present in the config at all,
errors related to missing required arguments lack source information or
even a reference to the provider in question. This PR adds more specific
error messages in three of these situations:
- ValidateProvider
- ConfigureProvider: provider.PrepareProviderConfig
- ConfigureProvider: ctx.ConfigureProvider

To test the last case I added a ConfigureProviderFn to the MockContext.
@codecov
Copy link

codecov bot commented Dec 11, 2020

Codecov Report

Merging #27261 (405e96b) into master (6e1017f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
terraform/eval_context_mock.go 64.22% <100.00%> (+0.66%) ⬆️
terraform/node_provider.go 89.24% <100.00%> (+7.15%) ⬆️
internal/providercache/dir.go 67.34% <0.00%> (-6.13%) ⬇️
terraform/node_resource_apply_instance.go 49.76% <0.00%> (-2.80%) ⬇️
terraform/node_resource_plan.go 96.11% <0.00%> (-1.95%) ⬇️

@mildwonkey mildwonkey requested a review from a team December 11, 2020 14:19
Copy link
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution to a confusing bug!

Provider %q requires explicit configuration. Add a provider block to the root
module and configure the provider's required arguments as described in the
provider documentation.
`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing this paragraph with embedded newlines has the unfortunate effect of causing odd line-wrapping in the diagnostic output. You can see this in the screenshot below: it wraps awkwardly between "root" and "module" when there's no need to:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already tried changing the newlines - including one long single line with no newlines - and it didn't improve the output, do you know how else I might improve this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. Making the last paragraph a single line seemed to work for me:

diff --git a/terraform/node_provider.go b/terraform/node_provider.go
index 57245fafb..001408bf2 100644
--- a/terraform/node_provider.go
+++ b/terraform/node_provider.go
@@ -185,7 +185,4 @@ func (n *NodeApplyableProvider) ConfigureProvider(ctx EvalContext, provider prov

 const providerConfigErr = `%s

-Provider %q requires explicit configuration. Add a provider block to the root
-module and configure the provider's required arguments as described in the
-provider documentation.
-`
+Provider %q requires explicit configuration. Add a provider block to the root module and configure the provider's required arguments as described in the provider documentation.`

Result:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize, my error - I tried what I thought I already tried before and it now looks better. Sorry!

@mildwonkey mildwonkey merged commit e938b02 into master Dec 11, 2020
@mildwonkey mildwonkey deleted the mildwonkey/provider-err-context branch December 11, 2020 18:21
@ghost
Copy link

ghost commented Jan 11, 2021

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.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing context for provider diagnostics
2 participants