How to Fix 'Provider Not Found' Error in Terraform
The
provider not found error in Terraform happens when Terraform can't find the provider plugin you declared. To fix it, ensure you have a proper provider block in your configuration and run terraform init to download the provider plugins.Why This Happens
This error occurs because Terraform cannot locate the provider plugin needed to manage resources. This usually happens if the provider block is missing or incorrectly configured, or if terraform init was not run to download the provider.
hcl
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
# Missing provider block below causes error
resource "aws_s3_bucket" "example" {
bucket = "my-bucket"
acl = "private"
}Output
Error: Could not satisfy plugin requirements
Provider "aws" not found. Terraform requires providers to be explicitly declared with a source and version.
The Fix
Add a provider block to your Terraform configuration to specify the provider settings. Then run terraform init to download the provider plugin. This tells Terraform where to find the provider and ensures it is installed.
hcl
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "example" {
bucket = "my-bucket"
acl = "private"
}Output
Terraform has been successfully initialized!
You may now run 'terraform plan' to see the changes.
Prevention
Always declare your providers explicitly with required_providers and provider blocks. Run terraform init after any change to providers. Use version constraints to avoid unexpected upgrades. Consider using Terraform modules to manage providers consistently.
Related Errors
- Plugin not installed: Run
terraform initto install missing plugins. - Version mismatch: Check your provider version constraints and update accordingly.
- Incorrect provider source: Verify the
sourceattribute matches the official provider namespace.
Key Takeaways
Always declare providers explicitly with required_providers and provider blocks.
Run terraform init to download and install provider plugins before applying.
Use version constraints to control provider versions and avoid surprises.
Check provider source names carefully to match official namespaces.
Use modules and consistent provider declarations to prevent errors.