flaupretre/terraform-ssh-tunnel

proxmox provider fails to use tunnel

Closed this issue · 2 comments

or i fail to read the docs... probably/hopefully the latter

files:

terraform {
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
      version = ">= 2.9.14"
    }
  }
}

module proxmox_tunnel {
  # You can also retrieve this module from the terraform registry
  source       = "flaupretre/tunnel/ssh"
  version      = "2.0.4"

  target_host  = "${var.proxmoxinternalhostip}"
  target_port  = "${var.proxmoxremotehostport}"

  gateway_host = "${var.proxmoxremotehostip}"
  gateway_user = "${var.proxmoxremotehostuser}"

  ssh_cmd = "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -i ${var.proxmoxremotehostkeypath}"
}

provider "proxmox" {
  pm_debug = true
  pm_api_url = "https://127.0.0.1:${var.proxmoxremotehostport}/api2/json"
  pm_tls_insecure = true
}

yet the tunnel is not established at time the proxmox provider tries to open a connection.
neither is there an error if i have a tunnel open and the same port is occupied

I have no personal experience using proxmox but, from what I see, you want to use an SSH tunnel to access a remote resource (whose IP is var.proxmoxinternalhostip) using an SSH gateway located at var.proxmoxremotehostip.

If it is the case, you must use the host and port retruned by the tunnel module. Your 'pm_api_url' should be modified to :

pm_api_url = "https://${module.proxmox_tunnel.host}:${module.proxmox_tunnel.port}/api2/json"

This way, the proxmox provider should connect to the newly-created tunnel.

If your proxmox gateway is not using the standard SSH port (22), you will need to add :

gateway_port = ${var.proxmoxremotehostport}

to your proxmox_tunnel definition.

Hope this helps.

gateway_port wasnt the culprit.

local_port was.

wierdly enough if the port is already reserved there is no error message and terraform plan works as expected.