[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for YDB](../index.md) > Using YDB via Terraform > Managing YDB topic configurations

# Managing YDB topic configurations

For operations with [topics](https://ydb.tech/docs/en//concepts/topic), use the `yandex_ydb_topic` resource.

{% note info %}

We recommend creating a topic in a separate folder. A topic in the database root visually breaks the database structure.

{% endnote %}

## Description of the yandex_ydb_topic resource {#yandex_ydb_topic_description}

Usage example for `yandex_ydb_topic`:

```tf
resource "yandex_ydb_topic" "ydb_topic" {
  database_endpoint = yandex_ydb_database_serverless.database1.ydb_full_endpoint  # database connection example
  name              = "test_dir/test_topic"
  supported_codecs  = ["zstd"]

  consumer {
    name             = "test-consumer1"
    starting_message_timestamp_ms = 0
    supported_codecs = ["zstd","raw"]
  }

  consumer {
    name             = "test-consumer2"
    starting_message_timestamp_ms = 2000
    supported_codecs = ["zstd"]
  }

  consumer {
    name             = "test-consumer3"
    starting_message_timestamp_ms = 0
    supported_codecs = ["zstd"]
  }
}
```

The following fields are supported:
| **Field name** | **Type** | **Description** |
| --- | --- | --- |
|`name`|`string`<br>`required`|Topic name.|
|`database_endpoint`|`string`<br>`required`|Full database path.|
|`retention_period_ms`|`number`<br>`optional`|Data retention period, in ms. The default value is `86400000` (full day).|
|`partitions_count`|`number`<br>`optional`|Number of partitions; the default value is `2`.|
|`supported_codecs`|`list(string)`<br>`optional`|Supported data compression codecs; the default value is `"gzip", "raw", "zstd"`,<br>which can be combined as needed.|
|`consumer`|`consumer`|Topic consumers.|

{% note info %}

You can create a consumer using Terraform but you cannot delete it. To delete a consumer, use the [management console](https://console.yandex.cloud) or [YDB CLI](https://ydb.tech/docs/en//reference/ydb-cli/install).

{% endnote %}

Data [consumer](https://ydb.tech/docs/en//concepts/topic#consumer) description:
| **Field name** | **Type** | **Description** |
| --- | --- | --- |
|`name`|`string`<br>`required`|Consumer name.|
|`supported_codecs`|`list(string)`<br>`optional`|Supported data compression codecs; the default value is `"gzip", "raw", "zstd"`, which can be combined as needed.|
|`starting_message_timestamp_ms`|`number`<br>`optional`|[UNIX timestamp](https://ru.wikipedia.org/wiki/Unix-время), in ms, for the consumer to start reading data from. The default is `0`, i.e., from the beginning of delivery.|