From 13a5c12d0d0042f96ceaa9a80b9955b8d46ac0e1 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Sat, 5 Jan 2019 13:10:52 -0800 Subject: [PATCH 1/3] Retry delete calls on 409 --- .../resources/resource_sql_database_instance.go.erb | 8 ++++++-- third_party/terraform/resources/resource_sql_user.go | 9 +++++++-- third_party/terraform/utils/utils.go | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/third_party/terraform/resources/resource_sql_database_instance.go.erb b/third_party/terraform/resources/resource_sql_database_instance.go.erb index 33f7fc928065..d4775c403800 100644 --- a/third_party/terraform/resources/resource_sql_database_instance.go.erb +++ b/third_party/terraform/resources/resource_sql_database_instance.go.erb @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform/helper/validation" "google.golang.org/api/googleapi" - "google.golang.org/api/sqladmin/v1beta4" + sqladmin "google.golang.org/api/sqladmin/v1beta4" ) const privateNetworkLinkRegex = "projects/(" + ProjectRegex + ")/global/networks/((?:[a-z](?:[-a-z0-9]*[a-z0-9])?))$" @@ -783,7 +783,11 @@ func resourceSqlDatabaseInstanceDelete(d *schema.ResourceData, meta interface{}) defer mutexKV.Unlock(instanceMutexKey(project, v.(string))) } - op, err := config.clientSqlAdmin.Instances.Delete(project, d.Get("name").(string)).Do() + var op *sqladmin.Operation + err = retryTime(func() error { + op, err = config.clientSqlAdmin.Instances.Delete(project, d.Get("name").(string)).Do() + return err + }, 5) if err != nil { return fmt.Errorf("Error, failed to delete instance %s: %s", d.Get("name").(string), err) diff --git a/third_party/terraform/resources/resource_sql_user.go b/third_party/terraform/resources/resource_sql_user.go index d11702c5fdb6..f01c257dc464 100644 --- a/third_party/terraform/resources/resource_sql_user.go +++ b/third_party/terraform/resources/resource_sql_user.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/hashicorp/terraform/helper/schema" - "google.golang.org/api/sqladmin/v1beta4" + sqladmin "google.golang.org/api/sqladmin/v1beta4" ) func resourceSqlUser() *schema.Resource { @@ -206,7 +206,12 @@ func resourceSqlUserDelete(d *schema.ResourceData, meta interface{}) error { mutexKV.Lock(instanceMutexKey(project, instance)) defer mutexKV.Unlock(instanceMutexKey(project, instance)) - op, err := config.clientSqlAdmin.Users.Delete(project, instance, host, name).Do() + + var op *sqladmin.Operation + err = retryTime(func() error { + op, err = config.clientSqlAdmin.Users.Delete(project, instance, host, name).Do() + return err + }, 5 /* minutes */) if err != nil { return fmt.Errorf("Error, failed to delete"+ diff --git a/third_party/terraform/utils/utils.go b/third_party/terraform/utils/utils.go index 305ee7ef86c2..2ada16b09791 100644 --- a/third_party/terraform/utils/utils.go +++ b/third_party/terraform/utils/utils.go @@ -331,7 +331,8 @@ func retryTimeDuration(retryFunc func() error, duration time.Duration) error { } func isRetryableError(err error) bool { - if gerr, ok := err.(*googleapi.Error); ok && (gerr.Code == 429 || gerr.Code == 500 || gerr.Code == 502 || gerr.Code == 503) { + // 409's are retried because cloud sql throws a 409 when concurrent calls are made + if gerr, ok := err.(*googleapi.Error); ok && (gerr.Code == 409 || gerr.Code == 429 || gerr.Code == 500 || gerr.Code == 502 || gerr.Code == 503) { return true } return false From 26c455f807d8aebdcf8f34edf987a44bff6b9df8 Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Mon, 7 Jan 2019 13:52:00 -0800 Subject: [PATCH 2/3] Make delete calls use the delete timeouts --- third_party/terraform/resources/resource_sql_database.go | 6 +++--- .../resources/resource_sql_database_instance.go.erb | 4 ++-- third_party/terraform/resources/resource_sql_user.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/third_party/terraform/resources/resource_sql_database.go b/third_party/terraform/resources/resource_sql_database.go index ffaf48cc301b..68f39b1e2c4c 100644 --- a/third_party/terraform/resources/resource_sql_database.go +++ b/third_party/terraform/resources/resource_sql_database.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" - "google.golang.org/api/sqladmin/v1beta4" + sqladmin "google.golang.org/api/sqladmin/v1beta4" ) func resourceSqlDatabase() *schema.Resource { @@ -206,10 +206,10 @@ func resourceSqlDatabaseDelete(d *schema.ResourceData, meta interface{}) error { defer mutexKV.Unlock(instanceMutexKey(project, instance_name)) var op *sqladmin.Operation - err = retryTime(func() error { + err = retryTimeDuration(func() error { op, err = config.clientSqlAdmin.Databases.Delete(project, instance_name, database_name).Do() return err - }, 5 /* minutes */) + }, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error, failed to delete"+ diff --git a/third_party/terraform/resources/resource_sql_database_instance.go.erb b/third_party/terraform/resources/resource_sql_database_instance.go.erb index d4775c403800..81689ed04b4e 100644 --- a/third_party/terraform/resources/resource_sql_database_instance.go.erb +++ b/third_party/terraform/resources/resource_sql_database_instance.go.erb @@ -784,10 +784,10 @@ func resourceSqlDatabaseInstanceDelete(d *schema.ResourceData, meta interface{}) } var op *sqladmin.Operation - err = retryTime(func() error { + err = retryTimeDuration(func() error { op, err = config.clientSqlAdmin.Instances.Delete(project, d.Get("name").(string)).Do() return err - }, 5) + }, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error, failed to delete instance %s: %s", d.Get("name").(string), err) diff --git a/third_party/terraform/resources/resource_sql_user.go b/third_party/terraform/resources/resource_sql_user.go index f01c257dc464..30089f517665 100644 --- a/third_party/terraform/resources/resource_sql_user.go +++ b/third_party/terraform/resources/resource_sql_user.go @@ -208,10 +208,10 @@ func resourceSqlUserDelete(d *schema.ResourceData, meta interface{}) error { defer mutexKV.Unlock(instanceMutexKey(project, instance)) var op *sqladmin.Operation - err = retryTime(func() error { + err = retryTimeDuration(func() error { op, err = config.clientSqlAdmin.Users.Delete(project, instance, host, name).Do() return err - }, 5 /* minutes */) + }, d.Timeout(schema.TimeoutDelete)) if err != nil { return fmt.Errorf("Error, failed to delete"+ From cf4ae32c753a183d5d88353a7f836e91d8eae85e Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 8 Jan 2019 00:49:28 +0000 Subject: [PATCH 3/3] Update tracked submodules -> HEAD on Tue Jan 8 00:49:28 UTC 2019 Tracked submodules are build/terraform-beta build/terraform build/ansible build/inspec. --- build/terraform | 2 +- build/terraform-beta | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index 43d40f4065e5..b31626a1a248 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 43d40f4065e5bc1098f77ac10412f3a6fe2d887d +Subproject commit b31626a1a248f8a9a6e0e8a81b082da3bd219f08 diff --git a/build/terraform-beta b/build/terraform-beta index 26b13d754ab9..9f429e37f7e0 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 26b13d754ab91ecd189422e2a16b389a903bd79c +Subproject commit 9f429e37f7e0778ab404381e47ac36e6a36fbd95