From 60d114f696b4ba315834bd6b642699ea3ee94a59 Mon Sep 17 00:00:00 2001 From: Lukas Budisky Date: Fri, 8 Nov 2019 16:29:47 +0100 Subject: [PATCH] Extend mysql DSN connection parameters New optional parameter for configuring mysql DSN connection - conn_params (map) - allow configure mysql connection parameters --- mysql/provider.go | 17 +++++++++++++++++ website/docs/index.html.markdown | 1 + 2 files changed, 18 insertions(+) diff --git a/mysql/provider.go b/mysql/provider.go index 256b6e61..fe6eb99d 100644 --- a/mysql/provider.go +++ b/mysql/provider.go @@ -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, @@ -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), @@ -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) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index ffd9882c..dc215c5f 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -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`.