terraform,

Resolve Terraform's 'net/http: request canceled while waiting for connection'

Apr 01, 2023 · 1 min read · Post a comment

Today’s error of the week is linked to the following Terraform issue:

│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/google: could not connect to registry.terraform.io: Failed to request
│ discovery document: Get "https://registry.terraform.io/.well-known/terraform.json": net/http: request canceled while waiting for connection
│ (Client.Timeout exceeded while awaiting headers)

Prerequisites

  • Terraform

Solution

As for the solution, mostly it comes down to a networking DNS, or a cache issue. So, try the following:

  • Check and update your DNS settings. Try adding Google’s and Cloudflare’s DNS servers: 8.8.8.8, 1.1.1.1.
  • Reconnect to your internet connection.
  • Try using a VPN instead.
  • Run dig registry.terraform.io.
  • Include disable_checkpoint = true in your .terraformrc file.
  • Clear Terraform cache: rm -rf .terraform then rerun terraform init.

Conclusion

When nothing works, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.