Skip to content

Commit

Permalink
Merge pull request #12 from randomcuriouscode/add-extra-sleep
Browse files Browse the repository at this point in the history
Add an optional extra sleep before checking the child ssh tunnel process status
  • Loading branch information
flaupretre authored May 11, 2022
2 parents 3c3e876 + 7a7ad18 commit 6d784b0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ No modules.
| <a name="input_target_host"></a> [target\_host](#input\_target\_host) | The target host. Name will be resolved by gateway | `string` | n/a | yes |
| <a name="input_target_port"></a> [target\_port](#input\_target\_port) | Target port number | `number` | n/a | yes |
| <a name="input_timeout"></a> [timeout](#input\_timeout) | Timeout value ensures tunnel cannot remain open forever | `string` | `"30m"` | no |
| <a name="input_ssh_tunnel_check_sleep"></a> [ssh\_tunnel\_check\_sleep](#input\_ssh\_tunnel\_check\_sleep) | Extra wait time allows for accounting for slow ssh tunnel establish time | `string` | `"0s"` | no |

## Outputs

Expand Down
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data external ssh_tunnel {
target_port = var.target_port,
gateway_host = local.gw,
gateway_port = var.gateway_port,
shell_cmd = var.shell_cmd
shell_cmd = var.shell_cmd,
ssh_tunnel_check_sleep = var.ssh_tunnel_check_sleep
}
}
3 changes: 3 additions & 0 deletions tunnel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if [ -z "$MPID" ] ; then
export GATEWAY_HOST="`echo $query | sed -e 's/^.*\"gateway_host\": *\"//' -e 's/\".*$//g'`"
export GATEWAY_PORT="`echo $query | sed -e 's/^.*\"gateway_port\": *\"//' -e 's/\".*$//g'`"
export SHELL_CMD="`echo $query | sed -e 's/^.*\"shell_cmd\": *\"//' -e 's/\",.*$//g' -e 's/\\\"/\"/g'`"
export SSH_TUNNEL_CHECK_SLEEP="`echo $query | sed -e 's/^.*\"ssh_tunnel_check_sleep\": *\"//' -e 's/\",.*$//g' -e 's/\\\"/\"/g'`"

echo "{ \"host\": \"$LOCAL_HOST\" }"
p=`ps -p $PPID -o "ppid="`
Expand All @@ -50,6 +51,8 @@ else

$SSH_CMD -N -L localhost:$LOCAL_PORT:$TARGET_HOST:$TARGET_PORT -p $GATEWAY_PORT $GATEWAY_HOST &
CPID=$!

sleep $SSH_TUNNEL_CHECK_SLEEP

while true ; do
if ! ps -p $CPID >/dev/null 2>&1 ; then
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ variable "timeout" {
description = "Timeout value ensures tunnel cannot remain open forever"
default = "30m"
}

variable "ssh_tunnel_check_sleep" {
type = string
description = "extra time to wait for ssh tunnel to connect"
default = "0s"
}

0 comments on commit 6d784b0

Please sign in to comment.