Introduction to using YDB via Terraform
Terraformtf extension. The HCL code is very similar to JSON and arranged into logical sections within configuration files.
With Terraform, you can create and update YDB databases, as well as manage their resources, such as tables, indexes, and table change data feeds. You should keep in mind that the configuration file you create to manage YDB becomes the single point of control for the database state, and you should describe any database updates in it. This is because after you successfully apply changes, Terraform creates a special state file, i.e., a text representation of the current database state, and uses it for reference in all subsequent updates.
If you update the database state via the configuration file and then change something else using the management console or CLI, Terraform will remain unaware of these changes until you run the terraform plan or terraform refresh commands. These commands will force Terraform to check the current state of the resources against the code in the state file. However, this does not mean that Terraform will automatically accept new changes and update the state file. The next time you run the terraform apply command, Terraform will try to bring the resources back to the state described in your configuration file, which can overwrite or delete your changes made outside Terraform. Therefore, to avoid conflicts between YDB state updates, you should use the configuration file as the single point of access.
Terraform connects to YDB via the yandex_ydb provider, with authentication via the yc console client.
This section contains the following guides:
- Getting authentication credentials.
- Installing and configuring Terraform and a provider to connect to YDB.
- Creating configuration files and connecting to YDB.
- Creating and reconfiguring a serverless database.
- Creating and reconfiguring a dedicated database.
- Creating row-oriented and column-oriented tables in a database.
- Creating a change data feed for a table.
- Creating secondary indexes in row-oriented tables.
- Creating topics.
Resources
Managed Service for YDB supports the following Terraform provider resources:
| Terraform resource | Yandex Cloud resource |
|---|---|
| yandex_ydb_database_dedicated | Database on dedicated resources |
| yandex_ydb_database_iam_binding | Binding access permissions to a database |
| yandex_ydb_database_serverless | Serverless database |
| yandex_ydb_topic | Topic |
| yandex_ydb_table | Table |
| yandex_ydb_table_changefeed | Change Data Capture |
yandex_ydb_table_index |
Table secondary index |
Data sources
Managed Service for YDB supports the following Terraform provider data sources:
| Terraform data source | Description |
|---|---|
| yandex_ydb_database_dedicated | Information about a database on dedicated resources |
| yandex_ydb_database_serverless | Information about a serverless database |