warrensbox/terraform-switcher

Is tfswitch using http_proxy and https_proxy env vars

Opened this issue · 2 comments

Hi,

we are encountering a problem with tfswitch behind a web proxy. We have configured the following env vars:

  • http_proxy
  • https_proxy
  • HTTP_PROXY
  • HTTPS_PROXY

We are getting a timeout when we try to download a specific version of terraform behind a web proxy.

Best regards
Fabian

Hi,

looking at download.go I see that the "default" go http client from net/http is being used to download the releases.
From what I see in the implementation of net/http/transport.go (lines 37-53 and 421 - 447) the client already supports the usage of the environment variables mentioned above.

Based on the example on this page I would assume that the call of http.Get in download.go is not sufficent to actually use a proxy. It seems to me that you have to instantiate a Client by passing an instance of Transport (which seems to be in charge of handling the proxy settings as seen above).

tr := &http.Transport{
//...
}
client := &http.Client{Transport: tr}
resp, err := client.Get("https://example.com")

Can someone confirm?

Hi,

seems that my assumption was wrong. Get uses DefaultClient which uses DefaultTransport. As for DefaultTransport:

It uses HTTP proxies as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy) environment variables.

So from my understanding does tfswitch actually support the environment variables and the error must lie elsewhere.