diff --git a/google/resource_sql_database_instance.go b/google/resource_sql_database_instance.go index 304d91ba9bb..f7f2704d559 100644 --- a/google/resource_sql_database_instance.go +++ b/google/resource_sql_database_instance.go @@ -5,6 +5,7 @@ import ( "log" "regexp" "strings" + "time" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -41,6 +42,12 @@ func resourceSqlDatabaseInstance() *schema.Resource { State: schema.ImportStatePassthrough, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + Schema: map[string]*schema.Schema{ "region": &schema.Schema{ Type: schema.TypeString, @@ -670,7 +677,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) d.SetId(instance.Name) - err = sqladminOperationWait(config, op, project, "Create Instance") + err = sqladminOperationWaitTime(config, op, project, "Create Instance", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { d.SetId("") return err @@ -697,7 +704,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) err = retry(func() error { op, err = config.clientSqlAdmin.Users.Delete(project, instance.Name, u.Host, u.Name).Do() if err == nil { - err = sqladminOperationWait(config, op, project, "Delete default root User") + err = sqladminOperationWaitTime(config, op, project, "Delete default root User", int(d.Timeout(schema.TimeoutCreate).Minutes())) } return err }) @@ -1027,7 +1034,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error, failed to update instance %s: %s", instance.Name, err) } - err = sqladminOperationWait(config, op, project, "Create Instance") + err = sqladminOperationWaitTime(config, op, project, "Update Instance", int(d.Timeout(schema.TimeoutUpdate).Minutes())) if err != nil { return err } @@ -1049,7 +1056,7 @@ func resourceSqlDatabaseInstanceDelete(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error, failed to delete instance %s: %s", d.Get("name").(string), err) } - err = sqladminOperationWait(config, op, project, "Delete Instance") + err = sqladminOperationWaitTime(config, op, project, "Delete Instance", int(d.Timeout(schema.TimeoutDelete).Minutes())) if err != nil { return err } diff --git a/google/sqladmin_operation.go b/google/sqladmin_operation.go index 9fb40bb0f1e..bc99f7e46cc 100644 --- a/google/sqladmin_operation.go +++ b/google/sqladmin_operation.go @@ -57,6 +57,10 @@ func (e SqlAdminOperationError) Error() string { } func sqladminOperationWait(config *Config, op *sqladmin.Operation, project, activity string) error { + return sqladminOperationWaitTime(config, op, project, activity, 10) +} + +func sqladminOperationWaitTime(config *Config, op *sqladmin.Operation, project, activity string, timeoutMinutes int) error { w := &SqlAdminOperationWaiter{ Service: config.clientSqlAdmin, Op: op, @@ -64,7 +68,7 @@ func sqladminOperationWait(config *Config, op *sqladmin.Operation, project, acti } state := w.Conf() - state.Timeout = 10 * time.Minute + state.Timeout = time.Duration(timeoutMinutes) * time.Minute state.MinTimeout = 2 * time.Second state.Delay = 5 * time.Second opRaw, err := state.WaitForState() diff --git a/website/docs/r/sql_database_instance.html.markdown b/website/docs/r/sql_database_instance.html.markdown index 055fa4385b6..016f8b3275c 100644 --- a/website/docs/r/sql_database_instance.html.markdown +++ b/website/docs/r/sql_database_instance.html.markdown @@ -229,6 +229,15 @@ when the resource is configured with a `count`. * `settings.version` - Used to make sure changes to the `settings` block are atomic. +## Timeouts + +`google_sql_database_instance` provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 10 minutes. +- `update` - Default is 10 minutes. +- `delete` - Default is 10 minutes. + ## Import Database instances can be imported using the `name`, e.g.