diff --git a/builtin/providers/postgresql/config.go b/builtin/providers/postgresql/config.go index 8bf7b2daa512..5ef7c8270743 100644 --- a/builtin/providers/postgresql/config.go +++ b/builtin/providers/postgresql/config.go @@ -13,6 +13,7 @@ type Config struct { Port int Username string Password string + Sslmode string } // Client struct holding connection string @@ -23,7 +24,7 @@ type Client struct { //NewClient returns new client config func (c *Config) NewClient() (*Client, error) { - connStr := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=postgres", c.Host, c.Port, c.Username, c.Password) + connStr := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=postgres sslmode=%s", c.Host, c.Port, c.Username, c.Password, c.Sslmode) client := Client{ connStr: connStr, diff --git a/builtin/providers/postgresql/provider.go b/builtin/providers/postgresql/provider.go index c048ec3ece76..e8a7250d47f8 100644 --- a/builtin/providers/postgresql/provider.go +++ b/builtin/providers/postgresql/provider.go @@ -35,6 +35,12 @@ func Provider() terraform.ResourceProvider { DefaultFunc: schema.EnvDefaultFunc("POSTGRESQL_PASSWORD", nil), Description: "Password for postgresql server connection", }, + "sslmode": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Default: "require", + Description: "Connection mode for postgresql server", + }, }, ResourcesMap: map[string]*schema.Resource{ @@ -52,6 +58,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { Port: d.Get("port").(int), Username: d.Get("username").(string), Password: d.Get("password").(string), + Sslmode: d.Get("sslmode").(string), } client, err := config.NewClient() diff --git a/website/source/docs/providers/postgresql/index.html.markdown b/website/source/docs/providers/postgresql/index.html.markdown index 36761b626a36..2d343d31fb87 100644 --- a/website/source/docs/providers/postgresql/index.html.markdown +++ b/website/source/docs/providers/postgresql/index.html.markdown @@ -20,6 +20,7 @@ provider "postgresql" { port = 5432 username = "postgres_user" password = "postgres_password" + sslmode = "require" } ``` @@ -60,4 +61,5 @@ The following arguments are supported: * `host` - (Required) The address for the postgresql server connection. * `port` - (Optional) The port for the postgresql server connection. (Default 5432) * `username` - (Required) Username for the server connection. -* `password` - (Optional) Password for the server connection. \ No newline at end of file +* `password` - (Optional) Password for the server connection. +* `sslmode` - (Optional) Set connection mode for postgresql (Default "require", more options [lib/pq documentations](https://godoc.org/github.com/lib/pq)). \ No newline at end of file