@@ -211,6 +211,69 @@ func TestAccBigtableTable_deletion_protection_unprotected(t *testing.T) {
211
211
})
212
212
}
213
213
214
+ func TestAccBigtableTable_change_stream_enable (t * testing.T ) {
215
+ // bigtable instance does not use the shared HTTP client, this test creates an instance
216
+ acctest .SkipIfVcr (t )
217
+ t .Parallel ()
218
+
219
+ instanceName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
220
+ tableName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
221
+ family := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
222
+
223
+ acctest .VcrTest (t , resource.TestCase {
224
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
225
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
226
+ CheckDestroy : testAccCheckBigtableTableDestroyProducer (t ),
227
+ Steps : []resource.TestStep {
228
+ // creating a table with a column family and change stream of 1 day
229
+ {
230
+ Config : testAccBigtableTable_change_stream_retention (instanceName , tableName , "24h0m0s" , family ),
231
+ },
232
+ {
233
+ ResourceName : "google_bigtable_table.table" ,
234
+ ImportState : true ,
235
+ ImportStateVerify : true ,
236
+ },
237
+ // it is not possible to delete the table because of change stream is enabled
238
+ {
239
+ Config : testAccBigtableTable_destroyTable (instanceName ),
240
+ ExpectError : regexp .MustCompile (".*the change stream is enabled.*" ),
241
+ },
242
+ // changing change stream retention value
243
+ {
244
+ Config : testAccBigtableTable_change_stream_retention (instanceName , tableName , "120h0m0s" , family ),
245
+ },
246
+ {
247
+ ResourceName : "google_bigtable_table.table" ,
248
+ ImportState : true ,
249
+ ImportStateVerify : true ,
250
+ },
251
+ // it is not possible to delete the table because of change stream is enabled
252
+ {
253
+ Config : testAccBigtableTable_destroyTable (instanceName ),
254
+ ExpectError : regexp .MustCompile (".*the change stream is enabled.*" ),
255
+ },
256
+ // disable changing change stream retention
257
+ {
258
+ Config : testAccBigtableTable_change_stream_retention (instanceName , tableName , "0" , family ),
259
+ Check : resource .ComposeTestCheckFunc (
260
+ testAccBigtableChangeStreamDisabled (t ),
261
+ ),
262
+ },
263
+ // destroying the table is possible when change stream is disabled
264
+ {
265
+ Config : testAccBigtableTable_destroyTable (instanceName ),
266
+ },
267
+ {
268
+ ResourceName : "google_bigtable_instance.instance" ,
269
+ ImportState : true ,
270
+ ImportStateVerify : true ,
271
+ ImportStateVerifyIgnore : []string {"deletion_protection" , "instance_type" },
272
+ },
273
+ },
274
+ })
275
+ }
276
+
214
277
func TestAccBigtableTable_familyMany (t * testing.T ) {
215
278
// bigtable instance does not use the shared HTTP client, this test creates an instance
216
279
acctest .SkipIfVcr (t )
@@ -328,6 +391,35 @@ func testAccBigtableColumnFamilyExists(t *testing.T, table_name_space, family st
328
391
}
329
392
}
330
393
394
+ func testAccBigtableChangeStreamDisabled (t * testing.T ) resource.TestCheckFunc {
395
+ var ctx = context .Background ()
396
+ return func (s * terraform.State ) error {
397
+ rs , ok := s .RootModule ().Resources ["google_bigtable_table.table" ]
398
+ if ! ok {
399
+ return fmt .Errorf ("Table not found: %s" , "google_bigtable_table.table" )
400
+ }
401
+
402
+ config := acctest .GoogleProviderConfig (t )
403
+ c , err := config .BigTableClientFactory (config .UserAgent ).NewAdminClient (config .Project , rs .Primary .Attributes ["instance_name" ])
404
+ if err != nil {
405
+ return fmt .Errorf ("Error starting admin client. %s" , err )
406
+ }
407
+
408
+ defer c .Close ()
409
+
410
+ table , err := c .TableInfo (ctx , rs .Primary .Attributes ["name" ])
411
+ if err != nil {
412
+ return fmt .Errorf ("Error retrieving table. Could not find %s in %s." , rs .Primary .Attributes ["name" ], rs .Primary .Attributes ["instance_name" ])
413
+ }
414
+
415
+ if table .ChangeStreamRetention != nil {
416
+ return fmt .Errorf ("Change Stream is expected to be disabled but it's not: %v" , table )
417
+ }
418
+
419
+ return nil
420
+ }
421
+ }
422
+
331
423
func testAccBigtableTable (instanceName , tableName string ) string {
332
424
return fmt .Sprintf (`
333
425
resource "google_bigtable_instance" "instance" {
@@ -420,6 +512,32 @@ resource "google_bigtable_table" "table" {
420
512
` , instanceName , instanceName , tableName , deletionProtection , family )
421
513
}
422
514
515
+ func testAccBigtableTable_change_stream_retention (instanceName , tableName , changeStreamRetention , family string ) string {
516
+ return fmt .Sprintf (`
517
+ resource "google_bigtable_instance" "instance" {
518
+ name = "%s"
519
+
520
+ cluster {
521
+ cluster_id = "%s"
522
+ zone = "us-central1-b"
523
+ }
524
+
525
+ instance_type = "DEVELOPMENT"
526
+ deletion_protection = false
527
+ }
528
+
529
+ resource "google_bigtable_table" "table" {
530
+ name = "%s"
531
+ instance_name = google_bigtable_instance.instance.name
532
+ change_stream_retention = "%s"
533
+
534
+ column_family {
535
+ family = "%s"
536
+ }
537
+ }
538
+ ` , instanceName , instanceName , tableName , changeStreamRetention , family )
539
+ }
540
+
423
541
func testAccBigtableTable_familyMany (instanceName , tableName , family string ) string {
424
542
return fmt .Sprintf (`
425
543
resource "google_bigtable_instance" "instance" {
0 commit comments