Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Extend mysql DSN connection parameters #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions mysql/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func Provider() terraform.ResourceProvider {
Optional: true,
},

"conn_params": {
Type: schema.TypeMap,
Optional: true,
Default: nil,
},

"authentication_plugin": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -114,12 +120,22 @@ func Provider() terraform.ResourceProvider {
func providerConfigure(d *schema.ResourceData) (interface{}, error) {

var endpoint = d.Get("endpoint").(string)
var conn_params = make(map[string]string)

proto := "tcp"
if len(endpoint) > 0 && endpoint[0] == '/' {
proto = "unix"
}

for k, v := range d.Get("conn_params").(map[string]interface{}) {
temp, ok := v.(string)
if !ok {
fmt.Errorf("Cannot convert connection parameters to string")
} else {
conn_params[k] = temp
}
}

conf := mysql.Config{
User: d.Get("username").(string),
Passwd: d.Get("password").(string),
Expand All @@ -128,6 +144,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
TLSConfig: d.Get("tls").(string),
AllowNativePasswords: d.Get("authentication_plugin").(string) == nativePasswords,
AllowCleartextPasswords: d.Get("authentication_plugin").(string) == cleartextPasswords,
Params: conn_params,
}

dialer, err := makeDialer(d)
Expand Down
1 change: 1 addition & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ The following arguments are supported:
* `max_conn_lifetime_sec` - (Optional) Sets the maximum amount of time a connection may be reused. If d <= 0, connections are reused forever.
* `max_open_conns` - (Optional) Sets the maximum number of open connections to the database. If n <= 0, then there is no limit on the number of open connections.
* `authentication_plugin` - (Optional) Sets the authentication plugin, it can be one of the following: `native` or `cleartext`. Defaults to `native`.
* `conn_params` - (Optional) Configure mysql DSN parameters. Default value `nil`.