Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/postgresql: Add support for 'sslmode' options present in lib/pq #6008

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)).