4
4
"context"
5
5
"fmt"
6
6
"log"
7
+ "time"
7
8
8
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9
10
)
@@ -19,6 +20,11 @@ func resourceBigtableTable() *schema.Resource {
19
20
State : resourceBigtableTableImport ,
20
21
},
21
22
23
+ // Set a longer timeout for table creation as adding column families can be slow.
24
+ Timeouts : & schema.ResourceTimeout {
25
+ Create : schema .DefaultTimeout (45 * time .Minute ),
26
+ },
27
+
22
28
// ----------------------------------------------------------------------
23
29
// IMPORTANT: Do not add any additional ForceNew fields to this resource.
24
30
// Destroying/recreating tables can lead to data loss for users.
@@ -124,7 +130,12 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error
124
130
column := co .(map [string ]interface {})
125
131
126
132
if v , ok := column ["family" ]; ok {
127
- if err := c .CreateColumnFamily (ctx , name , v .(string )); err != nil {
133
+ // Set a longer timeout as adding column family can be slow. The current timeout
134
+ // in the Go client is less than one minute. This timeout should not be longer
135
+ // than the overall timeout.
136
+ ctxWithTimeout , cancel := context .WithTimeout (ctx , 5 * time .Minute )
137
+ defer cancel () // Always call cancel.
138
+ if err := c .CreateColumnFamily (ctxWithTimeout , name , v .(string )); err != nil {
128
139
return fmt .Errorf ("Error creating column family %s. %s" , v , err )
129
140
}
130
141
}
0 commit comments