-
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
Unhelpful/unclear error message when required provider configurations are missing #34594
Comments
Hi @stusklinar, thanks for filing this! The problem is that you are only providing a definition for the I think you can get your test to work if you expand the
This provides a concrete provider definition for all the required providers in your configuration. I do think that the error message you are receiving is super unhelpful, I'll expand on that in a follow up comment to keep things separate. Hopefully this unblocks you! |
On the error message, this isn't actually something that is being reported by the testing framework itself. If I add the provider block directly to your configuration and execute terraform {
required_version = "<= 1.7.1"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.24.0, < 4.0.0"
configuration_aliases = [
azurerm.azsubscription
]
}
}
}
provider "azurerm" {
alias = "azsubscription"
features {}
}
variable "name" {
description = "Name of the Resource Group"
type = string
}
variable "location" {
description = "Location of the Resource Group"
type = string
default = "UK South"
}
resource "azurerm_resource_group" "this" {
name = var.name
location = var.location
} ~/terraform/34594 > terraform plan
var.name
Name of the Resource Group
Enter a value: thing
Planning failed. Terraform encountered an error while generating this plan.
╷
│ Error: Insufficient features blocks
│
│ on <empty> line 0:
│ (source code not available)
│
│ At least 1 "features" blocks are required.
╵ The I'm going to change the title of this issue, and we can use it to track improving the error message for this case so that in future it will state the real problem, which is that the provider block must be explicitly provided in the configuration if we have required attributes or blocks. Thanks! |
We do actually add some additional context for missing provider config if the provider validation call itself fails. This happens here. We don't any extra context if the schema validation itself fails (where the I think we can just take the additional context we add in the first case, and also add it in the second case. Then we'd get an error that looks like this:
Which provides a much better hint about the root cause of the problem, compared to the existing cryptic errors that are returned currently. |
This is great - thanks for this - consider me unblocked |
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. |
Terraform Version
Terraform Configuration Files
main.tf
test.tftest.hcl
Debug Output
TF Trace Log Output
Expected Behavior
Tests should pass
Actual Behavior
Steps to Reproduce
terraform init
terraform test
Additional Context
This is a largely reduced version of our problem - but illustrates the issue much the same.
We have modules that accept different providers for different subscriptions/accounts - in this simple mock-up we get the same error, of injecting a provider expects features.
References
The text was updated successfully, but these errors were encountered: