From 58d54a24d6868b889bef52b1e8a44f4a2e15c24c Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Fri, 22 Nov 2019 01:02:52 +0000 Subject: [PATCH] Add retries to SQL user insert and update operations. Signed-off-by: Modular Magician --- google-beta/resource_sql_user.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/google-beta/resource_sql_user.go b/google-beta/resource_sql_user.go index 5869fea356..72f5c8631e 100644 --- a/google-beta/resource_sql_user.go +++ b/google-beta/resource_sql_user.go @@ -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 "+ @@ -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"+