@@ -65,6 +65,12 @@ func resourceCDC() *schema.Resource {
65
65
Required : true ,
66
66
ForceNew : true ,
67
67
},
68
+ "pulsar_cluster" : {
69
+ Description : "Pulsar cluster name" ,
70
+ Type : schema .TypeString ,
71
+ Optional : true ,
72
+ ForceNew : true ,
73
+ },
68
74
"tenant_name" : {
69
75
Description : "Streaming tenant name" ,
70
76
Type : schema .TypeString ,
@@ -96,6 +102,7 @@ func resourceCDCDelete(ctx context.Context, resourceData *schema.ResourceData, m
96
102
token := meta .(astraClients ).token
97
103
98
104
id := resourceData .Id ()
105
+ pulsarClusterFromConfig := resourceData .Get ("pulsar_cluster_name" ).(string )
99
106
100
107
databaseId , keyspace , table , tenantName , err := parseCDCID (id )
101
108
if err != nil {
@@ -114,7 +121,7 @@ func resourceCDCDelete(ctx context.Context, resourceData *schema.ResourceData, m
114
121
return diag .FromErr (fmt .Errorf ("failed to read current organization: %w" , err ))
115
122
}
116
123
117
- pulsarCluster , pulsarToken , err := prepCDC (ctx , client , databaseId , token , org , streamingClient , tenantName )
124
+ pulsarCluster , pulsarToken , err := prepCDC (ctx , client , databaseId , token , org , streamingClient , tenantName , pulsarClusterFromConfig )
118
125
if err != nil {
119
126
diag .FromErr (err )
120
127
}
@@ -190,6 +197,7 @@ func resourceCDCRead(ctx context.Context, resourceData *schema.ResourceData, met
190
197
token := meta .(astraClients ).token
191
198
192
199
id := resourceData .Id ()
200
+ pulsarClusterFromConfig := resourceData .Get ("pulsar_cluster_name" ).(string )
193
201
194
202
databaseId , keyspace , table , tenantName , err := parseCDCID (id )
195
203
if err != nil {
@@ -206,7 +214,7 @@ func resourceCDCRead(ctx context.Context, resourceData *schema.ResourceData, met
206
214
return diag .FromErr (fmt .Errorf ("failed to read organization: %w" , err ))
207
215
}
208
216
209
- pulsarCluster , pulsarToken , err := prepCDC (ctx , client , databaseId , token , orgId , streamingClient , tenantName )
217
+ pulsarCluster , pulsarToken , err := prepCDC (ctx , client , databaseId , token , orgId , streamingClient , tenantName , pulsarClusterFromConfig )
210
218
if err != nil {
211
219
diag .FromErr (err )
212
220
}
@@ -291,6 +299,7 @@ func resourceCDCCreate(ctx context.Context, resourceData *schema.ResourceData, m
291
299
databaseId := resourceData .Get ("database_id" ).(string )
292
300
databaseName := resourceData .Get ("database_name" ).(string )
293
301
topicPartitions := resourceData .Get ("topic_partitions" ).(int )
302
+ pulsarClusterFromConfig := resourceData .Get ("pulsar_cluster_name" ).(string )
294
303
tenantName := resourceData .Get ("tenant_name" ).(string )
295
304
296
305
orgBody , _ := client .GetCurrentOrganization (ctx )
@@ -309,7 +318,7 @@ func resourceCDCCreate(ctx context.Context, resourceData *schema.ResourceData, m
309
318
TopicPartitions : topicPartitions ,
310
319
}
311
320
312
- pulsarCluster , pulsarToken , err := prepCDC (ctx , client , databaseId , token , org , streamingClient , tenantName )
321
+ pulsarCluster , pulsarToken , err := prepCDC (ctx , client , databaseId , token , org , streamingClient , tenantName , pulsarClusterFromConfig )
313
322
if err != nil {
314
323
return diag .FromErr (err )
315
324
}
@@ -386,7 +395,10 @@ func getTableCDCStatus(databaseID, keyspace, table string, cdcStatuses CDCStatus
386
395
return nil
387
396
}
388
397
389
- func prepCDC (ctx context.Context , client * astra.ClientWithResponses , databaseId string , token string , org OrgId , streamingClient * astrastreaming.ClientWithResponses , tenantName string ) (string , string , error ) {
398
+ // prepCDC get the pulsar cluster name (if it's not set) and the pulsar token
399
+ func prepCDC (ctx context.Context , client * astra.ClientWithResponses , databaseId string , token string , org OrgId ,
400
+ streamingClient * astrastreaming.ClientWithResponses , tenantName string , pulsarCluster string ) (string , string , error ) {
401
+
390
402
databaseResourceData := schema.ResourceData {}
391
403
db , err := getDatabase (ctx , & databaseResourceData , client , databaseId )
392
404
if err != nil {
@@ -395,9 +407,8 @@ func prepCDC(ctx context.Context, client *astra.ClientWithResponses, databaseId
395
407
396
408
// In most astra APIs there are dashes in region names depending on the cloud provider, this seems not to be the case for streaming
397
409
cloudProvider := string (* db .Info .CloudProvider )
398
- fmt . Printf ( "%s" , cloudProvider )
410
+ pulsarCluster = getPulsarCluster ( pulsarCluster , cloudProvider , * db . Info . Region , "" )
399
411
400
- pulsarCluster := getPulsarCluster ("" , cloudProvider , * db .Info .Region , "" )
401
412
pulsarToken , err := getPulsarToken (ctx , pulsarCluster , token , org , streamingClient , tenantName )
402
413
return pulsarCluster , pulsarToken , err
403
414
}
@@ -455,6 +466,7 @@ func setCDCData(resourceData *schema.ResourceData, cdc CDCStatus) diag.Diagnosti
455
466
return nil
456
467
}
457
468
469
+ // parseCDCID expects an ID in the format "databaseId/keyspace/table/tenantName"
458
470
func parseCDCID (id string ) (string , string , string , string , error ) {
459
471
idParts := strings .Split (strings .ToLower (id ), "/" )
460
472
if len (idParts ) != 4 {
0 commit comments