Skip to content

Commit 046abb0

Browse files
committed
Support sslnegotiation option
Signed-off-by: magic_rb <richard@brezak.sk>
1 parent 25fbd1c commit 046abb0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

postgresql/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
featureServer
4747
featureCreateRoleSelfGrant
4848
featureSecurityLabel
49+
featureSSLNegotiation
4950
)
5051

5152
var (
@@ -122,6 +123,9 @@ var (
122123
// https://www.postgresql.org/docs/16/release-16.html#RELEASE-16-PRIVILEGES
123124
featureCreateRoleSelfGrant: semver.MustParseRange(">=16.0.0"),
124125
featureSecurityLabel: semver.MustParseRange(">=11.0.0"),
126+
127+
// SSL without STARTTLS
128+
featureSSLNegotation: semver.MustParseRange(">=17.0.0"),
125129
}
126130
)
127131

@@ -175,6 +179,7 @@ type Config struct {
175179
DatabaseUsername string
176180
Superuser bool
177181
SSLMode string
182+
SSLNegotiation string
178183
ApplicationName string
179184
Timeout int
180185
ConnectTimeoutSec int
@@ -221,6 +226,9 @@ func (c *Config) connParams() []string {
221226
// (TLS is provided by gocloud directly)
222227
if c.Scheme == "postgres" {
223228
params["sslmode"] = c.SSLMode
229+
if c.featureSupported(featureSSLNegotation) {
230+
params["sslnegotiation"] = c.SSLNegotiation
231+
}
224232
params["connect_timeout"] = strconv.Itoa(c.ConnectTimeoutSec)
225233
}
226234

postgresql/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ func Provider() *schema.Provider {
147147
Optional: true,
148148
Deprecated: "Rename PostgreSQL provider `ssl_mode` attribute to `sslmode`",
149149
},
150+
"sslnegotiation": {
151+
Type: schema.TypeString,
152+
Optional: true,
153+
Default: "postgres",
154+
Description: "This option controls how SSL encryption is negotiated with the server, if SSL is used. In the default postgres mode, the client first asks the server if SSL is supported. In direct mode, the client starts the standard SSL handshake directly after establishing the TCP/IP connection.",
155+
},
150156
"clientcert": {
151157
Type: schema.TypeList,
152158
Optional: true,
@@ -376,6 +382,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
376382
DatabaseUsername: d.Get("database_username").(string),
377383
Superuser: d.Get("superuser").(bool),
378384
SSLMode: sslMode,
385+
SSLNegotiation: d.Get("sslnegotiation").(string),
379386
ApplicationName: "Terraform provider",
380387
ConnectTimeoutSec: d.Get("connect_timeout").(int),
381388
MaxConns: d.Get("max_connections").(int),

0 commit comments

Comments
 (0)