jaysonsantos / terraform-provider-jumphost

Terraform provider for Hashicups demo app
7 stars 6 forks source link

connect: connection refused #3

Open WhyNotHugo opened 3 years ago

WhyNotHugo commented 3 years ago

I'm always getting "connection refused":

╷
│ Error: error detecting capabilities: error PostgreSQL version: dial tcp [::1]:36843: connect: connection refused
│
│   with postgresql_database.django["staging"],
│   on postgres.tf line 17, in resource "postgresql_database" "django":
│   17: resource "postgresql_database" "django" {
│
╵

Authentication seems to be fine though, since providing a bogus username gives another error (that clearly indicates that auth has failed).

Minimal reproduction example. Note that you need to replace two values here.

terraform {
  required_providers {
    postgresql = {
      source  = "cyrilgdn/postgresql"
      version = ">=1.12.0"
    }
    jumphost = {
      source  = "jaysonsantos/jumphost"
      version = "0.0.2"
    }
  }
}

provider "jumphost" {
  # You need to replace these two values with a host and username for which
  # there's a key in your local agent.
  hostname = "ssh.example.com"
  username = "hugo"
}

provider "postgresql" {
  scheme          = "postgres"
  host            = "localhost"
  port            = data.jumphost_ssh.postgres.local_port
  database        = "postgres"
  username        = "test"
  password        = "test"
  connect_timeout = 10
  superuser       = false
}

data "jumphost_ssh" "postgres" {
  # You can leave this as-is. You'd get an error != connection refused if you can reach this.
  hostname = "example.com"
  port     = "80"
}

resource "postgresql_database" "django" {
  name = "test"
}

Run terraform init && terraform apply.

jaysonsantos commented 3 years ago

Sorry, I completely missed the notification. I will take a look as soon as possible :)

jaysonsantos commented 2 years ago

Hey there @WhyNotHugo, I was just checking this and noticed that you used port 80 to try and connect to PostgreSQL, could you double-check if port 5432 would throw the same error?

PKizzle commented 2 years ago

I can confirm that even with the port changed to 5432 I receive the same error.

This is the corresponding debug log:

[TRACE] vertex "module.db.var.jump_host_fqdn": starting visit (*terraform.nodeModuleVariable)
[TRACE] setValue: Saving value for output.kms_key_arn in state
[TRACE] vertex "output.kms_key_arn": visit complete
[TRACE] evalVariableValidations: not active for module.db.var.jump_host_fqdn, so skipping
[TRACE] vertex "module.db.var.jump_host_fqdn": visit complete
[TRACE] vertex "module.db.var.jump_host_fqdn (expand)": dynamic subgraph completed successfully
[TRACE] vertex "module.db.var.jump_host_fqdn (expand)": visit complete
[TRACE] vertex "module.db.provider[\"registry.terraform.io/hierynomus/jumphost\"]": starting visit (*terraform.NodeApplyableProvider)
[DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hashicorp/aws/3.61.0/darwin_amd64/terraform-provider-aws_v3.61.0_x5 pid=11165
[DEBUG] provider: plugin exited
[TRACE] vertex "provider[\"registry.terraform.io/hashicorp/aws\"] (close)": visit complete
[DEBUG] created provider logger: level=trace
[INFO]  provider: configuring client automatic mTLS
[DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/hierynomus/jumphost/0.1.0-pre.1/darwin_amd64/terraform-provider-jumphost_v0.1.0-pre.1 args=[.terraform/providers/registry.terraform.io/hierynomus/jumphost/0.1.0-pre.1/darwin_amd64/terraform-provider-jumphost_v0.1.0-pre.1]
[DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/hierynomus/jumphost/0.1.0-pre.1/darwin_amd64/terraform-provider-jumphost_v0.1.0-pre.1 pid=11169
[DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/hierynomus/jumphost/0.1.0-pre.1/darwin_amd64/terraform-provider-jumphost_v0.1.0-pre.1
[INFO]  provider.terraform-provider-jumphost_v0.1.0-pre.1: configuring server automatic mTLS: timestamp=2021-10-07T16:17:19.990+0200
[DEBUG] provider.terraform-provider-jumphost_v0.1.0-pre.1: plugin address: address=/var/folders/21/bwkrjbv94315x_hds_sn51wr0000gn/T/plugin026339596 network=unix timestamp=2021-10-07T16:17:20.019+0200
[DEBUG] provider: using plugin: version=5
[TRACE] provider.stdio: waiting for stdio data
[TRACE] BuiltinEvalContext: Initialized "module.db.provider[\"registry.terraform.io/hierynomus/jumphost\"]" provider for module.db.provider["registry.terraform.io/hierynomus/jumphost"]
[TRACE] buildProviderConfig for module.db.provider["registry.terraform.io/hierynomus/jumphost"]: using explicit config only
[TRACE] GRPCProvider: GetProviderSchema
[TRACE] GRPCProvider: ValidateProviderConfig
[WARN]  ValidateProviderConfig from "module.db.provider[\"registry.terraform.io/hierynomus/jumphost\"]" changed the config value, but that value is unused
[TRACE] GRPCProvider: ConfigureProvider
[INFO]  provider.terraform-provider-jumphost_v0.1.0-pre.1: 2021/10/07 16:17:20 Successfully parsed private key: ssh-rsa <SSH_KEY>: timestamp=2021-10-07T16:17:20.054+0200
[TRACE] vertex "module.db.provider[\"registry.terraform.io/hierynomus/jumphost\"]": visit complete
[TRACE] vertex "module.db.provider[\"registry.terraform.io/hierynomus/jumphost\"] (close)": starting visit (*terraform.graphNodeCloseProvider)
[TRACE] GRPCProvider: Close
[TRACE] dag/walk: upstream of "module.db (close)" errored, so skipping
[TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
[DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
[DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/hierynomus/jumphost/0.1.0-pre.1/darwin_amd64/terraform-provider-jumphost_v0.1.0-pre.1 pid=11169
[DEBUG] provider: plugin exited
[TRACE] vertex "module.db.provider[\"registry.terraform.io/hierynomus/jumphost\"] (close)": visit complete
[TRACE] dag/walk: upstream of "root" errored, so skipping