🔧 Error Fixes
· 2 min read
Last updated on

Terraform: Failed to Query Available Provider Packages


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

This error means Terraform can’t download the provider plugin from the Terraform Registry. It happens during terraform init when Terraform tries to fetch provider binaries.

What causes this

Several things can prevent Terraform from reaching the registry:

  • You haven’t run terraform init yet (or need to re-run it after changing providers)
  • Network issues — corporate proxy, VPN, firewall blocking registry.terraform.io
  • Typo in the provider source name
  • The provider version you specified doesn’t exist
  • A local mirror or filesystem mirror is misconfigured

Fix 1: Run terraform init

If you just cloned a repo or added a new provider, you need to initialize:

terraform init

If you’ve changed provider versions or sources, re-initialize with the upgrade flag:

terraform init -upgrade

Fix 2: Check your provider block for typos

A wrong source name is a common cause. Make sure the source matches the registry exactly:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"    # Not "aws/aws" or "hashicorp/awss"
      version = "~> 5.0"
    }
  }
}

Check that the version constraint is valid. You can browse available versions at registry.terraform.io/providers/hashicorp/aws/latest.

Fix 3: Fix network/proxy issues

If you’re behind a corporate proxy or firewall, Terraform can’t reach the registry:

# Test connectivity
curl -I https://registry.terraform.io

# Set proxy if needed
export HTTP_PROXY=http://proxy.company.com:8080
export HTTPS_PROXY=http://proxy.company.com:8080
terraform init

If the registry is blocked entirely, you can use a filesystem mirror:

# Create a CLI config at ~/.terraformrc
provider_installation {
  filesystem_mirror {
    path    = "/usr/share/terraform/providers"
    include = ["registry.terraform.io/*/*"]
  }
}

Fix 4: Clear the plugin cache

A corrupted plugin cache can cause this error. Clear it and re-init:

rm -rf .terraform
rm -f .terraform.lock.hcl
terraform init

The .terraform.lock.hcl file pins provider versions and hashes. If it references a version that no longer exists or has a checksum mismatch, deleting it forces Terraform to re-resolve.

Fix 5: Use a specific provider version

If the ~> constraint isn’t resolving, pin to an exact version to rule out version resolution issues:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "5.31.0"  # Exact version
    }
  }
}

How to prevent it

  • Always commit .terraform.lock.hcl to version control. It ensures everyone on the team uses the same provider versions and avoids resolution issues.
  • Use version constraints like ~> 5.0 (allows 5.x but not 6.0) rather than leaving versions unconstrained.
  • If you’re in an air-gapped environment, set up a local provider mirror and configure it in your .terraformrc.