Since Terraform 0.13, only one required_providers block is allowed per module. This error occurs when your configuration has multiple required_providers blocks. Consolidate them into a single block to resolve this issue.
Terraform 0.13 introduced a restriction that prohibits multiple required_providers blocks within the same module. This change was made to prevent ambiguity when merging provider configurations from different files. Each module can only have one terraform block containing the required_providers configuration. If Terraform finds more than one, it will throw this error and halt the plan or apply operation. This is different from earlier Terraform versions where multiple terraform blocks were implicitly merged together. The restriction enforces a single source of truth for provider version constraints within each module.
Search your Terraform configuration directory for all occurrences of the required_providers block. This includes main files, versions.tf, providers.tf, and any other .tf files in the module.
# Search for all required_providers blocks
grep -r "required_providers" .Note the line numbers and files where required_providers appears. You should only have one per module.
If you have required_providers in multiple files, choose one file to be your source of truth (usually versions.tf or main.tf) and move all provider declarations there.
Before (split configuration):
# versions.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}# providers.tf
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.0"
}
}
}After (consolidated):
# versions.tf
terraform {
required_version = ">= 0.13"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.0"
}
}
}Then delete the terraform block from the other files.
Delete any remaining terraform blocks containing required_providers from other configuration files. You can keep other terraform block settings like required_version in the main file if needed.
# Example: if you consolidated into versions.tf, remove terraform block from providers.tf
# Edit providers.tf and remove or comment out the terraform blockModules are allowed to have required_providers blocks that declare their dependencies. However, make sure your root module doesn't duplicate these provider declarations.
Each module should declare its own provider requirements independently. The root module can then satisfy all constraints with a single version of each provider.
# Root module consolidates all requirements
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0" # Must satisfy all modules
}
}
}
module "networking" {
source = "./modules/networking"
# Module has its own required_providers block
}
module "database" {
source = "./modules/database"
# Module has its own required_providers block
}After consolidating your configuration, run terraform init to reinitialize your working directory and verify the error is resolved.
terraform initIf successful, you should see output indicating the Terraform configuration has been initialized without errors. You can then proceed with terraform plan and apply.
Terraform Version Note: This restriction only applies to Terraform 0.13 and later. If you're still using Terraform 0.12, you can have multiple terraform blocks that will be implicitly merged. However, upgrading to 0.13+ is recommended for better module management and provider pinning.
Module Development Best Practices: When writing reusable modules, each module should declare its minimum required provider versions using >= constraints. This allows the root module to pin a single provider version that satisfies all module requirements. Avoid using exact version pins (~=) in modules unless absolutely necessary.
Provider Version Compatibility: When consolidating provider versions from multiple files, choose a version constraint that satisfies all module requirements. Use terraform plan without applying to verify compatibility before committing changes.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform