@@ -25,7 +25,7 @@ func TestAccCluster_basic(t *testing.T) {
25
25
Config : testAccClusterResource (roleName , clusterName , cluster2Name , roleName , "3xsmall" , "1" , "1s" , "true" , "true" , "Comment" ),
26
26
Check : resource .ComposeTestCheckFunc (
27
27
testAccCheckClusterExists ("materialize_cluster.test" ),
28
- resource .TestMatchResourceAttr ("materialize_cluster.test" , "id" , terraformObjectIdRegex ),
28
+ resource .TestMatchResourceAttr ("materialize_cluster.test" , "id" , terraformObjectTypeIdRegex ),
29
29
resource .TestCheckResourceAttr ("materialize_cluster.test" , "name" , clusterName ),
30
30
resource .TestCheckResourceAttr ("materialize_cluster.test" , "ownership_role" , "mz_system" ),
31
31
resource .TestCheckResourceAttr ("materialize_cluster.test" , "size" , "" ),
@@ -49,7 +49,7 @@ func TestAccCluster_basic(t *testing.T) {
49
49
ResourceName : "materialize_cluster.test" ,
50
50
ImportState : true ,
51
51
ImportStateVerify : true ,
52
- ImportStateVerifyIgnore : []string {"introspection_debugging" , "introspection_interval" },
52
+ ImportStateVerifyIgnore : []string {"introspection_debugging" , "introspection_interval" , "identify_by_name" },
53
53
},
54
54
},
55
55
})
@@ -81,7 +81,7 @@ func TestAccClusterCCSize_basic(t *testing.T) {
81
81
ResourceName : "materialize_cluster.test" ,
82
82
ImportState : true ,
83
83
ImportStateVerify : true ,
84
- ImportStateVerifyIgnore : []string {"introspection_debugging" , "introspection_interval" },
84
+ ImportStateVerifyIgnore : []string {"introspection_debugging" , "introspection_interval" , "identify_by_name" },
85
85
},
86
86
},
87
87
})
@@ -107,7 +107,7 @@ func TestAccClusterManagedNoReplication_basic(t *testing.T) {
107
107
ResourceName : "materialize_cluster.test" ,
108
108
ImportState : true ,
109
109
ImportStateVerify : true ,
110
- ImportStateVerifyIgnore : []string {"introspection_debugging" , "introspection_interval" },
110
+ ImportStateVerifyIgnore : []string {"introspection_debugging" , "introspection_interval" , "identify_by_name" },
111
111
},
112
112
},
113
113
})
@@ -133,7 +133,7 @@ func TestAccClusterManagedZeroReplication_basic(t *testing.T) {
133
133
ResourceName : "materialize_cluster.test" ,
134
134
ImportState : true ,
135
135
ImportStateVerify : true ,
136
- ImportStateVerifyIgnore : []string {"introspection_debugging" , "introspection_interval" },
136
+ ImportStateVerifyIgnore : []string {"introspection_debugging" , "introspection_interval" , "identify_by_name" },
137
137
},
138
138
},
139
139
})
@@ -293,6 +293,38 @@ func TestAccClusterWithScheduling(t *testing.T) {
293
293
})
294
294
}
295
295
296
+ func TestAccCluster_identifyByName (t * testing.T ) {
297
+ clusterName := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
298
+ resource .ParallelTest (t , resource.TestCase {
299
+ PreCheck : func () { testAccPreCheck (t ) },
300
+ ProviderFactories : testAccProviderFactories ,
301
+ CheckDestroy : testAccCheckAllClusterDestroyed ,
302
+ Steps : []resource.TestStep {
303
+ {
304
+ Config : testAccClusterResourceWithNameAsId (clusterName , "3xsmall" , "1" ),
305
+ Check : resource .ComposeTestCheckFunc (
306
+ testAccCheckClusterExists ("materialize_cluster.test_name_as_id" ),
307
+ resource .TestCheckResourceAttr ("materialize_cluster.test_name_as_id" , "name" , clusterName ),
308
+ resource .TestCheckResourceAttr ("materialize_cluster.test_name_as_id" , "identify_by_name" , "true" ),
309
+ resource .TestCheckResourceAttr ("materialize_cluster.test_name_as_id" , "id" , "aws/us-east-1:name:" + clusterName ),
310
+ resource .TestCheckResourceAttr ("materialize_cluster.test_name_as_id" , "size" , "3xsmall" ),
311
+ resource .TestCheckResourceAttr ("materialize_cluster.test_name_as_id" , "replication_factor" , "1" ),
312
+ ),
313
+ },
314
+ {
315
+ ResourceName : "materialize_cluster.test_name_as_id" ,
316
+ ImportState : true ,
317
+ ImportStateVerify : true ,
318
+ ImportStateVerifyIgnore : []string {
319
+ "identify_by_name" ,
320
+ "introspection_debugging" ,
321
+ "introspection_interval" ,
322
+ },
323
+ },
324
+ },
325
+ })
326
+ }
327
+
296
328
func TestAccCluster_disappears (t * testing.T ) {
297
329
clusterName := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
298
330
cluster2Name := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
@@ -436,6 +468,20 @@ resource "materialize_cluster" "test_scheduling" {
436
468
` , clusterName , size , onRefreshStr , rehydrationTimeEstimate )
437
469
}
438
470
471
+ func testAccClusterResourceWithNameAsId (clusterName , clusterSize , clusterReplicationFactor string ) string {
472
+ return fmt .Sprintf (`
473
+ resource "materialize_cluster" "test_name_as_id" {
474
+ name = "%[1]s"
475
+ size = "%[2]s"
476
+ replication_factor = %[3]s
477
+ identify_by_name = true
478
+ }
479
+ ` ,
480
+ clusterName ,
481
+ clusterSize ,
482
+ clusterReplicationFactor )
483
+ }
484
+
439
485
func testAccCheckClusterExists (name string ) resource.TestCheckFunc {
440
486
return func (s * terraform.State ) error {
441
487
meta := testAccProvider .Meta ()
@@ -447,7 +493,11 @@ func testAccCheckClusterExists(name string) resource.TestCheckFunc {
447
493
if ! ok {
448
494
return fmt .Errorf ("cluster not found: %s" , name )
449
495
}
450
- _ , err = materialize .ScanCluster (db , utils .ExtractId (r .Primary .ID ))
496
+ identifyByName := false
497
+ if r .Primary .Attributes ["identify_by_name" ] == "true" {
498
+ identifyByName = true
499
+ }
500
+ _ , err = materialize .ScanCluster (db , utils .ExtractId (r .Primary .ID ), identifyByName )
451
501
return err
452
502
}
453
503
}
@@ -464,7 +514,7 @@ func testAccCheckAllClusterDestroyed(s *terraform.State) error {
464
514
continue
465
515
}
466
516
467
- _ , err := materialize .ScanCluster (db , utils .ExtractId (r .Primary .ID ))
517
+ _ , err := materialize .ScanCluster (db , utils .ExtractId (r .Primary .ID ), false )
468
518
if err == nil {
469
519
return fmt .Errorf ("Cluster %v still exists" , utils .ExtractId (r .Primary .ID ))
470
520
} else if err != sql .ErrNoRows {
0 commit comments