Mr 123
Mr 123

Reputation: 191

AWS Terraform postgresql provider: SSL is not enabled on the server

I am trying to create a database in the created postgres RDS in AWS with postgresql provider. The terraform script i have created is as following:

    resource "aws_db_instance" "test_rds" {
  allocated_storage        = "" # gigabytes
  backup_retention_period  = 7   # in days
  engine                   = ""
  engine_version           = ""
  identifier               = ""
  instance_class           = ""
  multi_az                 = ""
  name                     = ""
  username                 = ""
  password                 = ""
  port                     = ""
  publicly_accessible      = "false"
  storage_encrypted        = "false"
  storage_type             = ""
  vpc_security_group_ids   = ["${aws_security_group.test_sg.id}"]
  db_subnet_group_name     = "${aws_db_subnet_group.rds_subnet_group.name}"
}

The postgresql provider is as following:

# Create databases in rds
provider "postgresql" {

  alias           = "alias"
  host            = "${aws_db_instance.test_rds.address}"
  port            =  5432
  username        = 
  password        = 
  database        = 
  sslmode         = "disable"

}

# Create user in rds
resource "postgresql_role" "test_role" {
  name             = 
  replication      = true
  login            = true
  password         = 
}

# Create database rds
resource "postgresql_database" "test_db" {
  name              = testdb
  owner             = "${postgresql_role.test_role.name}"
  lc_collate        = "C"
  allow_connections = true
  provider          = "postgresql.alias"
}

Anyway i keep retrieving Error: Error initializing PostgreSQL client: error detecting capabilities: error PostgreSQL version: pq: SSL is not enabled on the server

Note: the empty fields are already filled and the RDS is successfully created, the problem rises when trying to create the database in the rds with the postgresql provider.

Upvotes: 4

Views: 6185

Answers (2)

Gidi9
Gidi9

Reputation: 222

Ensuring there was a password set for the postgres user and disabled sslmode, did it for me

sslmode = "disable"

Upvotes: 1

user2059166
user2059166

Reputation: 81

We ran into this issue as well, and the problem was that the password was not defined. It seems that we will get the SSL is not enabled error when it has problems connecting. We also had the same problem when the db host name was missing. You will need to make sure you define all of the fields needed to connect in Terraform (probably database and username too).

Upvotes: 8

Related Questions