Skip to content

Commit

Permalink
- Add support for 'ssl_mode' options present in lib/pq
Browse files Browse the repository at this point in the history
- Update psotgresql provider's documentation
- Enforce default value to 'require' for ssl_mode
  • Loading branch information
Xavier Sellier committed Apr 11, 2016
1 parent fa703db commit fc9825e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion builtin/providers/postgresql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Config struct {
Port int
Username string
Password string
SslMode string
}

// Client struct holding connection string
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions builtin/providers/postgresql/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("POSTGRESQL_PASSWORD", nil),
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{
Expand All @@ -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("ssl_mode").(string),
}

client, err := config.NewClient()
Expand Down
4 changes: 3 additions & 1 deletion website/source/docs/providers/postgresql/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ provider "postgresql" {
port = 5432
username = "postgres_user"
password = "postgres_password"
ssl_mode = "require"
}
```
Expand Down Expand Up @@ -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.
* `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)).

0 comments on commit fc9825e

Please sign in to comment.