Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from winebarrel/add_connect_retry_timeout_sec_f…
Browse files Browse the repository at this point in the history
…or_mysqlx

Add connect_retry_timeout_sec to provider config
  • Loading branch information
winebarrel authored Mar 12, 2020
2 parents c98f1b7 + 356790f commit 299b5af
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions mysql/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ const (
)

type MySQLConfiguration struct {
Config *mysql.Config
MaxConnLifetime time.Duration
MaxOpenConns int
SSM *ssm.SSM
Config *mysql.Config
MaxConnLifetime time.Duration
MaxOpenConns int
ConnectRetryTimeoutSec time.Duration
SSM *ssm.SSM
}

func Provider() terraform.ResourceProvider {
Expand Down Expand Up @@ -110,6 +111,12 @@ func Provider() terraform.ResourceProvider {
ValidateFunc: validation.StringInSlice([]string{cleartextPasswords, nativePasswords}, true),
},

"connect_retry_timeout_sec": {
Type: schema.TypeInt,
Optional: true,
Default: 300,
},

"use_parameter_store": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -206,10 +213,11 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
}

mysqlConf := &MySQLConfiguration{
Config: &conf,
MaxConnLifetime: time.Duration(d.Get("max_conn_lifetime_sec").(int)) * time.Second,
MaxOpenConns: d.Get("max_open_conns").(int),
SSM: ssmSvc,
Config: &conf,
MaxConnLifetime: time.Duration(d.Get("max_conn_lifetime_sec").(int)) * time.Second,
MaxOpenConns: d.Get("max_open_conns").(int),
SSM: ssmSvc,
ConnectRetryTimeoutSec: time.Duration(d.Get("connect_retry_timeout_sec").(int)) * time.Second,
}

return mysqlConf, nil
Expand Down Expand Up @@ -271,7 +279,7 @@ func connectToMySQL(conf *MySQLConfiguration) (*sql.DB, error) {
// when Terraform thinks it's available and when it is actually available.
// This is particularly acute when provisioning a server and then immediately
// trying to provision a database on it.
retryError := resource.Retry(5*time.Minute, func() *resource.RetryError {
retryError := resource.Retry(conf.ConnectRetryTimeoutSec, func() *resource.RetryError {
db, err = sql.Open("mysql", dsn)
if err != nil {
return resource.RetryableError(err)
Expand Down

0 comments on commit 299b5af

Please sign in to comment.