Fixing Terraform 'Failed to query available provider packages' – registry.terraform.io Connection Error

beginner🏗️ Terraform2026-05-28| Terraform CLI (v0.13+), Linux (Ubuntu, Debian, RHEL), macOS, Windows, Air-gapped networks, Corporate firewalls.

Error Message

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: dial tcp: lookup registry.terraform.io: no such host
#terraform#devops#networking#troubleshooting#dns

The Error Message

Running terraform init is usually a seamless process. However, everything grinds to a halt if Terraform can't talk to the HashiCorp Registry to grab providers like AWS or Azure. When your machine lacks a clear path to the internet or fails to resolve the domain, you'll hit this wall:

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: dial tcp: lookup 
registry.terraform.io: no such host

Identifying the Root Cause

Terraform effectively shouts into the void and gets no response. Since this error happens at the network layer, Terraform can't even find the IP address for registry.terraform.io. This usually boils down to three culprits:

  • DNS Failure: Your system's DNS resolver is failing to translate the domain.
  • Corporate Proxy: A firewall is intercepting traffic, requiring specific environment variables to let HTTPS traffic through port 443.
  • Total Isolation: You are working in an air-gapped environment with no physical route to the public web.

Solution 1: Manual DNS and Network Verification

Your first step is determining if the problem is system-wide or isolated to Terraform. Use nslookup or dig to test the hostname directly.

nslookup registry.terraform.io

An "NXDOMAIN" or "non-existent domain" response confirms that your DNS configuration is broken. On Linux, take a look at /etc/resolv.conf. Ensure you have reliable nameservers listed, such as Google's 8.8.8.8 or your company's internal DNS IP.

If DNS looks healthy but terraform init still hangs, try a manual handshake with the registry via curl:

curl -I https://registry.terraform.io

Solution 2: Configuring HTTP Proxies

Corporate setups often block direct outbound traffic on port 443 for security. In these cases, you must explicitly point Terraform toward your company's proxy server. Set these environment variables in your terminal before running any Terraform commands.

For Linux and macOS:

export HTTP_PROXY="http://proxy.yourcompany.com:8080"
export HTTPS_PROXY="http://proxy.yourcompany.com:8080"
export NO_PROXY="localhost,127.0.0.1,169.254.169.254"

For Windows (PowerShell):

$env:HTTP_PROXY="http://proxy.yourcompany.com:8080"
$env:HTTPS_PROXY="http://proxy.yourcompany.com:8080"

If your proxy requires a login, use the http://user:password@proxy.url:port format. Once these are set, Terraform will route its provider requests through the designated tunnel.

Solution 3: Setting Up a Local Filesystem Mirror

Offline environments require a different approach since they can't reach the registry at all. You'll need to download provider binaries on a connected machine and transfer them—often via a secure USB or internal jump box—to your offline server.

After moving the files, create a CLI configuration file (.terraformrc on Linux/macOS or terraform.rc on Windows) to tell Terraform to look locally first.

Place the following block in ~/.terraformrc:

provider_installation {
  filesystem_mirror {
    path    = "/usr/share/terraform/providers"
    include = ["hashicorp/*", "registry.terraform.io/*/*"]
  }
  direct {
    exclude = ["hashicorp/*", "registry.terraform.io/*/*"]
  }
}

Ensure your folder structure matches exactly what Terraform expects. It should look like this:

/usr/share/terraform/providers/registry.terraform.io/hashicorp/aws/5.0.0/linux_amd64/terraform-provider-aws_v5.0.0_x5

Verification

To confirm the fix, follow these three steps:

  • Nuke the local cache by deleting the .terraform/ folder and .terraform.lock.hcl.
  • Run terraform init again.
  • Check for the green checkmark: ✔ HashiCorp AWS provider v5.x.x successfully installed.

If the "Finding latest version..." step completes quickly without timing out, you're back in business.

Prevention and Best Practices

To keep your deployments stable, consider these habits:

  • Enable Global Caching: Save bandwidth and time by caching providers locally. Add plugin_cache_dir = "$HOME/.terraform.d/plugin-cache" to your configuration.
  • Lock Your Versions: Always commit .terraform.lock.hcl to Git. This prevents "it works on my machine" issues when a teammate has a different connection speed or DNS cache.
  • Audit Network Routes: If you're building in a restricted VPC, verify that your NAT Gateway or Internet Gateway is actually reachable.

When I'm mapping out network boundaries or debugging complex firewall rules, I often use an IP Subnet Calculator. It’s a simple way to verify CIDR ranges and ensure my gateways are sitting in the right spot before I waste hours chasing a DNS ghost.

Related Error Notes