diff --git a/helper/communicator/config.go b/helper/communicator/config.go index 55f408076..01f93b023 100644 --- a/helper/communicator/config.go +++ b/helper/communicator/config.go @@ -179,7 +179,7 @@ type WinRM struct { // [`ssh_interface`](/docs/builders/amazon-ebs#ssh_interface) WinRMHost string `mapstructure:"winrm_host"` // Setting this to `true` adds the remote - // `host:post` to the `NO_PROXY` environment variable. This has the effect of + // `host:port` to the `NO_PROXY` environment variable. This has the effect of // bypassing any configured proxies when connecting to the remote host. // Default to `false`. WinRMNoProxy bool `mapstructure:"winrm_no_proxy"` diff --git a/helper/communicator/step_connect_winrm.go b/helper/communicator/step_connect_winrm.go index 6c37719ef..2600440ee 100644 --- a/helper/communicator/step_connect_winrm.go +++ b/helper/communicator/step_connect_winrm.go @@ -205,11 +205,6 @@ func (s *StepConnectWinRM) waitForWinRM(state multistep.StateBag, ctx context.Co func setNoProxy(host string, port int) error { current := os.Getenv("NO_PROXY") p := fmt.Sprintf("%s:%d", host, port) - // not set - // set - // is set and not contains - // set - // is set and contains if current == "" { return os.Setenv("NO_PROXY", p) } @@ -233,7 +228,12 @@ func envProxyFunc() func(*url.URL) (*url.URL, error) { return envProxyFuncValue } -// c.WinRMTransportDecorator = func() winrm.Transporter { return &winrm.ClientNTLM{} } +// ProxyTransportDecorator is a custom Transporter that reloads HTTP Proxy settings at client runtime. +// The net/http ProxyFromEnvironment only loads the environment once, when the +// code is initialized rather than when it's executed. This means that if your +// wrapping code sets the NO_PROXY env var (as Packer does!), it will be +// ignored. Re-loading the environment vars is more expensive, but it is the +// easiest way to work around this limitation. func ProxyTransportDecorator() winrmcmd.Transporter { return winrmcmd.NewClientWithProxyFunc(RefreshProxyFromEnvironment) } diff --git a/website/pages/partials/helper/communicator/WinRM-not-required.mdx b/website/pages/partials/helper/communicator/WinRM-not-required.mdx index 99ea7c9b3..7aee05b63 100644 --- a/website/pages/partials/helper/communicator/WinRM-not-required.mdx +++ b/website/pages/partials/helper/communicator/WinRM-not-required.mdx @@ -11,7 +11,7 @@ [`ssh_interface`](/docs/builders/amazon-ebs#ssh_interface) - `winrm_no_proxy` (bool) - Setting this to `true` adds the remote - `host:post` to the `NO_PROXY` environment variable. This has the effect of + `host:port` to the `NO_PROXY` environment variable. This has the effect of bypassing any configured proxies when connecting to the remote host. Default to `false`.