[Solved] Terraform Error accessing remote module registry in PowerShell

0 min read 127 words

If you are using PowerShell and trying to run a terraform init, you may get an error as follows:

Error: error accessing remote module registry

Failed to retrieve available versions for module ... from registry.terraform.io: Failed to request discovery document: Get "https://registry.terraform.io/.well-known/terraform.json": read tcp x.x.x.x:xxxx->x.x.x.x: wsarecv: An existing connection was forcibly closed by the remote host..

Note that you will still be able to make a successful curl request, but terraform will fail!

The problem

You need to make sure you have a proxy set.

The Windows Command Prompt lets you set a proxy as follows:

SET HTTP_PROXY=http://<USER>:<PASSWORD>@proxy.host.com:8080
SET HTTPS_PROXY=http://<USER>:<PASSWORD>@proxy.host.com:8080
SET NO_PROXY=.yourcompany.com

The solution

PowerShell will still fail, as it required the proxy environment variables to also be set as follows:

[Environment]::SetEnvironmentVariable("HTTP_PROXY","http://<USER>:<PASSWORD>@proxy.host.com:8080/", [EnvironmentVariableTarget]::Process)
[Environment]::SetEnvironmentVariable("HTTPS_PROXY","http://<USER>:<PASSWORD>@proxy.host.com:8080/", [EnvironmentVariableTarget]::Process)
[Environment]::SetEnvironmentVariable("NO_PROXY",".yourcompany.com", [EnvironmentVariableTarget]::Process)
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts