AndrewChubatiuk / terraform-provider-ssh

This provider enables SSH port forwarding in Terraform.
Mozilla Public License 2.0
8 stars 9 forks source link

Multiple tunnels #8

Open chrs-myrs opened 1 year ago

chrs-myrs commented 1 year ago

Yours is the most reliable SSH tunnel for terraform, but was very sad when I tried to add a second tunnel

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_version = ">= 1.0.9"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
    ssh = {
      source  = "AndrewChubatiuk/ssh"
      version = "0.1.5"
    }
    mysql = {
      source  = "petoju/mysql"
      version = "3.0.18"
    }
    redshift = {
      source = "brainly/redshift"
      version = "1.0.2"
    }
  }

  backend "s3" {
...
  }
}

provider "aws" {
...
}

provider "ssh" {}

data "ssh_tunnel" "mysql" {
  user = var.bastion_username
  auth {
    private_key {
      content = file(pathexpand("~/.ssh/id_rsa"))
    }
  }
  server {
    host = "---"
  }
  remote {
    host = "rds.${local.env}.local"
    port = 3306
  }
}

provider "mysql" {
  endpoint = data.ssh_tunnel.mysql.local.0.address
  username = "${local.env}_master"
  password = data.aws_ssm_parameter.cluster_password.value
  tls      = false
}

data "aws_ssm_parameter" "cluster_password" {
  name            = "---"
  with_decryption = true
}

data "ssh_tunnel" "redshift" {
  user = var.bastion_username
  auth {
    private_key {
      content = file(pathexpand("~/.ssh/id_rsa"))
    }
  }
  server {
    host = "bastion.---"
  }
  local {
    port = 5439
  }
  remote {
    host = "redshift.---"
    port = 5439
  }
}

Expected Behavior

Open two tunnels

Actual Behavior

Fail with rror: rpc: service already defined: SSHTunnelServer

Steps to Reproduce

  1. Add two ssh_tunnel data blocks
AndrewChubatiuk commented 1 year ago

Added ability to run multiple tunnels in v0.2.2