Skip to main content

Fix Terraform Error: Failed to Query Available Provider Packages

Key Takeaway

Fix terraform failed to query available provider packages. Check network connectivity, configure proxy settings, use filesystem mirrors for air-gapped environments, and fix provider source format.

Table of Contents

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

  1. No internet access — air-gapped environment or network down
  2. Firewall/proxy blocking — corporate firewall blocks registry.terraform.io
  3. Wrong provider sourcesource = "aws" instead of source = "hashicorp/aws"
  4. DNS resolution failure — can’t resolve registry.terraform.io
  5. 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:

WrongCorrect
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

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.

🚀

Level Up Your Terraform Skills

Hands-on courses, books, and resources from Luca Berton

Luca Berton
Written by

Luca Berton

DevOps Engineer, AWS Partner, Terraform expert, and author. Creator of Ansible Pilot, Terraform Pilot, and CopyPasteLearn.