Terraform relies on providers to interact with cloud platforms and services. However, misconfigurations or missing settings can cause deployment failures. Understanding the causes of provider-related errors is crucial for smooth infrastructure deployment.
In this article, we’ll cover:
The "provider configuration not present"
error in Terraform occurs when the required provider is missing, incorrectly defined, or not initialized. Common causes include:
- A missing
required_providers
block
- Uninitialized providers
- Incorrect provider configurations
- State file mismatches or corruption
- Version conflicts
- Provider definitions are missing in modules
The simplest way to avoid this error is to ensure the provider is correctly declared, initialized, and accessible in the working directory.
Below are common causes of this error and their solutions.
1. Missing required_providers block
Terraform requires you to declare the providers your configuration depends on. If the required_providers
block is missing, Terraform won’t know where to fetch the provider, causing an error. Terraform can usually infer the provider if it is in the default hashicorp namespace, but if you are using a provider from a custom namespace, it may not know where to find it.
In the example below, the required_providers
block is missing, so Terraform doesn’t know which provider to use:
terraform {
required_version = ">= 1.0.0"
}
resource "rabbitmq_vhost" "test" { name = "test" }
To resolve this, add the required_providers
block:
terraform {
required_providers {
rabbitmq = {
source = "cyrilgdn/rabbitmq"
version = "1.8.0"
}
}
}
provider "rabbitmq" {
endpoint = "http://127.0.0.1"
username = "guest"
password = "guest"
}
Note: Some configurations may also require a backend definition, especially when using remote state storage.
2. Provider not initialized
Terraform requires you to run terraform init
before using any provider. If you run terraform apply
without initialization, Terraform won’t have the provider installed, causing the error.
terraform init
sets up the working directory, downloads necessary providers, and resolves dependencies.
Additional fix: If you recently changed the provider or modified the state, run terraform init -reconfigure
to ensure Terraform reinitializes with the correct provider settings.
3. Incorrect provider definition
If the provider block is missing or misconfigured, Terraform won’t be able to use the required provider.
Here, we reference an AWS resource, but we haven’t defined the provider "aws"
block.
resource "aws_instance" "example" {
ami = "ami-123456"
instance_type = "t2.micro"
}
To fix this issue, add the correct provider definition:
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-123456"
instance_type = "t2.micro"
}
4. State file corruption or mismatch
If your Terraform state file (terraform.tfstate
) references a provider that is missing from the configuration, Terraform might throw the “provider configuration not present”
error.
For example, suppose we originally configured a provider like this:
provider "aws" {
region = "us-west-2"
}
Then, we modified the provider configuration to use a custom build of the AWS provider but kept using the same Terraform state.
Fix 1: Update the provider in the state
Use terraform state replace-provider
to update the provider reference in the state:
terraform state replace-provider 'registry.terraform.io/hashicorp/aws' 'registry.terraform.io/custom/aws'
Fix 2: Delete and reinitialize Terraform
If the provider state remains inconsistent, reset Terraform:
rm -rf .terraform
terraform init
5. Terraform version mismatch
The "provider configuration not present"
error can occur if Terraform is upgraded without ensuring compatibility with the provider version.
Suppose we initially used Terraform 0.12 with the AWS provider:
terraform {
required_version = "0.12.0"
}
provider "aws" {
region = "us-west-1"
}
Then, we upgraded Terraform to 1.6.0, but the provider version is outdated.
To fix this, we need to update the provider version to be compatible with Terraform:
terraform {
required_version = ">= 1.6.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
Then run terraform init -upgrade
to update the provider to the latest compatible version.
6. Module provider configuration missing
If a Terraform module relies on an implicit provider but doesn’t receive an explicit provider configuration, Terraform cannot use it.
Here, the module is using the AWS provider but lacks an explicit provider configuration:
# Root module (main.tf)
module "my_module" {
source = "./my_module"
}
# Inside my_module (my_module/main.tf)
resource "aws_s3_bucket" "example" {
bucket = "my-test-bucket"
}
To resolve this, declare the provider explicitly where you are calling the module:
provider "aws" {
region = "us-east-1"
}
module "my_module" {
source = "./my_module"
}
Similarly, if you want to use multiple providers for your modules, to deploy your infrastructure in different regions, for example, you should declare providers with aliases, and then explicitly add a providers block at the module level.
provider "aws" {
alias = "east"
region = "us-east-1"
}
provider "aws" {
alias = "west"
region = "us-west-2"
}
module "east_module" {
source = "./my_module"
providers = {
aws = aws.east
}
}
module "west_module" {
source = "./my_module"
providers = {
aws = aws.west
}
}
Note: By default, modules inherit providers from the root module. However, explicit provider passing is required when using multiple providers.
7. Multiple provider versions in different modules
When working with Terraform modules, different modules might require different versions of the same provider. Terraform allows defining provider versions at both the root level and module level, but misconfigurations can lead to the "provider configuration not present"
error.
Imagine a scenario where the root configuration uses AWS provider version 5.0, but a module called inside the configuration requires 4.0. If the versions are not correctly defined, Terraform may fail to find the appropriate provider version.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
module "old_module" {
source = "./old_module"
}
Here, the module implicitly inherits the root provider, but if old_module was written for AWS provider version 4.0, it may not work correctly. Terraform does not automatically resolve version mismatches across modules.
To resolve this issue, you will have to move the module to a different configuration or create a copy of the AWS provider and use it from a different namespace to call it with a different version.
Root module (main.tf):
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
aws resources..
Child module (other_configuration/main.tf
):
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" {
region = “us-east-1”
}
module "old_module" {
source = "./old_module"
}
If you are unsure about the provider versions being used, run:
terraform providers
This command lists all available providers and their versions across modules. If a module lacks an explicit provider, it will be shown as "provider configuration not present"
.
These advanced edge cases can cause "provider configuration not present"
errors in Terraform, even when the configuration appears correct.
Here’s a summary of these cases with possible solutions:
Edge case | Issue | Solution |
Provider in different directory | Provider is not inherited across directories | Use providers block when calling a module |
Conflicting provider versions | Root and module require different configurations | Define multiple provider configurations using alias and explicitly reference them in modules |
Provider missing in workspaces | Workspace-specific provider not initialized | Run terraform init -reconfigure when switching workspaces. Ensure workspace-specific backend configuration is properly set up. |
Network issues blocking provider download | Firewall/proxy blocks Terraform downloads | Manually mirror providers or set up a local registry. Set TF_PLUGIN_CACHE_DIR to cache providers locally. |
New module added but not initialized | terraform apply run before terraform init |
Always run terraform init -upgrade when adding modules and use terraform get to fetch new module dependencies. |
Authentication issues with cloud providers | No credentials provided | Check authentication methods (env vars , profiles , IAM roles ), and verify token validity. Use environment variables, profiles, or IAM roles |
In this article, we covered the "provider configuration not present"
error, its causes, and solutions in Terraform.
We encourage you to explore how Spacelift makes it easy to work with Terraform. If you need help managing your Terraform infrastructure, building more complex workflows based on Terraform, and managing AWS credentials per run, instead of using a static pair on your local machine, Spacelift is a fantastic tool for this.
To learn more about Spacelift, create a free account today or book a demo with one of our engineers.
Note: New versions of Terraform are placed under the BUSL license, but everything created before version 1.5.x stays open-source. OpenTofu is an open-source version of Terraform that expands on Terraform’s existing concepts and offerings. It is a viable alternative to HashiCorp’s Terraform, being forked from Terraform version 1.5.6.