@@ -47,8 +47,9 @@ type CDCResourceModel struct {
47
47
}
48
48
49
49
type KeyspaceTable struct {
50
- Keyspace types.String `tfsdk:"keyspace"`
51
- Table types.String `tfsdk:"table"`
50
+ Keyspace types.String `tfsdk:"keyspace"`
51
+ Table types.String `tfsdk:"table"`
52
+ DataTopics []types.String `tfsdk:"data_topics"`
52
53
}
53
54
54
55
type DatacenterToStreamingMap struct {
@@ -58,6 +59,17 @@ type DatacenterToStreamingMap struct {
58
59
StreamingTenant types.String `tfsdk:"streaming_tenant"`
59
60
}
60
61
62
+ // setDataTopics updates the data topics field for each table based on caculateCDCDataTopicName.
63
+ func (m * CDCResourceModel ) setDataTopics () {
64
+ for i := range m .Tables {
65
+ m .Tables [i ].DataTopics = make ([]types.String , len (m .Regions ))
66
+ for j := range m .Regions {
67
+ m .Tables [i ].DataTopics [j ] = types .StringValue (calculateCDCDataTopicName (m .Regions [j ].StreamingTenant .ValueString (),
68
+ m .DatabaseID .ValueString (), m .Tables [i ].Keyspace .ValueString (), m .Tables [i ].Table .ValueString ()))
69
+ }
70
+ }
71
+ }
72
+
61
73
func (r * CDCResource ) Metadata (_ context.Context , req resource.MetadataRequest , resp * resource.MetadataResponse ) {
62
74
resp .TypeName = "astra_cdc_v3"
63
75
}
@@ -88,6 +100,12 @@ func (r *CDCResource) Schema(_ context.Context, req resource.SchemaRequest, resp
88
100
"table" : schema.StringAttribute {
89
101
Required : true ,
90
102
},
103
+ "data_topics" : schema.ListAttribute {
104
+ Description : "List of Pulsar topics to which CDC data is published. " +
105
+ "One data topic per region, in the same order of regions." ,
106
+ Computed : true ,
107
+ ElementType : types .StringType ,
108
+ },
91
109
},
92
110
},
93
111
},
@@ -144,6 +162,7 @@ func (r *CDCResource) Create(ctx context.Context, req resource.CreateRequest, re
144
162
return
145
163
}
146
164
165
+ plan .setDataTopics ()
147
166
diags = resp .State .Set (ctx , & plan )
148
167
resp .Diagnostics .Append (diags ... )
149
168
}
@@ -286,7 +305,7 @@ func updateStateForCDCReadRequest(tfData *CDCResourceModel, respData *astra.List
286
305
})
287
306
}
288
307
tfData .Regions = regions
289
-
308
+ tfData . setDataTopics ()
290
309
}
291
310
292
311
func createDeleteCDCRequestBody (tfData * CDCResourceModel ) astra.DeleteCDCJSONRequestBody {
@@ -302,3 +321,11 @@ func createDeleteCDCRequestBody(tfData *CDCResourceModel) astra.DeleteCDCJSONReq
302
321
}
303
322
return reqData
304
323
}
324
+
325
+ const AstraCDCPulsarNamespace = "astracdc"
326
+
327
+ // calculateCDCDataTopicName constructs the expected CDC data topic name based on the database ID and streaming tenant.
328
+ // For example 'persistent://terraform-support1/astracdc/data-0d509b0f-d38a-4c8e-9680-fa7c752189b7-ks1.table1'
329
+ func calculateCDCDataTopicName (streamingTenant , databaseID , keyspace , tableName string ) string {
330
+ return fmt .Sprintf ("persistent://%s/%s/data-%s-%s.%s" , streamingTenant , AstraCDCPulsarNamespace , databaseID , keyspace , tableName )
331
+ }
0 commit comments