Creating a change data feed for a table
Change data capture (CDC)
Description of the yandex_ydb_table_changefeed resource
You can create a change data feed (CDF) for a table using the yandex_ydb_table_changefeed resource:
resource "yandex_ydb_table_changefeed" "ydb_changefeed" {
table_id = yandex_ydb_table.test_table_2.id
name = "changefeed"
mode = "NEW_IMAGE"
format = "JSON"
consumer {
name = "test_consumer"
}
}
We used the following fields to create a table CDF:
table_id: ID of the table to create a CDF for.name: CDF name.mode: CDF mode. For all available CDF modes, see this guide .format: CDF format. Only JSON format is available.
Full description of all the yandex_ydb_table_changefeed resource fields:
| Field name | Type | Description |
|---|---|---|
| table_path | stringrequired |
Table path. |
| connection_string | stringrequired |
Connection string, conflicts with table_id. |
| database_id | stringrequired |
Database ID, conflicts with table_path and connection_string. |
| table_id | stringrequired |
Terraform table ID. |
| name | stringrequired |
CDF name. |
| mode | stringrequired |
CDF mode |
| format | stringrequired |
CDF format. |
| virtual_timestamps | booloptional |
Using virtual timestamps |
| retention_period | stringoptional |
Data retention period in a topic, in ISO 8601 |
| consumer | array[consumer]optional |
Consumers for a CDF. |
When initializing the yandex_ydb_table_changefeed resource, you can only specify one connection field: connection_string, table_path, or table_id. If you specify multiple connection fields, they will come into conflict, e.g., the table_id field with a relative link in <resource>.<ID>.<parameter> format: yandex_ydb_table.test_table_2.id.
The CDF resource contains the consumer section. A consumername, i.e., the consumer's name. When initializing the yandex_ydb_table_changefeed resource, you can specify multiple consumers, or none; however, in this case, you will not be able to read data from the CDF.
Full list of the consumer section fields:
| Field name | Type | Description |
|---|---|---|
| name | stringrequired |
Consumer name. |
| supported_codecs | array[string]optional |
Supported data encodings. |
| starting_message_timestamp_ms | integeroptional |
UNIX timestamp for the consumer to start reading data from. |
The consumer name is used in the SDK or CLI to read data