Problem
When running terraform plan with a configuration that uses a module with a provider from a private registry, Terraform returns an Invalid provider configuration error.
│ Error: Invalid provider configuration │ │ Provider "registry.terraform.io/hashicorp/azurerm" │ requires explicit configuration. │ Add a provider block to │ the root module and configure the provider's required arguments as │ described in the provider documentation. ╵ ╷ │ Error: Insufficient features blocks │ │ on <empty> line 0: │ (source code not available) │ │ At least 1 "features" blocks are required.
Cause
When a module does not contain a required_providers block, Terraform assumes that any provider referenced in the module's resources should be sourced from the public Terraform Registry.
This behavior causes a conflict when the root module is configured to use the same provider from a private registry. Terraform treats the public and private registry versions as two distinct providers, which prevents the intended provider configuration from being inherited by the module.
Solutions
Solution 1: Add required_providers to Each Module
To ensure correct provider inheritance, you must explicitly declare provider sourcing requirements in every module that uses a provider from a private registry.
Add a required_providers block to the module's configuration to specify the source of the provider. This ensures Terraform resolves the correct provider from your private registry.
terraform {
required_providers {
azurerm = {
source = "private-provider.com/test/"
version = "3.107.0"
}
}
}