Software Engineering

[Solved] Terraform Error accessing remote module registry in PowerShell

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 Failed to request discovery document: Get "": 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:


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>", [EnvironmentVariableTarget]::Process)
[Environment]::SetEnvironmentVariable("HTTPS_PROXY","http://<USER>:<PASSWORD>", [EnvironmentVariableTarget]::Process)
[Environment]::SetEnvironmentVariable("NO_PROXY","", [EnvironmentVariableTarget]::Process)