Skip to content

Commit 3750bf7

Browse files
committed
Depreciate the PostgreSQL provider's ssl_mode option in favor of sslmode.
Both libpq(3) and github.com/lib/pq both use `sslmode`. Prefer this vs the non-standard `ssl_mode`. `ssl_mode` is supported for compatibility but should be removed in the future. Changelog: yes
1 parent a200899 commit 3750bf7

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

builtin/providers/postgresql/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Config struct {
1515
Database string
1616
Username string
1717
Password string
18-
SslMode string
18+
SSLMode string
1919
Timeout int
2020
ApplicationName string
2121
}

builtin/providers/postgresql/provider.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func Provider() terraform.ResourceProvider {
5959
DefaultFunc: schema.EnvDefaultFunc("PGCONNECT_TIMEOUT", nil),
6060
Description: "Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.",
6161
},
62+
"ssl_mode": {
63+
Type: schema.TypeString,
64+
Optional: true,
65+
Deprecated: "Rename PostgreSQL provider `ssl_mode` attribute to `sslmode`",
66+
},
6267
},
6368

6469
ResourcesMap: map[string]*schema.Resource{
@@ -72,14 +77,19 @@ func Provider() terraform.ResourceProvider {
7277
}
7378

7479
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
80+
var sslMode string
81+
var ok bool
82+
if sslMode, ok = d.GetOk("sslmode").(string); !ok {
83+
sslMode = d.Get("ssl_mode").(string)
84+
}
7585
config := Config{
7686
Host: d.Get("host").(string),
7787
Port: d.Get("port").(int),
7888
Database: d.Get("database").(string),
7989
Username: d.Get("username").(string),
8090
Password: d.Get("password").(string),
91+
SSLMode: sslMode,
8192
Timeout: d.Get("connect_timeout").(int),
82-
SslMode: d.Get("sslmode").(string),
8393
ApplicationName: tfAppName(),
8494
}
8595

website/source/docs/providers/postgresql/index.html.markdown

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ provider "postgresql" {
2121
database = "postgres"
2222
username = "postgres_user"
2323
password = "postgres_password"
24-
ssl_mode = "require"
24+
sslmode = "require"
2525
connect_timeout = 15
2626
}
2727
@@ -66,6 +66,14 @@ The following arguments are supported:
6666
* `username` - (Required) Username for the server connection.
6767
* `password` - (Optional) Password for the server connection.
6868
* `sslmode` - (Optional) Set the priority for an SSL connection to the server.
69+
Valid values for `sslmode` are (note: `prefer` is not supported by Go's
70+
[`lib/pq`](https://godoc.org/github.com/lib/pq)):
71+
* disable - No SSL
72+
* require - Always SSL (the default, also skip verification)
73+
* verify-ca - Always SSL (verify that the certificate presented by the server was signed by a trusted CA)
74+
* verify-full - Always SSL (verify that the certification presented by the server was signed by a trusted CA and the server host name matches the one in the certificate)
75+
Additional information on the options and their implications can be seen
76+
[in the `libpq(3)` SSL guide](http://www.postgresql.org/docs/current/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION).
6977
* `connect_timeout` - (Optional) Maximum wait for connection, in seconds. Zero means wait indefinitely, the default is `15`.
7078
The default is `prefer`; the full set of options and their implications
7179
can be seen [in the libpq SSL guide](http://www.postgresql.org/docs/9.4/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION).

0 commit comments

Comments
 (0)