0
votes

This post has a solution for remote-exec : How can I start a remote service using Terraform provisioning?

I am trying to do the same with local-exec provisioner.

I need to open ssh tunnel on remote node:

  #create remote SSH reverse tunnel
  provisioner "local-exec" {
    command = <<EOT
      ssh-keygen -f "$HOME/.ssh/known_hosts" -R "${self.ip}";
      nohup ssh -oStrictHostKeyChecking=no -N -R ${var.chef_zero_port}:localhost:${var.chef_zero_port} ${var.ssh_username}@${self.ip} -M -S /tmp/.ssh_to_${self.ip} &
      sleep 2
    EOT
    interpreter = ["/bin/bash","-c"]
  }

tunnel is created but Terraform does not move on to next step.

same if I replace ssh command with:

ssh -oStrictHostKeyChecking=no -fN -R ${var.chef_zero_port}:localhost:${var.chef_zero_port} ${var.ssh_username}@${self.ip} -M -S /tmp/.ssh_to_${self.ip};

any ideas?

1

1 Answers

0
votes

Terraform is waiting for all child processes to exit. nohup is detaching from the terminal, but it's still a child process. Try using disown to move the child to init (process 1).