-
Notifications
You must be signed in to change notification settings - Fork 78
How to work with postgresql resource through bastion host? #42
Comments
We are also looking for a way to do this. It would be great if the provider could support this! For example, other PostgreSQL tools support this, like Postico and pgAdmin etc. I think it could work like this on the provider: provider "postgresql" {
host = "${var.db_host}"
port = "${var.db_port}"
username = "${var.db_master_user}"
password = "${var.db_master_password}"
database = "${var.db_name}"
tunnel = {
type = "ssh"
private_key = "~/.ssh/some-key_id"
bastion_host = "my-ssh-bastion.domain.com"
bastion_port = 22
}
}
resource "postgresql_role" "api_role" {
name = "api"
password = "${var.db_role_api_password}"
} |
If anyone know any workaround to solve this problem please let know.
|
Any progress on this? How can one even not have this feature, I mean everything in AWS should be in VPC right? |
Unfortunately, not being able to pass ssh tunnel configs to the provider is a big show stopper for us. Would be more than awesome having a configs like this. I managed to work around by using @andreichernov answer AND version v0.1.0 (which waits before trying to connect, so there is time for the Anyways, thanks a lot for the work so far and a big +1 to this feature request! |
I successfully use VPN that gives me access to VPC. |
Simple workaround for those who do not want to install VPN. It proxies all traffic to specific IP address through bastion host using SSH.
Then run terraform as you would normally. |
An unmentioned but also valid way to accomplish this is by setting up a tunnel using SSH, then running terraform with
|
@hatch-carl : The challenge here is that the remote endpoint of PostgreSQL (Amazon RDS) will only be created within the course of executing Terraform. At the time of starting "terraform plan", there is nothing. No VPC to tunnel into, no bastion host, no database. At the time of starting "terraform apply", there may also be nothing. The entire environment will only be created by Terraform. So, in essence, two features are needed:
Cheers, |
Any update here? Thank you. |
Not as far as I know... It's been quiet and there were no announcements into this direction. I'm still fiddling with workarounds. |
There is a preliminary draft that has been opened by @dominik-lekse. It looks like some progress has stalled. He does state that he's willing to open up write access for those interested in contributing, however, he doesn't state what the limitations he's experiencing are. I'm not particularly knowledgeable of Go, but would be willing to pitch in if I had an idea of how to contribute. Or if someone who knows Go/Terraform could push this across the finish line, there is a cold beer waiting for them from me :D |
I blogged about the workaround mentioned here in detail: https://minhajuddin.com/2020/05/09/how-to-use-a-single-aurora-cluster-for-multiple-databases-each-with-its-own-restricted-user/#Connecting-to-an-RDS-database-via-an-SSH-tunnel . This requires you to have an SSH tunnel open while terraform runs a plan or apply. |
Thanks for the blog post. This of course requires the existence of the Bastion host, making dependencies tricky. One cannot stand up a given infrastructure in one go, let alone without prior knowledge or additional tooling to complete the infrastructure application. :( |
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
but after
terraform plan
terraform gives an errorError 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:
or I can add null resource:
but I am looking for right terraform way to solve this.
The text was updated successfully, but these errors were encountered: