From 83855261011a19e6486b682010c40de8df087f77 Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Wed, 29 May 2019 20:31:56 -0700 Subject: [PATCH] Run ssh.Dial outside of the go-routine, in order to print a much nicer error message in case things go wrong. For example, "could not dial: dial tcp: lookup bastion.example.com: no such host", instead of a huge stack trace. --- data_source_ssh_tunnel.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/data_source_ssh_tunnel.go b/data_source_ssh_tunnel.go index 5e9a4b0..5ebd157 100644 --- a/data_source_ssh_tunnel.go +++ b/data_source_ssh_tunnel.go @@ -167,12 +167,12 @@ func dataSourceSSHTunnelRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] port: %v", port) d.Set("port", port) - go func() { - sshClientConn, err := ssh.Dial("tcp", host, sshConf) - if err != nil { - panic(err) - } + sshClientConn, err := ssh.Dial("tcp", host, sshConf) + if err != nil { + return fmt.Errorf("could not dial: %v", err) + } + go func() { // The accept loop for { localConn, err := localListener.Accept()