Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeouts support for BigTable operations #14861

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/8037.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigtable: add timeout support for bigtable admin operations
```
5 changes: 5 additions & 0 deletions google/resource_bigtable_gc_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func ResourceBigtableGCPolicy() *schema.Resource {
Update: resourceBigtableGCPolicyUpsert,
CustomizeDiff: resourceBigtableGCPolicyCustomizeDiff,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
},

Schema: map[string]*schema.Schema{
"instance_name": {
Type: schema.TypeString,
Expand Down
16 changes: 12 additions & 4 deletions google/resource_bigtable_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -29,6 +30,11 @@ func ResourceBigtableInstance() *schema.Resource {
State: resourceBigtableInstanceImport,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Update: schema.DefaultTimeout(20 * time.Minute),
},

CustomizeDiff: customdiff.All(
resourceBigtableInstanceClusterReorderTypeList,
),
Expand Down Expand Up @@ -213,8 +219,9 @@ func resourceBigtableInstanceCreate(d *schema.ResourceData, meta interface{}) er

defer c.Close()

err = c.CreateInstanceWithClusters(ctx, conf)
if err != nil {
ctxWithTimeout, cancel := context.WithTimeout(ctx, d.Timeout(schema.TimeoutCreate))
defer cancel()
if err := c.CreateInstanceWithClusters(ctxWithTimeout, conf); err != nil {
return fmt.Errorf("Error creating instance. %s", err)
}

Expand Down Expand Up @@ -349,8 +356,9 @@ func resourceBigtableInstanceUpdate(d *schema.ResourceData, meta interface{}) er
return err
}

_, err = bigtable.UpdateInstanceAndSyncClusters(ctx, c, conf)
if err != nil {
ctxWithTimeout, cancel := context.WithTimeout(ctx, d.Timeout(schema.TimeoutUpdate))
defer cancel()
if _, err := bigtable.UpdateInstanceAndSyncClusters(ctxWithTimeout, c, conf); err != nil {
return fmt.Errorf("Error updating instance. %s", err)
}

Expand Down
9 changes: 6 additions & 3 deletions google/resource_bigtable_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func ResourceBigtableTable() *schema.Resource {
// Set a longer timeout for table creation as adding column families can be slow.
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(45 * time.Minute),
Update: schema.DefaultTimeout(20 * time.Minute),
},

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -157,7 +158,7 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error
// This method may return before the table's creation is complete - we may need to wait until
// it exists in the future.
// Set a longer timeout as creating table and adding column families can be pretty slow.
ctxWithTimeout, cancel := context.WithTimeout(ctx, 20*time.Minute)
ctxWithTimeout, cancel := context.WithTimeout(ctx, d.Timeout(schema.TimeoutCreate))
defer cancel() // Always call cancel.
err = c.CreateTableFromConf(ctxWithTimeout, &tblConf)
if err != nil {
Expand Down Expand Up @@ -276,14 +277,16 @@ func resourceBigtableTableUpdate(d *schema.ResourceData, meta interface{}) error
}
}

ctxWithTimeout, cancel := context.WithTimeout(ctx, d.Timeout(schema.TimeoutCreate))
defer cancel()
if d.HasChange("deletion_protection") {
deletionProtection := d.Get("deletion_protection")
if deletionProtection == "PROTECTED" {
if err := c.UpdateTableWithDeletionProtection(ctx, name, bigtable.Protected); err != nil {
if err := c.UpdateTableWithDeletionProtection(ctxWithTimeout, name, bigtable.Protected); err != nil {
return fmt.Errorf("Error updating deletion protection in table %v: %s", name, err)
}
} else if deletionProtection == "UNPROTECTED" {
if err := c.UpdateTableWithDeletionProtection(ctx, name, bigtable.Unprotected); err != nil {
if err := c.UpdateTableWithDeletionProtection(ctxWithTimeout, name, bigtable.Unprotected); err != nil {
return fmt.Errorf("Error updating deletion protection in table %v: %s", name, err)
}
}
Expand Down