Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries to SQL user insert and update operations. #1399

Merged
merged 1 commit into from
Nov 22, 2019
Merged
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
18 changes: 14 additions & 4 deletions google-beta/resource_sql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ func resourceSqlUserCreate(d *schema.ResourceData, meta interface{}) error {

mutexKV.Lock(instanceMutexKey(project, instance))
defer mutexKV.Unlock(instanceMutexKey(project, instance))
op, err := config.clientSqlAdmin.Users.Insert(project, instance,
user).Do()
var op *sqladmin.Operation
insertFunc := func() error {
op, err = config.clientSqlAdmin.Users.Insert(project, instance,
user).Do()
return err
}
err = retryTimeDuration(insertFunc, d.Timeout(schema.TimeoutCreate))

if err != nil {
return fmt.Errorf("Error, failed to insert "+
Expand Down Expand Up @@ -172,8 +177,13 @@ func resourceSqlUserUpdate(d *schema.ResourceData, meta interface{}) error {

mutexKV.Lock(instanceMutexKey(project, instance))
defer mutexKV.Unlock(instanceMutexKey(project, instance))
op, err := config.clientSqlAdmin.Users.Update(project, instance, name,
user).Host(host).Do()
var op *sqladmin.Operation
updateFunc := func() error {
op, err = config.clientSqlAdmin.Users.Update(project, instance, name,
user).Host(host).Do()
return err
}
err = retryTimeDuration(updateFunc, d.Timeout(schema.TimeoutUpdate))

if err != nil {
return fmt.Errorf("Error, failed to update"+
Expand Down