This error occurs when Terraform cannot retrieve provider packages from the registry due to network issues, version constraint mismatches, or authentication problems. Resolving it typically involves checking connectivity, updating version constraints, or using the -upgrade flag.
When you run `terraform init`, Terraform queries the Terraform Registry (registry.terraform.io) to download provider plugins specified in your configuration. This error indicates that Terraform failed to connect to the registry or retrieve the provider packages matching your version constraints. The failure can stem from network connectivity issues, DNS resolution problems, misconfigured version constraints in your Terraform files, authentication issues with private registries, or temporary unavailability of the Terraform Registry itself.
First, check if you can reach the Terraform Registry:
ping registry.terraform.io
curl -I https://registry.terraform.ioIf both commands fail, your network is blocking access to the registry. Check your firewall rules, proxy settings, and ensure you have internet connectivity.
Delete the local Terraform cache and lock file, then reinitialize:
rm -rf .terraform
rm .terraform.lock.hcl
terraform initThis forces Terraform to re-fetch all provider information from the registry.
If you have version constraints that don't match available releases, use the -upgrade flag:
terraform init -upgradeThis tells Terraform to select new provider versions that satisfy your constraints, rather than using locked versions.
Verify your required_providers block in your Terraform files. Ensure version constraints are valid:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}Run terraform providers to see what version constraints are active:
terraform providersIf constraints conflict between modules, adjust them so they have overlapping version ranges.
Some providers have multiple source addresses. For example, the DataDog provider is datadog/datadog, not hashicorp/datadog. Check the official Terraform Registry documentation for the correct source:
required_providers {
datadog = {
source = "datadog/datadog" # Correct
version = "~> 3.0"
}
}If you're using a VPN or proxy, Go's DNS client may have issues. Try switching to a public DNS server:
export GODEBUG=netdns=go
terraform initOr configure your system to use Google's public DNS (8.8.8.8) instead of your local DNS server.
If you're in a region with restricted access to HashiCorp's repositories, configure a Terraform Registry mirror in your .terraformrc or terraform.rc file:
provider_installation {
network_mirror {
url = "https://terraform-mirror.example.com"
}
direct {
exclude = ["hashicorp/*"]
}
}Contact your infrastructure team for the correct mirror URL.
Ensure your Terraform version is compatible with the providers you're trying to use:
terraform versionConsult the provider documentation for minimum Terraform version requirements. If your Terraform version is too old, upgrade it:
terraform -install-dir=/usr/local/bin upgradeOr use a version manager like tfenv to switch versions.
Provider resolution in Terraform is a multi-step process: first, Terraform parses your configuration to identify required providers and version constraints. Then it queries the Terraform Registry API to find matching releases. If using a private registry or mirror, Terraform connects to that instead. The error can occur at any of these stages.
For module development, follow the best practice of specifying only minimum provider versions (e.g., >= 1.0) in reusable modules, and let the root module manage maximum versions. This prevents version conflicts when modules are composed together.
If you frequently encounter registry connectivity issues in CI/CD pipelines, consider using terraform init -lock=false to skip lock file generation and pre-cache providers in your CI image to reduce registry queries.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform