diff --git a/postgresreplication/provider.go b/postgresreplication/provider.go index bda6805..c29b35f 100644 --- a/postgresreplication/provider.go +++ b/postgresreplication/provider.go @@ -10,6 +10,7 @@ const ( portKey = "port" hostKey = "host" userKey = "user" + sslmodeKey = "sslmode" passwordKey = "password" ) @@ -18,6 +19,7 @@ const ( defaultHost = "localhost" defaultUser = "postgres" defaultPassword = "" + defaultSslMode = "preferp" ) type providerConfiguration struct { @@ -25,6 +27,7 @@ type providerConfiguration struct { host string user string password string + sslMode string } func Provider() *schema.Provider { @@ -35,6 +38,7 @@ func Provider() *schema.Provider { host: d.Get(hostKey).(string), user: d.Get(userKey).(string), password: d.Get(passwordKey).(string), + sslMode: d.Get(sslmodeKey).(string), }, nil }, ResourcesMap: map[string]*schema.Resource{ @@ -55,6 +59,13 @@ func Provider() *schema.Provider { Default: defaultPort, Description: "The server port to connect to.", }, + sslmodeKey: { + Type: schema.TypeString, + Optional: true, + Sensitive: false, + Default: defaultSslMode, + Description: "The ssl mode to use.", + }, userKey: { Type: schema.TypeString, Optional: true, diff --git a/postgresreplication/resource_replication_slot.go b/postgresreplication/resource_replication_slot.go index 7005b76..86f2626 100644 --- a/postgresreplication/resource_replication_slot.go +++ b/postgresreplication/resource_replication_slot.go @@ -1,6 +1,7 @@ package postgresreplication import ( + "fmt" "github.com/hashicorp/terraform/helper/schema" "github.com/jackc/pgx" "github.com/pkg/errors" @@ -46,12 +47,16 @@ func resourceReplicationSlot() *schema.Resource { func connect(d *schema.ResourceData, m interface{}) (r *pgx.ReplicationConn, err error) { c := m.(*providerConfiguration) - dbConfig := pgx.ConnConfig{ - Host: c.host, - Port: c.port, - User: c.user, - Password: c.password, - Database: d.Get(databaseAttributeName).(string), + dbConfig, err := pgx.ParseURI(fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s", + c.user, + c.password, + c.host, + c.port, + d.Get(databaseAttributeName).(string), + c.sslMode)) + + if err != nil { + return nil, errors.Wrap(err, "error setting up database connection.") } replConn, err := pgx.ReplicationConnect(dbConfig)