Quick Answer
# Check if you can reach the registry
curl -sI https://registry.terraform.io | head -5
# If behind a proxy
export HTTPS_PROXY=http://proxy.corp.com:8080
terraform init
The Error
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
hashicorp/aws: could not connect to registry.terraform.io:
connection refused
Or:
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
hashicorp/aws: provider registry registry.terraform.io does not
have a provider named registry.terraform.io/hashicorp/aws
What Causes This
- No internet access — air-gapped environment or network down
- Firewall/proxy blocking — corporate firewall blocks
registry.terraform.io - Wrong provider source —
source = "aws"instead ofsource = "hashicorp/aws" - DNS resolution failure — can’t resolve
registry.terraform.io - TLS inspection — corporate proxy intercepts HTTPS with custom CA
Solution 1: Check Network Connectivity
# Test registry access
curl -sI https://registry.terraform.io
# Should return HTTP/2 200
# Test DNS
nslookup registry.terraform.io
# Test with verbose output
curl -v https://registry.terraform.io/v1/providers/hashicorp/aws/versions 2>&1 | head -20
Solution 2: Configure Proxy
# Set proxy for current session
export HTTP_PROXY=http://proxy.corp.com:8080
export HTTPS_PROXY=http://proxy.corp.com:8080
export NO_PROXY=localhost,127.0.0.1,.internal.corp.com
terraform init
For persistent config, add to ~/.bashrc or use Terraform CLI config:
# ~/.terraformrc
host "registry.terraform.io" {
services = {
"providers.v1" = "https://registry.terraform.io/v1/providers/"
}
}
Solution 3: Fix Provider Source
# ❌ Legacy format (Terraform 0.12 and earlier)
provider "aws" {
version = "~> 5.0"
}
# ✅ Correct format (Terraform 0.13+)
terraform {
required_providers {
aws = {
source = "hashicorp/aws" # namespace/type
version = "~> 5.0"
}
}
}
Common source mistakes:
| Wrong | Correct |
|---|---|
source = "aws" | source = "hashicorp/aws" |
source = "google" | source = "hashicorp/google" |
source = "kubernetes" | source = "hashicorp/kubernetes" |
source = "datadog" | source = "DataDog/datadog" |
Solution 4: Filesystem Mirror (Air-Gapped)
For environments without internet access:
# On a machine WITH internet — download providers
terraform providers mirror /path/to/mirror
# ~/.terraformrc on air-gapped machine
provider_installation {
filesystem_mirror {
path = "/opt/terraform/providers"
include = ["registry.terraform.io/*/*"]
}
}
Solution 5: Network Mirror
# ~/.terraformrc
provider_installation {
network_mirror {
url = "https://terraform-mirror.internal.corp.com/"
}
}
Solution 6: TLS Certificate Issues
# If corporate proxy intercepts TLS
# Add CA cert
export SSL_CERT_FILE=/etc/pki/tls/certs/corporate-ca.pem
# Or skip verification (NOT recommended for production)
export TF_SKIP_PROVIDER_VERIFY=true
Hands-On Courses
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
Conclusion
“Failed to query provider packages” is a connectivity problem between Terraform and registry.terraform.io. Check your network, configure proxy if behind a firewall, use the correct source = "hashicorp/aws" format, and set up filesystem mirrors for air-gapped environments.