Skip to content

Commit

Permalink
Fix missed occurence of TpuBasePath (hashicorp#1110)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rileykarson committed Aug 30, 2019
1 parent 998996f commit 48060e6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion google-beta/data_source_tpu_tensorflow_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func dataSourceTpuTensorFlowVersionsRead(d *schema.ResourceData, meta interface{
return err
}

url, err := replaceVars(d, config, "{{TpuBasePath}}projects/{{project}}/locations/{{zone}}/tensorflowVersions")
url, err := replaceVars(d, config, "{{TPUBasePath}}projects/{{project}}/locations/{{zone}}/tensorflowVersions")
if err != nil {
return err
}
Expand Down
7 changes: 7 additions & 0 deletions google-beta/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ func pubsubTopicProjectNotReady(err error) (bool, string) {
}
return false, ""
}

func isSqlOperationInProgressError(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 409 {
return true, "Waiting for other concurrent Cloud SQL operations to finish"
}
return false, ""
}
37 changes: 19 additions & 18 deletions google-beta/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,12 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
defer mutexKV.Unlock(instanceMutexKey(project, instance.MasterInstanceName))
}

op, err := config.clientSqlAdmin.Instances.Insert(project, instance).Do()
var op *sqladmin.Operation
err = retryTimeDuration(func() (operr error) {
op, operr = config.clientSqlAdmin.Instances.Insert(project, instance).Do()
return operr
}, d.Timeout(schema.TimeoutCreate), isSqlOperationInProgressError)
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 409 {
return fmt.Errorf("Error, failed to create instance %s with error code 409: %s. This may be due to a name collision - SQL instance names cannot be reused within a week.", instance.Name, err)
}
return fmt.Errorf("Error, failed to create instance %s: %s", instance.Name, err)
}

Expand All @@ -515,10 +516,10 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
// Users in a replica instance are inherited from the master instance and should be left alone.
if sqlDatabaseIsMaster(d) {
var users *sqladmin.UsersListResponse
err = retryTime(func() error {
err = retryTimeDuration(func() error {
users, err = config.clientSqlAdmin.Users.List(project, instance.Name).Do()
return err
}, 5)
}, d.Timeout(schema.TimeoutRead), isSqlOperationInProgressError)
if err != nil {
return fmt.Errorf("Error, attempting to list users associated with instance %s: %s", instance.Name, err)
}
Expand Down Expand Up @@ -701,13 +702,10 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
}

var instance *sqladmin.DatabaseInstance
err = retry(
func() error {
instance, err = config.clientSqlAdmin.Instances.Get(project, d.Id()).Do()
return err
},
)

err = retryTimeDuration(func() (rerr error) {
instance, rerr = config.clientSqlAdmin.Instances.Get(project, d.Id()).Do()
return rerr
}, d.Timeout(schema.TimeoutRead), isSqlOperationInProgressError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("SQL Database Instance %q", d.Get("name").(string)))
}
Expand Down Expand Up @@ -781,7 +779,11 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
defer mutexKV.Unlock(instanceMutexKey(project, v.(string)))
}

op, err := config.clientSqlAdmin.Instances.Update(project, d.Get("name").(string), instance).Do()
var op *sqladmin.Operation
err = retryTimeDuration(func() (rerr error) {
op, rerr = config.clientSqlAdmin.Instances.Update(project, d.Get("name").(string), instance).Do()
return rerr
}, d.Timeout(schema.TimeoutUpdate), isSqlOperationInProgressError)
if err != nil {
return fmt.Errorf("Error, failed to update instance settings for %s: %s", instance.Name, err)
}
Expand Down Expand Up @@ -810,11 +812,10 @@ func resourceSqlDatabaseInstanceDelete(d *schema.ResourceData, meta interface{})
}

var op *sqladmin.Operation
err = retryTimeDuration(func() error {
op, err = config.clientSqlAdmin.Instances.Delete(project, d.Get("name").(string)).Do()
return err
err = retryTimeDuration(func() (rerr error) {
op, rerr = config.clientSqlAdmin.Instances.Delete(project, d.Get("name").(string)).Do()
return rerr
}, d.Timeout(schema.TimeoutDelete))

if err != nil {
return fmt.Errorf("Error, failed to delete instance %s: %s", d.Get("name").(string), err)
}
Expand Down

0 comments on commit 48060e6

Please sign in to comment.