This error occurs when Terraform cannot find the provider configuration for a resource. It typically happens when a provider block is missing, incorrectly defined, or the provider hasn't been initialized in the working directory.
The 'Provider configuration not present' error in Terraform occurs when the required provider is missing, incorrectly defined, or not initialized. Terraform cannot locate the provider configuration needed to manage your infrastructure resources. This error is commonly triggered when a provider block is defined in a module but not at the root level, when providers are removed while resources still exist in the state, or when terraform init hasn't been run to download and initialize the provider plugins.
Execute terraform init or terraform init -reconfigure in your working directory. This command sets up the working directory, downloads necessary providers, and resolves dependencies.
terraform init -reconfigureThe -reconfigure flag is especially useful if you've recently changed providers or modified your state.
Ensure your provider block is defined at the root level of your Terraform configuration, not inside child modules. Provider definitions should be at the root.
# ./main.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.0.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
module "example" {
source = "./modules/example"
}If your configuration doesn't have a required_providers block, add it to declare the providers your configuration depends on. This block tells Terraform where to fetch the provider from.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}If you're using provider aliases to use multiple configurations of the same provider, ensure they are correctly referenced. Define the alias in the provider block and reference it in resource blocks.
provider "aws" {
alias = "primary"
region = "us-east-1"
}
provider "aws" {
alias = "secondary"
region = "us-west-2"
}
resource "aws_instance" "primary" {
provider = aws.primary
# configuration
}If the state file references a provider that's no longer in your configuration, use terraform state replace-provider to update it. Replace the provider paths with your old and new provider sources.
terraform state replace-provider 'registry.terraform.io/hashicorp/aws' 'registry.terraform.io/custom/aws'If you removed a provider configuration while resources created by that provider still exist in state, temporarily re-add the provider block to destroy those resources properly.
provider "aws" {
region = "us-east-1"
}Then run terraform destroy before removing the provider block again.
After making corrections, validate your configuration to catch any remaining issues before applying.
terraform validate
terraform planThese commands help verify that your provider configuration is correct and all resources can be properly referenced.
For complex multi-provider setups, consider using provider inheritance where child modules inherit the provider configuration from the root module rather than defining their own. This prevents the common scenario where providers are defined in modules. When using Terraform Cloud or Enterprise, ensure your provider configuration is consistent across all environments. If you're migrating between provider sources (e.g., from one registry to another), use terraform state replace-provider to update all state references. For large states with many resources, this operation may take time and should be tested in a non-production environment first. Additionally, when working with remote backends, ensure the state file is properly locked during these operations to prevent concurrent modifications.
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