@@ -142,7 +142,7 @@ func resourceTableCreate(ctx context.Context, d *schema.ResourceData, meta inter
142
142
TableOptions : nil ,
143
143
}
144
144
145
- var restClient astrarestapi.Client
145
+ var restClient * astrarestapi.ClientWithResponses
146
146
if val , ok := stargateCache [databaseID ]; ok {
147
147
restClient = val
148
148
} else {
@@ -230,7 +230,7 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interfa
230
230
231
231
stargateCache := meta .(astraClients ).stargateClientCache
232
232
233
- var restClient astrarestapi.Client
233
+ var restClient * astrarestapi.ClientWithResponses
234
234
if val , ok := stargateCache [databaseID ]; ok {
235
235
restClient = val
236
236
} else {
@@ -243,24 +243,25 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interfa
243
243
244
244
fmt .Printf ("%v" , restClient )
245
245
246
+ raw := true
246
247
params := astrarestapi.GetTableParams {
247
- Raw : nil ,
248
+ Raw : & raw ,
248
249
XCassandraToken : token ,
249
250
}
250
- resp , err := restClient .GetTable (ctx , keyspaceName , tableName , & params )
251
+ resp , err := restClient .GetTableWithResponse (ctx , keyspaceName , tableName , & params )
251
252
if err != nil {
252
253
return diag .FromErr (fmt .Errorf ("error getting table (not retrying) err: %w" , err ))
253
- } else if resp .StatusCode == 409 {
254
+ } else if resp .StatusCode () == 409 {
254
255
// DevOps API returns 409 for concurrent modifications, these need to be retried.
255
- b , _ := io .ReadAll (resp .Body )
256
- return diag .FromErr (fmt .Errorf ("error getting table (retrying): %s" , b ))
257
- } else if resp .StatusCode >= 400 {
256
+ return diag .Errorf ("error getting table (retrying): %s" , string (resp .Body ))
257
+ } else if resp .StatusCode () >= 400 {
258
258
//table not found
259
259
d .SetId ("" )
260
260
return nil
261
261
}
262
262
263
- if err := setTableResourceData (d , databaseID , region , keyspaceName , tableName ); err != nil {
263
+ tableData := resp .JSON200
264
+ if err := setTableResourceDataWithTableData (d , databaseID , region , keyspaceName , tableName , tableData ); err != nil {
264
265
return diag .FromErr (fmt .Errorf ("Error setting keyspace data (not retrying) %s" , err ))
265
266
}
266
267
@@ -282,7 +283,7 @@ func resourceTableDelete(ctx context.Context, d *schema.ResourceData, meta inter
282
283
283
284
stargateCache := meta .(astraClients ).stargateClientCache
284
285
285
- var restClient astrarestapi.Client
286
+ var restClient * astrarestapi.ClientWithResponses
286
287
if val , ok := stargateCache [databaseID ]; ok {
287
288
restClient = val
288
289
} else {
@@ -333,6 +334,42 @@ func setTableResourceData(d *schema.ResourceData, databaseID, region, keyspaceNa
333
334
return nil
334
335
}
335
336
337
+ func setTableResourceDataWithTableData (d * schema.ResourceData , databaseID , region , keyspaceName , table string , tableData * astrarestapi.Table ) error {
338
+ if err := setTableResourceData (d , databaseID ,region , keyspaceName , table ); err != nil {
339
+ return err
340
+ }
341
+ if tableData == nil {
342
+ return fmt .Errorf ("Table Data was nil" )
343
+ }
344
+ // now set the rest of the table data
345
+ // partition_key
346
+ if err := d .Set ("partition_keys" , strings .Join (tableData .PrimaryKey .PartitionKey , ":" )); err != nil {
347
+ return err
348
+ }
349
+
350
+ // clustering_columns
351
+ if tableData .PrimaryKey .ClusteringKey != nil {
352
+ if err := d .Set ("clustering_columns" , strings .Join (* tableData .PrimaryKey .ClusteringKey , ":" )); err != nil {
353
+ return err
354
+ }
355
+ }
356
+
357
+ // column_definitions
358
+ cdefs := make ([]map [string ]string , len (tableData .ColumnDefinitions ))
359
+ for index , cdef := range tableData .ColumnDefinitions {
360
+ defs := map [string ]string {
361
+ "Name" : cdef .Name ,
362
+ "TypeDefinition" : string (cdef .TypeDefinition ),
363
+ "Static" : strconv .FormatBool (* cdef .Static ),
364
+ }
365
+ cdefs [index ] = defs
366
+ }
367
+ if err := d .Set ("column_definitions" , cdefs ); err != nil {
368
+ return err
369
+ }
370
+ return nil
371
+ }
372
+
336
373
// parseTableID returns the databaseID, region, keyspace, tablename, error (if the format is invalid).
337
374
func parseTableID (id string ) (string , string , string , string , error ) {
338
375
idParts := strings .Split (id , "/" )
0 commit comments