cyrilgdn / terraform-provider-postgresql

Terraform PostgreSQL provider
https://www.terraform.io/docs/providers/postgresql/
Mozilla Public License 2.0
397 stars 204 forks source link

error PostgreSQL version: dial tcp: lookup 192.168.1.1:53: server misbehaving #272

Open beasteers opened 1 year ago

beasteers commented 1 year ago
│ Error: error detecting capabilities: error PostgreSQL version: 
         dial tcp: lookup postgresql.default.svc.cluster.local 
         on 192.168.1.1:53: server misbehaving

Essentially, I'm having DNS trouble with the terraform postgres provider. It should probably be using some 10.0.0.10:53 nameserver or something for the internal cluster (?) I think? But instead, it's trying to lookup the postgres service using the LAN dns.

How can I use this provider with a local cluster service name? I would have thought it would work out of the box. I'd prefer not having to expose postgres to the public, but maybe I'm misunderstanding how this works.

Thanks!

Terraform Version

$ terraform -v
Terraform v1.3.6
on darwin_amd64
+ provider registry.terraform.io/cyrilgdn/postgresql v1.17.1
+ provider registry.terraform.io/hashicorp/azurerm v3.32.0
+ provider registry.terraform.io/hashicorp/helm v2.7.1
+ provider registry.terraform.io/hashicorp/kubernetes v2.16.0
+ provider registry.terraform.io/hashicorp/null v3.2.1
+ provider registry.terraform.io/hashicorp/random v3.4.3
+ provider registry.terraform.io/mrparkers/keycloak v4.1.0

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

Here's the relevant config

terraform {
  required_providers {
    postgresql = {
      source = "cyrilgdn/postgresql"
      version = "1.17.1"
    }
  }
}

# setup postgres

resource "helm_release" "postgresql" {
  # also tested with https://charts.timescale.com timescaledb-single
  chart      = "postgresql"
  name       = "postgresql"
  repository = "https://charts.bitnami.com/bitnami"
  namespace  = var.namespace

  values = [
    templatefile("${path.module}/values/postgres.values.yml", {
      super_password = "password"
    })
  ]
}

# setup postgres resources

provider "postgresql" {
  host       = "${helm_release.postgresql.name}.${var.namespace}.svc.cluster.local"
  port       = 5432
  database   = "postgres"
  sslmode    = "disable"

  username   = "postgres"
  password   = "password"
}

resource "postgresql_role" "grafana" {
    name                = "grafana"
    password            = "password"
    encrypted_password  = true
    login               = true
}

Panic Output

module.app.helm_release.postgresql: Creating...
module.app.helm_release.postgresql: Still creating... [40s elapsed]
module.app.helm_release.postgresql: Creation complete after 44s [id=postgresql]
module.app.postgresql_role.grafana: Creating...
╷
│ Error: error detecting capabilities: error PostgreSQL version: dial tcp: lookup postgresql.default.svc.cluster.local on 192.168.1.1:53: server misbehaving
│ 
│   with module.app.postgresql_role.grafana,
│   on modules/app/timescale.tf line 83, in resource "postgresql_role" "grafana":
│   83: resource "postgresql_role" "grafana" {
│ 
╵

Expected Behavior

It should have resolved the postgres address to the internal cluster service and been able to connect

Actual Behavior

It failed using 192.168.1.1:53 instead

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

I'm deploying to an AKS cluster from a mac

gabrielbull commented 1 year ago

I have the same issue. It is intermittent as well, one time it will work, then it won't.

cablespaghetti commented 1 year ago

I have the same issue since we moved to split dns on our VPN. This should be fixed if this provider can upgrade to Go 1.20: https://danp.net/posts/macos-dns-change-in-go-1-20/ https://github.com/Telmate/terraform-provider-proxmox/issues/665

@cyrilgdn Are you able to upgrade the Go version, would raising a PR help? Thanks

cablespaghetti commented 1 year ago

Just coming back around to this issue. I think this is a duplicate: https://github.com/cyrilgdn/terraform-provider-postgresql/issues/241

I'm going to try and raise a PR.

ytimocin commented 4 months ago

Running into exact same error on AKS and it started happening two weeks ago. Any ideas?