- Add support for 'ssl_mode' options present in lib/pq

- Update psotgresql provider's documentation
- Enforce default value to 'require' for ssl_mode
This commit is contained in:
Xavier Sellier 2016-04-04 11:40:28 -04:00
parent fa703db8a6
commit fc9825e4c4
3 changed files with 12 additions and 2 deletions

View File

@ -13,6 +13,7 @@ type Config struct {
Port int Port int
Username string Username string
Password string Password string
SslMode string
} }
// Client struct holding connection string // Client struct holding connection string
@ -23,7 +24,7 @@ type Client struct {
//NewClient returns new client config //NewClient returns new client config
func (c *Config) NewClient() (*Client, error) { 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{ client := Client{
connStr: connStr, connStr: connStr,

View File

@ -35,6 +35,12 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("POSTGRESQL_PASSWORD", nil), DefaultFunc: schema.EnvDefaultFunc("POSTGRESQL_PASSWORD", nil),
Description: "Password for postgresql server connection", Description: "Password for postgresql server connection",
}, },
"ssl_mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "require",
Description: "Connection mode for postgresql server",
},
}, },
ResourcesMap: map[string]*schema.Resource{ ResourcesMap: map[string]*schema.Resource{
@ -52,6 +58,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
Port: d.Get("port").(int), Port: d.Get("port").(int),
Username: d.Get("username").(string), Username: d.Get("username").(string),
Password: d.Get("password").(string), Password: d.Get("password").(string),
SslMode: d.Get("ssl_mode").(string),
} }
client, err := config.NewClient() client, err := config.NewClient()

View File

@ -20,6 +20,7 @@ provider "postgresql" {
port = 5432 port = 5432
username = "postgres_user" username = "postgres_user"
password = "postgres_password" password = "postgres_password"
ssl_mode = "require"
} }
``` ```
@ -60,4 +61,5 @@ The following arguments are supported:
* `host` - (Required) The address for the postgresql server connection. * `host` - (Required) The address for the postgresql server connection.
* `port` - (Optional) The port for the postgresql server connection. (Default 5432) * `port` - (Optional) The port for the postgresql server connection. (Default 5432)
* `username` - (Required) Username for the server connection. * `username` - (Required) Username for the server connection.
* `password` - (Optional) Password for the server connection. * `password` - (Optional) Password for the server connection.
* `ssl_mode` - (Optional) Set connection mode for postgresql server (Default "require", more options [lib/pq documentations](https://godoc.org/github.com/lib/pq)).