I want to connect to RDS instance through ssh tunnel in bastion host. I tried with a terraform provider (https://github.com/flaupretre/terraform-ssh-tunnel) When i run the code, i get following error
file not found: tunnel.sh
I tried to achieve the ssh tunnel by myself, do i used below code
resource "null_resource" "ssh-tunnel" {
provisioner "local-exec" {
command = "ssh -i ./test.pem -L 54320:{aws-rds-endpoint}:5432 -f ec2-user@{bastion-public-ip} -v >./stdout.log 2>./stderr.log"
}
triggers = {
always_run = timestamp()
}
}
I used triggers always because the tunnel will be killed in CI step. However i am unable to do create ssh tunnel, it does not gives any error but the tunnel is not created. Below is the error
╷
│ Error: error detecting capabilities: error PostgreSQL version: read tcp
[::1]:57115->[::1]:54320: read: connection reset by peer
│
│ with postgresql_role.app_roles["settings"],
│ on main.tf line 150, in resource "postgresql_role" "app_roles":
│ 150: resource "postgresql_role" "app_roles" {
│
╵
I tried to create another ssh tunnel in same port (54320) and i was able to, which means the tunnel was not created by terraform.
Can someone help me please.
Thanks,