flaupretre/terraform-ssh-tunnel

Connection reset by peer

Closed this issue · 1 comments

Hi, i'm currently in the process of wrapping my things around this module, provider aliases and passing provider aliases to own created modules. However, i am encountering a problem and would be happy to get some feedback if i configured everything correctly.

This is the module/provider config in my terraform root:

module "db_tunnel" {
  source = "flaupretre/tunnel/ssh"
  version = "1.10.0"
  
  target_host = module.rds_postgres.postgres_ip
  target_port = 5432

  ssh_cmd = "ssh -o StrictHostKeyChecking=no -i ~/.ssh/tsms_id_rsa.pub"

  gateway_host = module.admin_vm.admin_vm_ip
}

provider "postgresql" {
  alias = "tunnel"
  host = "${module.db_tunnel.host}"
  port = "${module.db_tunnel.port}"
  database = "postgres"
  username = "root"
  password = module.rds_postgres.postgres_password
}

Now, i want to use this postgresql.tunnel provider in a submodule. I call this submodule and forward the alias to it:

module "harbor" {
  source          = "../modules/harbor"
  providers = {
    postgresql-tunnel = postgresql.tunnel
   }
  env             = var.env
}

Inside the submodule i am calling the postgresql-tunnel provider which i have configured to use the Postgresql Provider

resource "postgresql_role" "harbor_role" {
  provider = postgresql-tunnel
  name = "harbor"
  login = true
  password = random_password.postgresql_password.result
  
}

A terraform plan detects that the role does not exist yet, which is correct, and wants terraform to create it. However, the call of terraform apply crashes:

module.harbor.postgresql_role.harbor_role: Creating...
╷
│ Error: error detecting capabilities: error PostgreSQL version: read tcp 127.0.0.1:35864->127.0.0.1:58741: read: connection reset by peer
│ 
│   with module.harbor.postgresql_role.harbor_role,
│   on ../modules/harbor/database.tf line 9, in resource "postgresql_role" "harbor_role":
│    9: resource "postgresql_role" "harbor_role" {
│ 
╵

I have no idea why this forwarding from localhost to localhost happens. Are there some internals in your module which i do not seem to understand yet?

Nevermind, my error