From 8be6190ab7f55a46611b0e82c04a82c36fa93424 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 22 Mar 2019 10:24:05 -0700 Subject: [PATCH] Parse 409 error strings to determine retriable status (#3285) Signed-off-by: Modular Magician --- google/resource_sql_database_instance.go | 6 +----- google/utils.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/google/resource_sql_database_instance.go b/google/resource_sql_database_instance.go index 8af4fdc0..a89ed6ac 100644 --- a/google/resource_sql_database_instance.go +++ b/google/resource_sql_database_instance.go @@ -493,11 +493,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) op, err := config.clientSqlAdmin.Instances.Insert(project, instance).Do() if err != nil { - if googleapiError, ok := err.(*googleapi.Error); ok && googleapiError.Code == 409 { - return fmt.Errorf("Error, the name %s is unavailable because it was used recently", instance.Name) - } else { - return fmt.Errorf("Error, failed to create instance %s: %s", instance.Name, err) - } + return fmt.Errorf("Error, failed to create instance %s: %s", instance.Name, err) } d.SetId(instance.Name) diff --git a/google/utils.go b/google/utils.go index 153e192e..49cb6caf 100644 --- a/google/utils.go +++ b/google/utils.go @@ -350,8 +350,7 @@ func retryTimeDuration(retryFunc func() error, duration time.Duration) error { } func isRetryableError(err error) bool { - // 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) { + if gerr, ok := err.(*googleapi.Error); ok && (gerr.Code == 429 || gerr.Code == 500 || gerr.Code == 502 || gerr.Code == 503) { return true } // These operations are always hitting googleapis.com - they should rarely @@ -359,6 +358,14 @@ func isRetryableError(err error) bool { if urlerr, ok := err.(*url.Error); ok && urlerr.Timeout() { return true } + if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 409 && strings.Contains(gerr.Body, "operationInProgress") { + // 409's are retried because cloud sql throws a 409 when concurrent calls are made. + // The only way right now to determine it is a SQL 409 due to concurrent calls is to + // look at the contents of the error message. + // See https://github.com/terraform-providers/terraform-provider-google/issues/3279 + return true + } + return false }