Skip to content

Commit cbc8540

Browse files
committed
multi-region CDC
Add new astra_cdc_v3 resource to use the new CDC API endpoints in support of multi-region CDC. Deprecate the older astra_cdc resource.
1 parent 65b28be commit cbc8540

File tree

8 files changed

+508
-10
lines changed

8 files changed

+508
-10
lines changed

docs/resources/cdc.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ resource "random_uuid" "identifier" {}
2525
2626
# Create a new tenant
2727
resource "astra_streaming_tenant" "streaming_tenant" {
28+
cluster_name = "pulsar-gcp-uscentral1"
2829
tenant_name = substr("webstore-clicks-${random_uuid.identifier.id}", 0, 32)
2930
user_email = "someuser@example.com"
30-
cloud_provider = "gcp"
3131
deletion_protection = false
32-
region = "us-central1"
3332
}
3433
3534
# Create a new database
@@ -74,7 +73,6 @@ resource "astra_cdc" "db_cdc" {
7473
database_name = astra_database.db_database.name
7574
table = astra_table.db_table.table
7675
keyspace = astra_database.db_database.keyspace
77-
pulsar_cluster = astra_streaming_tenant.cluster_name
7876
tenant_name = astra_streaming_tenant.streaming_tenant.tenant_name
7977
topic_partitions = 3
8078
}

docs/resources/cdc_v3.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "astra_cdc_v3 Resource - terraform-provider-astra"
4+
subcategory: ""
5+
description: |-
6+
astra_cdc_v3 enables CDC between Astra Serverless database and Astra Streaming.
7+
---
8+
9+
# astra_cdc_v3 (Resource)
10+
11+
`astra_cdc_v3` enables CDC between Astra Serverless database and Astra Streaming.
12+
13+
## Example Usage
14+
15+
```terraform
16+
/*
17+
NOTE:
18+
19+
The streaming tenant and database will be created at the same time because they have no dependent resources in the flow.
20+
The table will then be created, and then the CDC connection after that. This all follows terraform dependency rules.
21+
*/
22+
23+
# Generate a random pet name to avoid naming conflicts
24+
resource "random_uuid" "identifier" {}
25+
26+
# Create a new tenant
27+
resource "astra_streaming_tenant" "streaming_tenant" {
28+
cluster_name = "pulsar-gcp-uscentral1"
29+
tenant_name = substr("webstore-clicks-${random_uuid.identifier.id}", 0, 32)
30+
user_email = "someuser@example.com"
31+
cloud_provider = "gcp"
32+
deletion_protection = false
33+
region = "us-central1"
34+
}
35+
36+
# Create a new database
37+
resource "astra_database" "db_database" {
38+
name = substr("webstore-clicks-${random_uuid.identifier.id}", 0, 50)
39+
keyspace = "click_data" # 48 characters max
40+
cloud_provider = "gcp" # this must match the cloud_provider of the tenant
41+
regions = ["us-central1"] # this must match the region of the tenant
42+
deletion_protection = false
43+
}
44+
45+
# Create a new table in that database
46+
resource "astra_table" "db_table" {
47+
keyspace = astra_database.db_database.keyspace
48+
database_id = astra_database.db_database.id
49+
region = astra_database.db_database.regions[0]
50+
table = "all_product_clicks"
51+
clustering_columns = "visitor_id:click_timestamp"
52+
partition_keys = "visitor_id:click_url"
53+
column_definitions = [
54+
{
55+
Name : "click_timestamp"
56+
Static : false
57+
TypeDefinition : "bigint"
58+
},
59+
{
60+
Name : "visitor_id"
61+
Static : false
62+
TypeDefinition : "uuid"
63+
},
64+
{
65+
Name : "click_url"
66+
Static : false
67+
TypeDefinition : "text"
68+
}
69+
]
70+
}
71+
72+
# Create a new CDC connection between tenant topic and db table
73+
resource "astra_cdc" "db_cdc" {
74+
database_id = astra_database.db_database.id
75+
database_name = astra_database.db_database.name
76+
table = astra_table.db_table.table
77+
keyspace = astra_database.db_database.keyspace
78+
pulsar_cluster = astra_streaming_tenant.cluster_name
79+
tenant_name = astra_streaming_tenant.streaming_tenant.tenant_name
80+
topic_partitions = 3
81+
}
82+
83+
# --Formatted Outputs--
84+
# astra_cdc.db_cdc.connector_status
85+
# astra_cdc.db_cdc.data_topic
86+
# astra_cdc.db_cdc.id
87+
```
88+
89+
<!-- schema generated by tfplugindocs -->
90+
## Schema
91+
92+
### Required
93+
94+
- `database_id` (String) Astra database to create the keyspace.
95+
- `database_name` (String) Astra database name.
96+
- `regions` (Attributes List) Mapping between datacenter regions and streaming tenants. (see [below for nested schema](#nestedatt--regions))
97+
- `tables` (Attributes List) List of tables to enable CDC. Must include at least 1. (see [below for nested schema](#nestedatt--tables))
98+
99+
<a id="nestedatt--regions"></a>
100+
### Nested Schema for `regions`
101+
102+
Required:
103+
104+
- `datacenter_id` (String) Astra Datacenter ID
105+
- `region` (String) Cloud provider region
106+
- `streaming_cluster` (String) Name of Pulsar cluster hosting the streaming tenant.
107+
- `streaming_tenant` (String) Name of the streaming tenant
108+
109+
110+
<a id="nestedatt--tables"></a>
111+
### Nested Schema for `tables`
112+
113+
Required:
114+
115+
- `keyspace` (String)
116+
- `table` (String)
117+
118+
## Import
119+
120+
Import is supported using the following syntax:
121+
122+
```shell
123+
terraform import astra_cdc_v3.example \<databaseId\>
124+
```

examples/resources/astra_cdc/resource.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ resource "random_uuid" "identifier" {}
1010

1111
# Create a new tenant
1212
resource "astra_streaming_tenant" "streaming_tenant" {
13+
cluster_name = "pulsar-gcp-uscentral1"
1314
tenant_name = substr("webstore-clicks-${random_uuid.identifier.id}", 0, 32)
1415
user_email = "someuser@example.com"
15-
cloud_provider = "gcp"
1616
deletion_protection = false
17-
region = "us-central1"
1817
}
1918

2019
# Create a new database
@@ -59,7 +58,6 @@ resource "astra_cdc" "db_cdc" {
5958
database_name = astra_database.db_database.name
6059
table = astra_table.db_table.table
6160
keyspace = astra_database.db_database.keyspace
62-
pulsar_cluster = astra_streaming_tenant.cluster_name
6361
tenant_name = astra_streaming_tenant.streaming_tenant.tenant_name
6462
topic_partitions = 3
6563
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import astra_cdc_v3.example \<databaseId\>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
NOTE:
3+
4+
The streaming tenant and database will be created at the same time because they have no dependent resources in the flow.
5+
The table will then be created, and then the CDC connection after that. This all follows terraform dependency rules.
6+
*/
7+
8+
# Generate a random pet name to avoid naming conflicts
9+
resource "random_uuid" "identifier" {}
10+
11+
# Create a new tenant
12+
resource "astra_streaming_tenant" "streaming_tenant" {
13+
cluster_name = "pulsar-gcp-uscentral1"
14+
tenant_name = substr("webstore-clicks-${random_uuid.identifier.id}", 0, 32)
15+
user_email = "someuser@example.com"
16+
cloud_provider = "gcp"
17+
deletion_protection = false
18+
region = "us-central1"
19+
}
20+
21+
# Create a new database
22+
resource "astra_database" "db_database" {
23+
name = substr("webstore-clicks-${random_uuid.identifier.id}", 0, 50)
24+
keyspace = "click_data" # 48 characters max
25+
cloud_provider = "gcp" # this must match the cloud_provider of the tenant
26+
regions = ["us-central1"] # this must match the region of the tenant
27+
deletion_protection = false
28+
}
29+
30+
# Create a new table in that database
31+
resource "astra_table" "db_table" {
32+
keyspace = astra_database.db_database.keyspace
33+
database_id = astra_database.db_database.id
34+
region = astra_database.db_database.regions[0]
35+
table = "all_product_clicks"
36+
clustering_columns = "visitor_id:click_timestamp"
37+
partition_keys = "visitor_id:click_url"
38+
column_definitions = [
39+
{
40+
Name : "click_timestamp"
41+
Static : false
42+
TypeDefinition : "bigint"
43+
},
44+
{
45+
Name : "visitor_id"
46+
Static : false
47+
TypeDefinition : "uuid"
48+
},
49+
{
50+
Name : "click_url"
51+
Static : false
52+
TypeDefinition : "text"
53+
}
54+
]
55+
}
56+
57+
# Create a new CDC connection between tenant topic and db table
58+
resource "astra_cdc" "db_cdc" {
59+
database_id = astra_database.db_database.id
60+
database_name = astra_database.db_database.name
61+
table = astra_table.db_table.table
62+
keyspace = astra_database.db_database.keyspace
63+
pulsar_cluster = astra_streaming_tenant.cluster_name
64+
tenant_name = astra_streaming_tenant.streaming_tenant.tenant_name
65+
topic_partitions = 3
66+
}
67+
68+
# --Formatted Outputs--
69+
# astra_cdc.db_cdc.connector_status
70+
# astra_cdc.db_cdc.data_topic
71+
# astra_cdc.db_cdc.id

internal/provider/provider_framework.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (p *astraProvider) DataSources(_ context.Context) []func() datasource.DataS
107107
// Resources defines the resources implemented in this provider.
108108
func (p *astraProvider) Resources(_ context.Context) []func() resource.Resource {
109109
return []func() resource.Resource{
110+
NewAstraCDCv3Resource,
110111
NewStreamingTenantResource,
111112
NewStreamingNamespaceResource,
112113
NewStreamingPulsarTokenResource,

internal/provider/resource_cdc.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121

2222
func resourceCDC() *schema.Resource {
2323
return &schema.Resource{
24-
Description: "`astra_cdc` enables cdc for an Astra Serverless table.",
25-
CreateContext: resourceCDCCreate,
26-
ReadContext: resourceCDCRead,
27-
DeleteContext: resourceCDCDelete,
24+
DeprecationMessage: "`astra_cdc` is deprecated, please migrate to `astra_cdc_v3`.",
25+
Description: "`astra_cdc` enables cdc for an Astra Serverless table.",
26+
CreateContext: resourceCDCCreate,
27+
ReadContext: resourceCDCRead,
28+
DeleteContext: resourceCDCDelete,
2829

2930
Importer: &schema.ResourceImporter{
3031
StateContext: schema.ImportStatePassthroughContext,

0 commit comments

Comments
 (0)