Skip to content

Commit 9592b8e

Browse files
authored
updates for multi-region CDC (#449)
* fix bug on CDCv3 create * update docs * add and update tests
1 parent 4448e08 commit 9592b8e

File tree

5 files changed

+125
-11
lines changed

5 files changed

+125
-11
lines changed

docs/resources/cdc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
page_title: "astra_cdc Resource - terraform-provider-astra"
44
subcategory: ""
55
description: |-
6-
astra_cdc enables cdc for an Astra Serverless table.
6+
Deprecated as of version 2.4, please use astra_cdc_v3 resource instead.
77
---
88

99
# astra_cdc (Resource)
1010

11-
`astra_cdc` enables cdc for an Astra Serverless table.
11+
Deprecated as of version 2.4, please use `astra_cdc_v3` resource instead.
1212

1313
## Example Usage
1414

internal/provider/resource_cdc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
func resourceCDC() *schema.Resource {
2323
return &schema.Resource{
2424
DeprecationMessage: "`astra_cdc` is deprecated, please migrate to `astra_cdc_v3`.",
25-
Description: "`astra_cdc` enables cdc for an Astra Serverless table.",
25+
Description: "Deprecated as of version 2.4, please use `astra_cdc_v3` resource instead.",
2626
CreateContext: resourceCDCCreate,
2727
ReadContext: resourceCDCRead,
2828
DeleteContext: resourceCDCDelete,

internal/provider/resource_cdc_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ resource "astra_table" "table_1" {
6868
partition_keys = "b"
6969
column_definitions = [
7070
{
71-
Name: "a"- Static: false
71+
Name: "a"
72+
Static: false
7273
TypeDefinition: "text"
7374
},
7475
{

internal/provider/resource_cdc_v3.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77

88
"github.com/datastax/astra-client-go/v2/astra"
9+
"github.com/hashicorp/terraform-plugin-framework/attr"
910
"github.com/hashicorp/terraform-plugin-framework/path"
1011
"github.com/hashicorp/terraform-plugin-framework/resource"
1112
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -47,9 +48,9 @@ type CDCResourceModel struct {
4748
}
4849

4950
type KeyspaceTable struct {
50-
Keyspace types.String `tfsdk:"keyspace"`
51-
Table types.String `tfsdk:"table"`
52-
DataTopics []types.String `tfsdk:"data_topics"`
51+
Keyspace types.String `tfsdk:"keyspace"`
52+
Table types.String `tfsdk:"table"`
53+
DataTopics types.List `tfsdk:"data_topics"`
5354
}
5455

5556
type DatacenterToStreamingMap struct {
@@ -61,12 +62,15 @@ type DatacenterToStreamingMap struct {
6162

6263
// setDataTopics updates the data topics field for each table based on caculateCDCDataTopicName.
6364
func (m *CDCResourceModel) setDataTopics() {
65+
6466
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()))
67+
dataTopics := []attr.Value{}
68+
69+
for _, region := range m.Regions {
70+
topicFQDN := calculateCDCDataTopicName(region.StreamingTenant.ValueString(), m.DatabaseID.ValueString(), m.Tables[i].Keyspace.ValueString(), m.Tables[i].Table.ValueString())
71+
dataTopics = append(dataTopics, types.StringValue(topicFQDN))
6972
}
73+
m.Tables[i].DataTopics, _ = types.ListValue(types.StringType, dataTopics)
7074
}
7175
}
7276

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package provider
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestAstraCDCv3(t *testing.T) {
11+
checkRequiredTestVars(t, "ASTRA_TEST_CDC_V3_TEST_ENABLED")
12+
streamingTenant := "terraform-cdcv3-test-" + randomString(4)
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheck(t) },
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAstraCDCv3Config("GCP", "us-east1", streamingTenant),
19+
},
20+
},
21+
})
22+
}
23+
24+
func testAstraCDCv3Config(cloud_provider, region, streamingTenant string) string {
25+
return fmt.Sprintf(`
26+
27+
resource "astra_database" "database_1" {
28+
cloud_provider = "%s"
29+
regions = ["%s"]
30+
name = "terraform-cdc-test"
31+
keyspace = "ks1"
32+
deletion_protection = "false"
33+
}
34+
35+
resource "astra_table" "table_1" {
36+
database_id = astra_database.database_1.id
37+
keyspace = astra_database.database_1.keyspace
38+
region = astra_database.database_1.region[0]
39+
table = "cdctable1"
40+
clustering_columns = "a"
41+
partition_keys = "b"
42+
column_definitions = [
43+
{
44+
Name: "a"
45+
Static: false
46+
TypeDefinition: "text"
47+
},
48+
{
49+
Name: "b"
50+
Static: false
51+
TypeDefinition: "text"
52+
}
53+
]
54+
}
55+
56+
resource "astra_table" "table_2" {
57+
database_id = astra_database.database_1.id
58+
keyspace = astra_database.database_1.keyspace
59+
region = astra_database.database_1.region[0]
60+
table = "cdctable2"
61+
clustering_columns = "a"
62+
partition_keys = "b"
63+
column_definitions = [
64+
{
65+
Name: "a"
66+
Static: false
67+
TypeDefinition: "text"
68+
},
69+
{
70+
Name: "b"
71+
Static: false
72+
TypeDefinition: "text"
73+
}
74+
]
75+
}
76+
77+
resource "astra_streaming_tenant" "tenant_1" {
78+
cluster_name = "pulsar-gcp-useast1"
79+
tenant_name = "%s"
80+
user_email = "test@datastax.com"
81+
deletion_protection = "false"
82+
}
83+
84+
resource "astra_cdc_v3" "cdc_1" {
85+
depends_on = [ astra_database.database_1, astra_streaming_tenant.streaming_tenant_1 ]
86+
database_id = astra_database.database_1.id
87+
database_name = astra_database.database_1.name
88+
tables = [
89+
{
90+
keyspace = "ks1"
91+
table = "table1"
92+
},
93+
{
94+
keyspace = "ks1"
95+
table = "table2"
96+
},
97+
]
98+
regions = [
99+
{
100+
region = "us-east1"
101+
datacenter_id = "${astra_database.example.id}-1"
102+
streaming_cluster = astra_streaming_tenant.tenant_1.cluster_name
103+
streaming_tenant = astra_streaming_tenant.tenant_1.tenant_name
104+
},
105+
]
106+
107+
}`, cloud_provider, region, streamingTenant)
108+
109+
}

0 commit comments

Comments
 (0)