This repository was archived by the owner on Nov 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
This repository was archived by the owner on Nov 14, 2020. It is now read-only.
How to work with postgresql resource through bastion host? #42
Copy link
Copy link
Open
Description
This issue was originally opened by @andreichernov as hashicorp/terraform#18591. It was migrated here as a result of the provider split. The original body of the issue is below.
How I can make some actions with Postgresql db on AWS RDS through bastion host in the same VPC
provider "postgresql" {
host = "${var.db_host}"
port = "${var.db_port}"
username = "${var.db_master_user}"
password = "${var.db_master_password}"
database = "${var.db_name}"
}
resource "postgresql_role" "api_role" {
name = "api"
superuser = false
create_database = true
login = true
password = "${var.db_role_api_password}"
create_role = false
connection {
type = "ssh"
host = "${var.db_host}"
port = 5432
private_key = "${var.private_key}"
bastion_host = "${var.bastion_public_ip}"
bastion_port = 22
bastion_host_key = "${var.public_key}"
bastion_private_key = "${var.private_key}"
bastion_user = "ec2-user"
}
but after terraform plan terraform gives an error Error initializing PostgreSQL client: error detecting capabilities: error PostgreSQL version: dial tcp 10.0.31.22:5432: getsockopt: connection timed out
Of course, I know that I can create following ssh config on my local PC:
Host bastion-multiplex
HostName _bastion-public-ip-here_
Port 22
User ec2-user
IdentityFile _path-to-ssh-key-here_
ControlMaster auto
ControlPersist 20m
LocalForward 54320 some-name.rds.amazonaws.com:5432
or I can add null resource:
resource "null_resource" "ssh-tunnel" {
depends_on = ["aws_instance.bastion"]
provisioner "local-exec" {
command = "ssh -i ${path.root}/${var.environment_tier}.pem -L 54320:${var.db_host}:${var.db_port} ec2-user@${local.bastion_public_ip} -N"
}
}
but I am looking for right terraform way to solve this.
renatoargh, mavogel, voltechs, J0zi, theintz and 8 morebarryib
Metadata
Metadata
Assignees
Labels
No labels