Added 'connect_timeout' argument to provider 'postgresql' (#10380)
This commit is contained in:
parent
47ac66f675
commit
f993f0e70e
|
@ -14,6 +14,7 @@ type Config struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
SslMode string
|
SslMode string
|
||||||
|
Timeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client struct holding connection string
|
// Client struct holding connection string
|
||||||
|
@ -24,7 +25,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 sslmode=%s", c.Host, c.Port, c.Username, c.Password, c.SslMode)
|
connStr := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=postgres sslmode=%s connect_timeout=%d", c.Host, c.Port, c.Username, c.Password, c.SslMode, c.Timeout)
|
||||||
|
|
||||||
client := Client{
|
client := Client{
|
||||||
connStr: connStr,
|
connStr: connStr,
|
||||||
|
|
|
@ -40,6 +40,13 @@ func Provider() terraform.ResourceProvider {
|
||||||
DefaultFunc: schema.EnvDefaultFunc("PGSSLMODE", "require"),
|
DefaultFunc: schema.EnvDefaultFunc("PGSSLMODE", "require"),
|
||||||
Description: "Connection mode for PostgreSQL server",
|
Description: "Connection mode for PostgreSQL server",
|
||||||
},
|
},
|
||||||
|
"connect_timeout": {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Optional: true,
|
||||||
|
Default: 15,
|
||||||
|
DefaultFunc: schema.EnvDefaultFunc("PGCONNECT_TIMEOUT", nil),
|
||||||
|
Description: "Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
ResourcesMap: map[string]*schema.Resource{
|
ResourcesMap: map[string]*schema.Resource{
|
||||||
|
@ -59,6 +66,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||||
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),
|
SslMode: d.Get("ssl_mode").(string),
|
||||||
|
Timeout: d.Get("connect_timeout").(int),
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := config.NewClient()
|
client, err := config.NewClient()
|
||||||
|
|
|
@ -21,6 +21,7 @@ provider "postgresql" {
|
||||||
username = "postgres_user"
|
username = "postgres_user"
|
||||||
password = "postgres_password"
|
password = "postgres_password"
|
||||||
ssl_mode = "require"
|
ssl_mode = "require"
|
||||||
|
connect_timeout = 15
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -63,5 +64,6 @@ The following arguments are supported:
|
||||||
* `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 the priority for an SSL connection to the server.
|
* `ssl_mode` - (Optional) Set the priority for an SSL connection to the server.
|
||||||
|
* `connect_timeout` - (Optional) Maximum wait for connection, in seconds. Zero means wait indefinitely, the default is `15`.
|
||||||
The default is `prefer`; the full set of options and their implications
|
The default is `prefer`; the full set of options and their implications
|
||||||
can be seen [in the libpq SSL guide](http://www.postgresql.org/docs/9.4/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION).
|
can be seen [in the libpq SSL guide](http://www.postgresql.org/docs/9.4/static/libpq-ssl.html#LIBPQ-SSL-PROTECTION).
|
||||||
|
|
Loading…
Reference in New Issue