Search code examples
sshterragrunt

Activate a ssh sock5 proxy in a Terragrunt before_hook


I am trying to activate a ssh sock5 proxy before applying a RDS Terraform stack.

For this I configure the ssh command into a Terragrunt before_hook block, example below:

  before_hook "ssh_tunnel_start" {
    commands = ["init", "plan", "apply"]
    execute  = ["ssh", "-D", "3306", "-M", "-S", "/tmp/ssh-control-socket", "-fnNTC", "<bastion_host>"]
  }

If I execute the ssh command manually in my terminal it is working as expected, ssh bind the local port and then detach, but executed from the Terragrunt hook the proxy is up but the ssh command do not detach and the Terragrunt process can't continue and get stuck on the hook command.


Solution

  • I have found a working solution by using screen, maybe there is a better one.

    before_hook "ssh_tunnel_start" {
      commands = ["init", "plan", "apply"]
      execute  = ["screen", "-d", "-m", "ssh", "-D", "3306", "-M", "-S", "/tmp/ssh-control-socket", "-fnNTC", "<bastion_host>"      
    }