Introduction to YDB via Terraform
Terraformtf
extention. The HCL code is very similar to JSON and organized into logical sections within configuration files.
With Terraform, you can create and modify YDB databases, as well as manage their resources, such as tables, indexes, and table changefeeds. It is important to understand that the configuration file you create to manage YDB becomes the single point of control for the database state, and all your database updates must take place through it. This is because after each successful update, Terraform creates a special state file, i.e., a textual representation of the current database state, and uses it for reference in all subsequent updates.
If you modify 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 what is written in the state file. However, this does not mean that Terraform will automatically accept new changes and update the state file. The reason is that the next time you run the terraform apply
command, Terraform will try to bring the resources to the state described in your configuration file, which can overwrite or delete your external changes. Therefore, to avoid conflicts between YDB state updates, you should use the single point of access, i.e., the configuration file.
The yandex_ydb
provider enables you to connect Terraform to YDB, and the yc console client is used for authentication.
This section contains the following guides:
- Obtaining authentication data.
- Installing and configuring Terraform and a provider to connect to YDB.
- Creating configuration files and connecting to YDB.
- Creating and editing parameters of a serverless database.
- Creating and editing parameters of a dedicated database.
- Creating row-based tables in a database.
- Creating a table changefeed.
- Creating secondary indexes in row-oriented tables.
- Creating topics.
Resources
The following Terraform provider resources are supported for Managed Service for YDB:
Terraform resource | Yandex Cloud resource |
---|---|
yandex_ydb_database_dedicated |
Database on dedicated resources |
yandex_ydb_database_iam_binding |
Binding access privileges 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 |
Secondary table 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 |