Creating a Yandex StoreDoc cluster
A Yandex StoreDoc cluster consists of one or multiple database hosts, with the option to configure replication between them. Any cluster with more than one host has replication enabled by default. In this setup, the primary host accepts write requests and asynchronously replicates changes to secondary hosts.
Note
- The number of hosts you can create with a Yandex StoreDoc cluster depends on the selected disk type and host class.
- The available disk types depend on the selected host class.
Cluster DB connections are managed by Connection Manager. Creating a cluster automatically creates:
-
Connection Manager connection with information about the database connection.
-
Yandex Lockbox secret that stores the DB owner's user password. Storing passwords in Yandex Lockbox ensures their security.
The connection and secret will be created for each new database user. To view all connections, select the Connections tab on the cluster page.
You need the connection-manager.viewer role to view connection info. You can use Connection Manager to configure access to connections.
You can use Connection Manager and secrets you create there free of charge.
Creating a cluster
To create a Yandex StoreDoc cluster, you need the vpc.user role along with the managed-mongodb.editor role or higher. For details on assigning roles, see this Identity and Access Management article.
To create a Yandex StoreDoc cluster:
-
In the management console
, select the folder where you want to create your database cluster. -
Navigate to the Yandex StoreDoc service.
-
Click Create cluster.
-
Under Basic parameters:
-
In the Cluster name field, specify your cluster name. The cluster name must be unique within the cloud.
-
Optionally, specify your cluster Description.
-
Select your cluster environment. Note that you cannot change the environment once the cluster is created:
PRODUCTION: For stable versions of your applications.PRESTABLE: For testing purposes. The prestable environment is similar to the production environment and is also covered by an SLA. However, it receives new features, improvements, and bug fixes earlier. In the prestable environment, you can test new versions for compatibility with your application.
-
Specify the DBMS version.
-
Select the sharding type:
- Disabled: Cluster will consist only of
MONGODhosts. - Standard: Cluster will consist of
MONGODandMONGOINFRAhosts. - Advanced: Cluster will consist of
MONGOD,MONGOS, andMONGOCFGhosts.
- Disabled: Cluster will consist only of
-
-
Under Network settings, select:
- Cloud network for cluster deployment.
- Security groups for the cluster network traffic. You may need to configure security groups to connect to the cluster.
-
Specify the computing resource configuration:
- For a non-sharded cluster, under Resources.
- For a cluster with standard sharding, under Mongod Resources and Mongoinfra Resources.
- For a cluster with advanced sharding, under Mongod Resources, Mongos Resources, and Mongocfg Resources.
To specify your computing resource configuration:
-
Select the platform, VM type, and host class. The latter determines the technical specifications of the VMs the database hosts will be deployed on. All available options are listed under Host classes. When you change the host class for a cluster, the specifications of all existing instances also change.
Note
The memory-optimized configuration type is unavailable for
MONGOShosts. -
Under Storage:
-
Select the disk type.
The selected type determines the increments in which you can change your disk size:
- Network HDD and SSD storage: In increments of 1 GB.
- Local SSD storage:
- For Intel Broadwell and Intel Cascade Lake: In increments of 100 GB.
- For Intel Ice Lake: In increments of 368 GB.
- Non-replicated SSDs and ultra high-speed network SSDs with three replicas: In increments of 93 GB.
-
Select the storage capacity for your data and backups. For more information, see Backups.
-
Optionally, select Encrypted disk to encrypt the disk with a custom KMS key.
-
To create a new key, click Create.
-
To use the key you created earlier, select it in the KMS key field.
To learn more about disk encryption, see Storage.
-
-
-
Under Hosts, add the DB hosts created with the cluster:
- Click Add host.
- Select the availability zone.
- Select a subnet in the chosen availability zone. If your network has no subnets, create one:
- To allow external access to the host from outside Yandex Cloud, enable Public access.
To ensure fault tolerance while using
local-ssdandnetwork-ssd-nonreplicateddisks, you need a minimum of 3 hosts. For more information, see Storage.By default, hosts are created in different availability zones. Read more about host management.
-
Under Database, specify the database details:
-
Database name.
A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
Username.
-
User password. The password must be at least 8 characters long.
-
-
Specify additional cluster settings, if required:
-
Backup start time (UTC): Time interval during which the cluster backup starts. Time is specified in 24-hour UTC format. The default time is
22:00 - 23:00UTC. -
Retention period for automatic backups, days
Retention period for automatic backups. Backups are automatically deleted once their retention period expires. The default is 7 days. This feature is at the Preview stage. For more information, see Backups.
Changing the retention period affects both new and existing automatic backups. For example, if the initial retention period was 7 days, and the remaining lifetime of a separate automatic backup is 1 day, increasing the retention period to 9 days will change the remaining lifetime of this backup to 3 days.
For an existing cluster, automatic backups are stored for a specified number of days whereas manually created ones are stored indefinitely. After a cluster is deleted, all backups persist for 7 days.
-
Maintenance window: Maintenance window settings:
- To enable maintenance at any time, select arbitrary (default).
- To specify the preferred maintenance start time, select by schedule and specify the desired day of the week and UTC hour. For example, you can choose a time when the cluster is least loaded.
Maintenance operations are carried out both on enabled and disabled clusters. They may include updating the DBMS, applying patches, and so on.
-
WebSQL access: Enables you to run SQL queries against cluster databases from the Yandex Cloud management console using Yandex WebSQL.
-
Statistics sampling: Enable this option to use the built-in performance diagnostics tool in the cluster. This feature is at the Preview stage.
-
Deletion protection: Cluster protection from accidental deletion.
Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.
-
-
If necessary, configure database settings.
Note
Some Yandex StoreDoc settings depend on the selected host class.
-
Click Create cluster.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To create a Yandex StoreDoc cluster:
-
Verify that your folder has subnets for cluster host placement:
yc vpc subnet listIf your folder contains no subnets, create them in VPC.
-
See the description of the CLI command for creating a cluster:
yc managed-mongodb cluster create --help -
Specify the cluster parameters in the create command (not all parameters are given in the example):
For a non-sharded cluster
yc managed-mongodb cluster create \ --name <cluster_name> \ --environment=<environment> \ --network-name <network_name> \\ --security-group-ids <security_group_IDs> \ --host zone-id=<availability_zone>,` `subnet-id=<subnet_ID>,` `assign-public-ip=<allow_public_access_to_host>,` `hidden=<hide_host>,` `secondary-delay-secs=<replica_lag_in_seconds>,` `priority=<host_priority> \ --mongod-resource-preset <host_class> \ --user name=<username>,password=<user_password> \ --database name=<DB_name> \ --mongod-disk-type <network-hdd|network-ssd|network-ssd-nonreplicated|local-ssd> \ --mongod-disk-size <storage_size_in_GB> \ --disk-encryption-key-id <KMS_key_ID> \ --performance-diagnostics=<enable_diagnostics> \ --deletion-protectionFor a cluster with standard sharding
yc managed-mongodb cluster create \ --name <cluster_name> \ --environment=<environment> \ --mongodb-version <Yandex_StoreDoc_version> \ --network-name <network_name> \ --security-group-ids <security_group_IDs> \ --user name=<username>,password=<user_password> \ --database name=<DB_name> \ --mongod-resource-preset <host_class> \ --mongod-disk-type <network-hdd|network-ssd|network-ssd-nonreplicated|local-ssd> \ --mongod-disk-size <storage_size_in_GB> \ --host type=mongod,` `zone-id=<availability_zone>,` `subnet-id=<subnet_ID>,` `hidden=<hide_host>,` `secondary-delay-secs=<replica_lag_in_seconds>,` `priority=<host_priority> \ --mongoinfra-resource-preset <host_class> \ --mongoinfra-disk-type <network-hdd|network-ssd> \ --mongoinfra-disk-size <storage_size_in_GB> \ --host type=mongoinfra,` `zone-id=<availability_zone>,` `subnet-id=<subnet_ID>,` `assign-public-ip=<allow_public_access_to_host> \ --disk-encryption-key-id <KMS_key_ID> \ --performance-diagnostics=<enable_diagnostics> \ --deletion-protectionFor a cluster with advanced sharding
yc managed-mongodb cluster create \ --name <cluster_name> \ --environment=<environment> \ --mongodb-version <Yandex_StoreDoc_version> \ --network-name <network_name> \ --security-group-ids <security_group_IDs> \ --user name=<username>,password=<user_password> \ --database name=<DB_name> \ --mongod-resource-preset <host_class> \ --mongod-disk-type <network-hdd|network-ssd|network-ssd-nonreplicated|local-ssd> \ --mongod-disk-size <storage_size_in_GB> \ --host type=mongod,` `zone-id=<availability_zone>,` `subnet-id=<subnet_ID>,` `hidden=<hide_host>,` `secondary-delay-secs=<replica_lag_in_seconds>,` `priority=<host_priority> \ --mongos-resource-preset <host_class> \ --mongos-disk-type <network-hdd|network-ssd> \ --mongos-disk-size <storage_size_in_GB> \ --host type=mongos,` `zone-id=<availability_zone>,` `subnet-id=<subnet_ID>,` `assign-public-ip=<allow_public_access_to_host> \ --mongocfg-resource-preset <host_class> \ --mongocfg-disk-type <network-hdd|network-ssd> \ --mongocfg-disk-size <storage_size_in_GB> \ --host type=mongocfg,` `zone-id=<availability_zone>,` `subnet-id=<subnet_ID> \ --disk-encryption-key-id <KMS_key_ID> \ --performance-diagnostics=<enable_diagnostics> \ --deletion-protectionWhere:
-
--environment: Environment,prestableorproduction. -
--security-group-ids: List of security group IDs. -
--database name: Database name.Note
A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
--host: Host settings:-
type: Host type, i.e.,mongod,mongoinfra,mongos, ormongocfg. The default host type ismongod. -
zone-id: Availability zone. -
subnet-id: Subnet ID. To be specified if the selected availability zone has more than one subnet. -
assign-public-ip: Internet access to the host via a public IP address,trueorfalse. In a sharded cluster, it is used only forMONGOSandMONGOINFRAhosts. -
hidden: Hide host,trueorfalse. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster). -
secondary-delay-secs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations. -
priority: Host priority for assignment as a master.Note
The
hidden,secondary-delay-secs, andpriorityparameters are used forMONGODhosts only.
-
-
--mongod-resource-preset:MONGODhost class. -
--mongoinfra-resource-preset,--mongos-resource-preset,--mongocfg-resource-preset:MONGOINFRA,MONGOS, andMONGOCFGhost classes, respectively (for sharded clusters only). -
--mongod-disk-type: Disk type ofMONGODhosts. -
--mongoinfra-disk-type,--mongos-disk-type,--mongocfg-disk-type: Disk types ofMONGOINFRA,MONGOS, andMONGOCFGhosts, respectively (for sharded clusters only). -
--disk-encryption-key-id: Disk encryption with a custom KMS key.To learn more about disk encryption, see Storage.
-
--performance-diagnostics: Enables cluster performance diagnostics,trueorfalse. -
--deletion-protection: Cluster protection from accidental deletion,trueorfalse.Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.
Note
The default maintenance mode for new clusters is
anytime. You can set a specific maintenance period when updating the cluster settings. -
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To create a Yandex StoreDoc cluster:
-
In the configuration file, describe the resources you want to create:
-
Database cluster: Description of the cluster and its hosts.
-
Network: Description of the cloud network where a cluster will be located. If you already have a suitable network, you don't have to describe it again.
-
Subnets: Description of the subnets to connect the cluster hosts to. If you already have suitable subnets, you don't have to describe them again.
Here is an example of the configuration file structure:
For a non-sharded cluster
resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { name = "<cluster_name>" environment = "<environment>" network_id = yandex_vpc_network.<network_name>.id security_group_ids = [ "<list_of_security_group_IDs>" ] deletion_protection = <protect_cluster_from_deletion> cluster_config { version = "<Yandex_StoreDoc_version>" } resources_mongod { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { type = "mongod" zone_id = "<availability_zone>" subnet_id = yandex_vpc_subnet.<subnet_name>.id assign_public_ip = <allow_public_access_to_host> host_parameters { hidden = <hide_host> secondary_delay_secs = <replica_lag_in_seconds> priority = <host_priority> } } resources_mongoinfra { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { type = "mongoinfra" zone_id = "<availability_zone>" subnet_id = yandex_vpc_subnet.<subnet_name>.id assign_public_ip = <allow_public_access_to_host> } } resource "yandex_mdb_mongodb_database" "<DB_name>" { cluster_id = yandex_mdb_mongodb_cluster.<cluster_name>.id name = "<DB_name>" } resource "yandex_mdb_mongodb_user" "<username>" { cluster_id = yandex_mdb_mongodb_cluster.<cluster_name>.id name = "<username>" password = "<password>" permission { database_name = "<DB_name>" roles = [ "<list_of_user_roles>" ] } depends_on = [ yandex_mdb_mongodb_database.<DB_name> ] } resource "yandex_vpc_network" "<network_name>" { name = "<network_name>" } resource "yandex_vpc_subnet" "<subnet_name>" { name = "<subnet_name>" zone = "<availability_zone>" network_id = yandex_vpc_network.<network_name>.id v4_cidr_blocks = ["<range>"] }For a cluster with standard sharding
resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { name = "<cluster_name>" environment = "<environment>" network_id = yandex_vpc_network.<network_name>.id security_group_ids = [ "<list_of_security_group_IDs>" ] deletion_protection = <protect_cluster_against_deletion> cluster_config { version = "<Yandex_StoreDoc_version>" } resources_mongod { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { type = "mongod" zone_id = "<availability_zone>" subnet_id = yandex_vpc_subnet.<subnet_name>.id host_parameters { hidden = <hide_host> secondary_delay_secs = <replica_lag_in_seconds> priority = <host_priority> } } resources_mongoinfra { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { type = "mongoinfra" zone_id = "<availability_zone>" subnet_id = yandex_vpc_subnet.<subnet_name>.id assign_public_ip = <allow_public_access_to_host> } } resource "yandex_mdb_mongodb_database" "<DB_name>" { cluster_id = yandex_mdb_mongodb_cluster.<cluster_name>.id name = "<DB_name>" } resource "yandex_mdb_mongodb_user" "<username>" { cluster_id = yandex_mdb_mongodb_cluster.<cluster_name>.id name = "<username>" password = "<password>" permission { database_name = "<DB_name>" roles = [ "<list_of_user_roles>" ] } depends_on = [ yandex_mdb_mongodb_database.<DB_name> ] } resource "yandex_vpc_network" "<network_name>" { name = "<network_name>" } resource "yandex_vpc_subnet" "<subnet_name>" { name = "<subnet_name>" zone = "<availability_zone>" network_id = yandex_vpc_network.<network_name>.id v4_cidr_blocks = ["<range>"] }For a cluster with advanced sharding
resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { name = "<cluster_name>" environment = "<environment>" network_id = yandex_vpc_network.<network_name>.id security_group_ids = [ "<list_of_security_group_IDs>" ] deletion_protection = <protect_cluster_against_deletion> cluster_config { version = "<Yandex_StoreDoc_version>" } resources_mongod { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { type = "mongod" zone_id = "<availability_zone>" subnet_id = yandex_vpc_subnet.<subnet_name>.id host_parameters { hidden = <hide_host> secondary_delay_secs = <replica_lag_in_seconds> priority = <host_priority> } } resources_mongos { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { type = "mongos" zone_id = "<availability_zone>" subnet_id = yandex_vpc_subnet.<subnet_name>.id assign_public_ip = <allow_public_access_to_host> } resources_mongocfg { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { type = "mongocfg" zone_id = "<availability_zone>" subnet_id = yandex_vpc_subnet.<subnet_name>.id } } resource "yandex_mdb_mongodb_database" "<DB_name>" { cluster_id = yandex_mdb_mongodb_cluster.<cluster_name>.id name = "<DB_name>" } resource "yandex_mdb_mongodb_user" "<username>" { cluster_id = yandex_mdb_mongodb_cluster.<cluster_name>.id name = "<username>" password = "<password>" permission { database_name = "<DB_name>" roles = [ "<list_of_user_roles>" ] } depends_on = [ yandex_mdb_mongodb_database.<DB_name> ] } resource "yandex_vpc_network" "<network_name>" { name = "<network_name>" } resource "yandex_vpc_subnet" "<subnet_name>" { name = "<subnet_name>" zone = "<availability_zone>" network_id = yandex_vpc_network.<network_name>.id v4_cidr_blocks = ["<range>"] }Where:
-
environment: Environment,PRESTABLEorPRODUCTION. -
host: Host settings:zone_id: Availability zone.subnet_id: ID of the subnet in the selected availability zone.assign_public_ip: Public access to the host,trueorfalse. In a sharded cluster, it is used only forMONGOSandMONGOINFRAhosts.host_parameters: Additional host parameters:hidden: Hide host,trueorfalse. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).secondary_delay_secs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.priority: Host priority for assignment as a master.
Note
The
hidden,secondary_delay_secs, andpriorityparameters are used forMONGODhosts only. -
deletion_protection: Cluster protection against accidental deletion,trueorfalse.Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.
-
version: Yandex StoreDoc version, 6.0 or 7.0.
A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names.To set up the maintenance window (for disabled clusters as well), add the
maintenance_windowsection to the cluster description:resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { ... maintenance_window { type = <maintenance_type> day = <day_of_week> hour = <hour> } ... }Where:
type: Maintenance type. The possible values include:ANYTIME: AnytimeWEEKLY: On a schedule
day: Day of week for theWEEKLYtype, i.e.,MON,TUE,WED,THU,FRI,SAT, orSUN.hour: UTC hour for theWEEKLYtype, from1to24.
To encrypt the disk with a custom KMS key, add the
disk_encryption_key_idparameter:resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { ... disk_encryption_key_id = <KMS_key_ID> ... }To learn more about disk encryption, see Storage.
For more information about the resources you can create with Terraform, see this provider guide.
-
-
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Create the cluster.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
This will create all required resources in the specified folder, and you will see the host FQDNs in the terminal. You can verify that the new resources have appeared and check their configuration in the management console
.Timeouts
The Terraform provider sets the following timeouts for Yandex StoreDoc cluster operations:
- Creating a cluster, including by restoring one from a backup: 30 minutes.
- Editing a cluster: 60 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the
timeoutsblock to the cluster description, for example:resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { ... timeouts { create = "1h30m" # An hour and a half update = "2h" # Two hours } } -
-
Get an IAM token for API authentication and place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Create a file named
body.jsonand paste the following code into it:For a non-sharded cluster
{ "folderId": "<folder_ID>", "name": "<cluster_name>", "environment": "<environment>", "networkId": "<network_ID>", "securityGroupIds": [ "<security_group_1_ID>", "<security_group_2_ID>", ... "<security_group_N_ID>" ], "deletionProtection": <protect_cluster_from_deletion>, "maintenanceWindow": { "weeklyMaintenanceWindow": { "day": "<day_of_week>", "hour": "<hour>" } }, "configSpec": { "version": "<Yandex_StoreDoc_version>", "mongodb": { "mongod": { "resources": { "resourcePresetId": "<host_class>", "diskSize": "<storage_size_in_bytes>", "diskTypeId": "<disk_type>" } } }, "backupWindowStart": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" }, "backupRetainPeriodDays": "<backup_retention_in_days>", "performanceDiagnostics": { "profilingEnabled": <enable_profiler> } }, "databaseSpecs": [ { "name": "<DB_name>" }, { <similar_configuration_for_DB_2> }, { ... }, { <similar_configuration_for_DB_N> } ], "userSpecs": [ { "name": "<username>", "password": "<user_password>", "permissions": [ { "databaseName": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] }, { <similar_settings_for_user_2> }, { ... }, { <similar_settings_for_user_N> } ], "hostSpecs": [ { "zoneId": "<availability_zone>", "subnetId": "<subnet_ID>", "assignPublicIp": <allow_public_access_to_host>, "type": "MONGOD", "hidden": <hide_host>, "secondaryDelaySecs": "<replica_lag_in_seconds>", "priority": "<host_priority>", "tags": "<host_labels>" }, { <similar_settings_for_host_2> }, { ... }, { <similar_settings_for_host_N> } ], }For a cluster with standard sharding
{ "folderId": "<folder_ID>", "name": "<cluster_name>", "environment": "<environment>", "networkId": "<network_ID>", "securityGroupIds": [ "<security_group_1_ID>", "<security_group_2_ID>", ... "<security_group_N_ID>" ], "deletionProtection": <protect_cluster_against_deletion>, "maintenanceWindow": { "weeklyMaintenanceWindow": { "day": "<day_of_week>", "hour": "<hour>" } }, "configSpec": { "version": "<Yandex_StoreDoc_version>", "mongodb": { "mongod": { "resources": { "resourcePresetId": "<host_class>", "diskSize": "<storage_size_in_bytes>", "diskTypeId": "<disk_type>" } }, "mongoinfra": { "resources": { "resourcePresetId": "<host_class>", "diskSize": "<storage_size_in_bytes>", "diskTypeId": "<disk_type>" } } }, "backupWindowStart": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" }, "backupRetainPeriodDays": "<backup_retention_in_days>", "performanceDiagnostics": { "profilingEnabled": <enable_profiler> } }, "databaseSpecs": [ { "name": "<DB_name>" }, { <similar_configuration_for_DB_2> }, { ... }, { <similar_configuration_for_DB_N> } ], "userSpecs": [ { "name": "<username>", "password": "<user_password>", "permissions": [ { "databaseName": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] }, { <similar_settings_for_user_2> }, { ... }, { <similar_settings_for_user_N> } ], "hostSpecs": [ { "zoneId": "<availability_zone>", "subnetId": "<subnet_ID>", "type": "MONGOD", "shardName": "<shard_name>", "hidden": <hide_host>, "secondaryDelaySecs": "<replica_lag_in_seconds>", "priority": "<host_priority>", "tags": "<host_labels>" }, { "zoneId": "<availability_zone>", "subnetId": "<subnet_ID>", "type": "MONGOINFRA", "assignPublicIp": <allow_public_access_to_host>, "tags": "<host_labels>" }, { <similar_settings_for_host_3> }, { ... }, { <similar_configuration_for_host_N> } ] }For a cluster with advanced sharding
{ "folderId": "<folder_ID>", "name": "<cluster_name>", "environment": "<environment>", "networkId": "<network_ID>", "securityGroupIds": [ "<security_group_1_ID>", "<security_group_2_ID>", ... "<security_group_N_ID>" ], "deletionProtection": <protect_cluster_against_deletion>, "maintenanceWindow": { "weeklyMaintenanceWindow": { "day": "<day_of_week>", "hour": "<hour>" } }, "configSpec": { "version": "<Yandex_StoreDoc_version>", "mongodb": { "mongod": { "resources": { "resourcePresetId": "<host_class>", "diskSize": "<storage_size_in_bytes>", "diskTypeId": "<disk_type>" } }, "mongos": { "resources": { "resourcePresetId": "<host_class>", "diskSize": "<storage_size_in_bytes>", "diskTypeId": "<disk_type>" } }, "mongocfg": { "resources": { "resourcePresetId": "<host_class>", "diskSize": "<storage_size_in_bytes>", "diskTypeId": "<disk_type>" } } }, "backupWindowStart": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" }, "backupRetainPeriodDays": "<backup_retention_in_days>", "performanceDiagnostics": { "profilingEnabled": <enable_profiler> } }, "databaseSpecs": [ { "name": "<DB_name>" }, { <similar_configuration_for_DB_2> }, { ... }, { <similar_configuration_for_DB_N> } ], "userSpecs": [ { "name": "<username>", "password": "<user_password>", "permissions": [ { "databaseName": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] }, { <similar_settings_for_user_2> }, { ... }, { <similar_settings_for_user_N> } ], "hostSpecs": [ { "zoneId": "<availability_zone>", "subnetId": "<subnet_ID>", "type": "MONGOD", "shardName": "<shard_name>", "hidden": <hide_host>, "secondaryDelaySecs": "<replica_lag_in_seconds>", "priority": "<host_priority>", "tags": "<host_labels>" }, { "zoneId": "<availability_zone>", "subnetId": "<subnet_ID>", "type": "MONGOS", "assignPublicIp": <allow_public_access_to_host>, "tags": "<host_labels>" }, { "zoneId": "<availability_zone>", "subnetId": "<subnet_ID>", "type": "MONGOCFG", "tags": "<host_labels>" }, { <similar_settings_for_host_4> }, { ... }, { <similar_configuration_for_host_N> } ] }Where:
-
folderId: Folder ID. You can get it from the list of your cloud folders. -
name: Cluster name. -
environment: Cluster environment,PRODUCTIONorPRESTABLE. -
networkId: ID of the network where your cluster will be deployed. -
securityGroupIds: Security group IDs. -
deletionProtection: Cluster deletion protection,trueorfalse.Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.
-
maintenanceWindow: Maintenance window settings, applying to both running and stopped clusters. InmaintenanceWindow, provide one of the following values:-
anytime: Maintenance can occur at any time. -
weeklyMaintenanceWindow: Maintenance occurs once a week at the specified time:day: Day of the week, inDDDformat.hour: Hour of the day, inHHformat. Allowed values range from1to24hours.
-
-
configSpec: Cluster settings:-
version: Yandex StoreDoc version, 5.0, 6.0, or 7.0. -
mongod: Host type.-
resources: Cluster resources:resourcePresetId: Host class.diskSize: Disk size in bytes.diskTypeId: Disk type.
-
-
backupWindowStart: Backup window settings.Here, specify the backup start time:
hours: Between0and23hours.minutes: Between0and59minutes.seconds: Between0and59seconds.nanos: Between0and999999999nanoseconds.
-
backupRetainPeriodDays: Backup retention time in days. -
performanceDiagnostics: Statistics collection settings:profilingEnabled: Enable profiler,trueorfalse.
-
-
databaseSpecs: Database settings as an array of elements, one per database. Each element contains a databasename.A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
userSpecs: User settings as an array of elements, one per user. Each element has the following structure:-
name: Username. -
password: Password. -
permissions: User permissions:databaseName: Name of the database the user can access.roles: User roles as an array of strings, one per role. Possible values are listed in Users and roles.
In the
permissionsarray, add a separate element with permission settings for each database.
-
-
hostSpecs: Cluster host settings as an array of elements, one per host. Each element has the following structure:* `zoneId`: [Availability zone](../../overview/concepts/geo-scope.md).subnetId: Subnet ID.assignPublicIp: Internet access to the host via a public IP address,trueorfalse. In a sharded cluster, it is used only forMONGOSandMONGOINFRAhosts.type: Host type in a sharded cluster,MONGOD,MONGOINFRA,MONGOS, orMONGOCFG.tags: Host labels.shard_name: Shard name in a sharded cluster (forMONGODhosts only).hidden: Hide host,trueorfalse. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).secondaryDelaySecs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.priority: Host priority for assignment as a master.
Note
The
shardName,hidden,secondaryDelaySecs, andpriorityparameters are used forMONGODhosts only.
-
-
Call the Cluster.Create method, e.g., via the following cURL
request:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters' \ --data "@body.json" -
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Create a file named
body.jsonand paste the following code into it:For a non-sharded cluster
{ "folder_id": "<folder_ID>", "name": "<cluster_name>", "environment": "<environment>", "network_id": "<network_ID>", "security_group_ids": [ "<security_group_1_ID>", "<security_group_2_ID>", ... "<security_group_N_ID>" ], "deletion_protection": <protect_cluster_from_deletion>, "maintenance_window": { "weekly_maintenance_window": { "day": "<day_of_week>", "hour": "<hour>" } }, "config_spec": { "version": "<Yandex_StoreDoc_version>", "mongodb": { "mongod": { "resources": { "resource_preset_id": "<host_class>", "disk_size": "<storage_size_in_bytes>", "disk_type_id": "<disk_type>" } } }, "backup_window_start": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" }, "backup_retain_period_days": "<backup_retention_in_days>", "performance_diagnostics": { "profiling_enabled": <enable_profiler> } }, "database_specs": [ { "name": "<DB_name>" }, { <similar_configuration_for_DB_2> }, { ... }, { <similar_configuration_for_DB_N> } ], "user_specs": [ { "name": "<username>", "password": "<user_password>", "permissions": [ { "database_name": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] }, { <similar_settings_for_user_2> }, { ... }, { <similar_settings_for_user_N> } ], "host_specs": [ { "zone_id": "<availability_zone>", "subnet_id": "<subnet_ID>", "assign_public_ip": <allow_public_access_to_host>, "type": "MONGOD", "hidden": <hide_host>, "secondary_delay_secs": "<replica_lag_in_seconds>", "priority": "<host_priority>", "tags": "<host_labels>" }, { <similar_settings_for_host_2> }, { ... }, { <similar_settings_for_host_N> } ] }For a cluster with standard sharding
{ "folder_id": "<folder_ID>", "name": "<cluster_name>", "environment": "<environment>", "network_id": "<network_ID>", "security_group_ids": [ "<security_group_1_ID>", "<security_group_2_ID>", ... "<security_group_N_ID>" ], "deletion_protection": <protect_cluster_against_deletion>, "maintenance_window": { "weekly_maintenance_window": { "day": "<day_of_week>", "hour": "<hour>" } }, "config_spec": { "version": "<Yandex_StoreDoc_version>", "mongodb": { "mongod": { "resources": { "resource_preset_id": "<host_class>", "disk_size": "<storage_size_in_bytes>", "disk_type_id": "<disk_type>" } }, "mongoinfra": { "resources": { "resource_preset_id": "<host_class>", "disk_size": "<storage_size_in_bytes>", "disk_type_id": "<disk_type>" } } }, "backup_window_start": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" }, "backup_retain_period_days": "<backup_retention_in_days>", "performance_diagnostics": { "profiling_enabled": <enable_profiler> } }, "database_specs": [ { "name": "<DB_name>" }, { <similar_configuration_for_DB_2> }, { ... }, { <similar_configuration_for_DB_N> } ], "user_specs": [ { "name": "<username>", "password": "<user_password>", "permissions": [ { "database_name": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] }, { <similar_settings_for_user_2> }, { ... }, { <similar_settings_for_user_N> } ], "host_specs": [ { "zone_id": "<availability_zone>", "subnet_id": "<subnet_ID>", "type": "MONGOD", "shard_name": "<shard_name>", "hidden": <hide_host>, "secondary_delay_secs": "<replica_lag_in_seconds>", "priority": "<host_priority>", "tags": "<host_labels>" }, { "zone_id": "<availability_zone>", "subnet_id": "<subnet_ID>", "type": "MONGOINFRA", "assign_public_ip": <allow_public_access_to_host>, "tags": "<host_labels>" }, { <similar_settings_for_host_3> }, { ... }, { <similar_configuration_for_host_N> } ] }For a cluster with advanced sharding
{ "folder_id": "<folder_ID>", "name": "<cluster_name>", "environment": "<environment>", "network_id": "<network_ID>", "security_group_ids": [ "<security_group_1_ID>", "<security_group_2_ID>", ... "<security_group_N_ID>" ], "deletion_protection": <protect_cluster_against_deletion>, "maintenance_window": { "weekly_maintenance_window": { "day": "<day_of_week>", "hour": "<hour>" } }, "config_spec": { "version": "<Yandex_StoreDoc_version>", "mongodb": { "mongod": { "resources": { "resource_preset_id": "<host_class>", "disk_size": "<storage_size_in_bytes>", "disk_type_id": "<disk_type>" } }, "mongos": { "resources": { "resource_preset_id": "<host_class>", "disk_size": "<storage_size_in_bytes>", "disk_type_id": "<disk_type>" } }, "mongocfg": { "resources": { "resource_preset_id": "<host_class>", "disk_size": "<storage_size_in_bytes>", "disk_type_id": "<disk_type>" } } }, "backup_window_start": { "hours": "<hours>", "minutes": "<minutes>", "seconds": "<seconds>", "nanos": "<nanoseconds>" }, "backup_retain_period_days": "<backup_retention_in_days>", "performance_diagnostics": { "profiling_enabled": <enable_profiler> } }, "database_specs": [ { "name": "<DB_name>" }, { <similar_configuration_for_DB_2> }, { ... }, { <similar_configuration_for_DB_N> } ], "user_specs": [ { "name": "<username>", "password": "<user_password>", "permissions": [ { "database_name": "<DB_name>", "roles": [ "<role_1>", "<role_2>", ..., "<role_N>" ] } ] }, { <similar_settings_for_user_2> }, { ... }, { <similar_settings_for_user_N> } ], "host_specs": [ { "zone_id": "<availability_zone>", "subnet_id": "<subnet_ID>", "type": "MONGOD", "shard_name": "<shard_name>", "hidden": <hide_host>, "secondary_delay_secs": "<replica_lag_in_seconds>", "priority": "<host_priority>", "tags": "<host_labels>" }, { "zone_id": "<availability_zone>", "subnet_id": "<subnet_ID>", "type": "MONGOS", "assign_public_ip": <allow_public_access_to_host>, "tags": "<host_labels>" }, { "zone_id": "<availability_zone>", "subnet_id": "<subnet_ID>", "type": "MONGOCFG", "tags": "<host_labels>" }, { <similar_settings_for_host_4> }, { ... }, { <similar_configuration_for_host_N> } ] }Where:
-
folder_id: Folder ID. You can get it from the list of your cloud folders. -
name: Cluster name. -
environment: Cluster environment,PRODUCTIONorPRESTABLE. -
network_id: ID of the network where your cluster will be deployed. -
security_group_ids: Security group IDs. -
deletion_protection: Cluster deletion protection,trueorfalse.Even with cluster deletion protection enabled, one can still delete a user or database or connect manually and delete the database contents.
-
maintenance_window: Maintenance window settings, applying to both running and stopped clusters. Inmaintenance_window, provide one of the following values:-
anytime: Maintenance can occur at any time. -
weekly_maintenance_window: Maintenance occurs once a week at the specified time:day: Day of the week, inDDDformat.hour: Hour of the day, inHHformat. Allowed values range from1to24hours.
-
-
config_spec: Cluster settings:version: Yandex StoreDoc version, 5.0, 6.0, or 7.0.-
mongod,mongoinfra,mongos,mongocfg: Host types.-
resources: Cluster resources:resource_preset_id: Host class.disk_size: Disk size, in bytes.disk_type_id: Disk type.
-
-
backup_window_start: Backup window settings.Here, specify the backup start time:
hours: Between0and23hours.minutes: Between0and59minutes.seconds: Between0and59seconds.nanos: Between0and999999999nanoseconds.
-
backup_retain_period_days: Backup retention time in days. -
performance_diagnostics: Statistics collection settings:profiling_enabled: Enable the profiler,trueorfalse.
-
-
database_specs: Database settings as an array of elements, one per database. Each element contains a databasename.A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
user_specs: User settings as an array of elements, one per user. Each element has the following structure:-
name: Username. -
password: Password. -
permissions: User permissions:database_name: Name of the database the user can access.roles: User roles as an array of strings, one per role. Possible values are listed in Users and roles.
In the
permissionsarray, add a separate element with permission settings for each database.
-
-
host_specs: Cluster host settings as an array of elements, one per host. Each element has the following structure:* `zone_id`: [Availability zone](../../overview/concepts/geo-scope.md).subnet_id: Subnet ID.assign_public_ip: Internet access to the host via a public IP address,trueorfalse. In a sharded cluster, it is used only forMONGOSandMONGOINFRAhosts.type: Host type in a sharded cluster,MONGOD,MONGOINFRA,MONGOS, orMONGOCFG.tags: Host labels.shard_name: Shard name in a sharded cluster.hidden: Hide host,trueorfalse. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).secondaryDelaySecs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.priority: Host priority for assignment as a master.
Note
The
shard_name,hidden,secondaryDelaySecs, andpriorityparameters are used forMONGODhosts only.
-
-
Call the ClusterService.Create method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.ClusterService.Create \ < body.json -
Check the server response to make sure your request was successful.
Warning
If you specified security group IDs when creating a cluster, you may need to configure these security groups to enable cluster access.
Creating a cluster copy
You can create a new Yandex StoreDoc cluster based on the configuration of an existing one by importing the source Yandex StoreDoc cluster configuration into Terraform. This lets you either create an exact replica or use the imported configuration as a baseline for customization. Using import is convenient when you need to replicate a Yandex StoreDoc cluster with multiple settings.
To create a Yandex StoreDoc cluster copy:
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
In your current working directory, create a
.tffile with the following contents:resource "yandex_mdb_mongodb_cluster" "old" { } -
Save the ID of the original Yandex StoreDoc cluster to an environment variable:
export STOREDOC_CLUSTER_ID=<cluster_ID>You can get the cluster ID from the list of clusters in your folder.
-
Import the original Yandex StoreDoc cluster configuration into Terraform:
terraform import yandex_mdb_mongodb_cluster.old ${STOREDOC_CLUSTER_ID} -
Get the imported configuration:
terraform show -
Copy it from the terminal and paste it into the
.tffile. -
Move the file to the new
imported-clusterdirectory. -
Modify the copied configuration to prepare it for creating a new cluster:
- Specify the new cluster name in the
resourcestring and in thenameargument. - Delete the
created_at,health,id,sharded, andstatusarguments. - In the
hostsections, delete thehealthandnamearguments. - If the
maintenance_windowsection containstype = "ANYTIME", delete thehourargument. - Delete all
usersections. Useyandex_mdb_mongodb_userresource to add database users. - Optionally, you can customize the configuration further as needed.
- Specify the new cluster name in the
-
Navigate to the
imported-clusterdirectory and get the authentication credentials. -
In the same directory, configure and initialize the provider. Instead of manually creating the provider configuration file, you can download it
. -
Move the configuration file to the
imported-clusterdirectory and specify its settings. If you have not set the authentication credentials as environment variables, specify them in the configuration file. -
Validate your Terraform configuration:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
Timeouts
The Terraform provider sets the following timeouts for Yandex StoreDoc cluster operations:
- Creating a cluster, including by restoring one from a backup: 30 minutes.
- Editing a cluster: 60 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts block to the cluster description, for example:
resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # An hour and a half
update = "2h" # Two hours
}
}
Examples
Creating a single-host cluster
Create a Yandex StoreDoc cluster with the following test specifications:
- Name:
mymg. - Environment:
production. - Network:
default. - Security group ID:
enp6saqnq4ie244g67sb. s2.microhost in theb0rcctk2rvtr********subnet and theru-central1-aavailability zone.- Network SSD storage (
network-ssd): 20 GB. - Username:
user1, password:user1user1. - Database:
db1. - Deletion protection: Enabled.
Run this command:
yc managed-mongodb cluster create \
--name mymg \
--environment production \
--network-name default \
--security-group-ids enp6saqnq4ie244g67sb \
--mongod-resource-preset s2.micro \
--host zone-id=ru-central1-a,subnet-id=b0rcctk2rvtr******** \
--mongod-disk-size 20 \
--mongod-disk-type network-ssd \
--user name=user1,password=user1user1 \
--database name=db1 \
--deletion-protection
Create a Yandex StoreDoc cluster and its supporting network, using the following test specifications:
-
Name:
mymg. -
Version:
7.0. -
Environment:
PRODUCTION. -
Cloud ID:
b1gq90dgh25bebiu75o. -
Folder ID:
b1gia87mbaomkfvsleds. -
Network:
mynet. -
Host class:
s2.micro. -
Number of
hostblocks: 1. -
Subnet:
mysubnet. Network settings:- Availability zone:
ru-central1-a. - Range:
10.5.0.0/24.
- Availability zone:
-
Security group:
mymg-sg. Rules in this security group must allow incoming public TCP connections on port27018. -
Network SSD storage:
network-ssd. -
Storage size: 20 GB.
-
Username:
user1. -
Password:
user1user1. -
Database:
db1. -
Deletion protection: Enabled.
Configuration file for a single-host cluster:
resource "yandex_mdb_mongodb_cluster" "mymg" {
name = "mymg"
environment = "PRODUCTION"
network_id = yandex_vpc_network.mynet.id
security_group_ids = [ yandex_vpc_security_group.mymg-sg.id ]
deletion_protection = true
cluster_config {
version = "7.0"
}
resources_mongod {
resource_preset_id = "s2.micro"
disk_type_id = "network-ssd"
disk_size = 20
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
}
}
resource "yandex_mdb_mongodb_database" "db1" {
cluster_id = yandex_mdb_mongodb_cluster.mymg.id
name = "db1"
}
resource "yandex_mdb_mongodb_user" "user1" {
cluster_id = yandex_mdb_mongodb_cluster.mymg.id
name = "user1"
password = "user1user1"
permission {
database_name = "db1"
}
depends_on = [
yandex_mdb_mongodb_database.db1
]
}
resource "yandex_vpc_network" "mynet" {
name = "mynet"
}
resource "yandex_vpc_security_group" "mymg-sg" {
name = "mymg-sg"
network_id = yandex_vpc_network.mynet.id
ingress {
description = "Yandex StoreDoc"
port = 27018
protocol = "TCP"
v4_cidr_blocks = [ "0.0.0.0/0" ]
}
}
resource "yandex_vpc_subnet" "mysubnet" {
name = "mysubnet"
zone = "ru-central1-a"
network_id = yandex_vpc_network.mynet.id
v4_cidr_blocks = ["10.5.0.0/24"]
}
Creating a sharded cluster
You can create Yandex StoreDoc clusters with standard or advanced sharding. To learn more about sharding types, see Sharding management.
Standard sharding
Create a multi-host Yandex StoreDoc cluster along with its supporting network:
- One
MONGODhost. - Three
MONGOINFRAhosts.
Cluster test specifications:
- Name:
mymg. - Environment:
PRODUCTION. - Deletion protection: Enabled.
- Version:
7.0. - Database:
db1. - Username:
user1. - Password:
user1user1. MONGODhost class:s2.micro.MONGOINFRAhost class:c3-c2-m4.- Network SSD storage:
network-ssd. - Storage size: 10 GB.
Network specifications:
-
Availability zone:
ru-central1-a. -
Network:
mynet. -
Security group:
mymg-sgwithenp6saqnq4ie244g67sbID. In Terraform, a group is created with the rule allowing TCP connections to the cluster from the internet on port27018. -
Subnet:
mysubnet. -
Range:
10.5.0.0/24(only for Terraform).
To create a Yandex StoreDoc cluster with standard sharding, run this command:
yc managed-mongodb cluster create \
--name mymg \
--environment production \
--deletion-protection \
--mongodb-version 7.0 \
--database name=db1 \
--user name=user1,password=user1user1 \
--mongod-resource-preset s2.micro \
--mongod-disk-type network-ssd \
--mongod-disk-size 10 \
--host type=mongod,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--mongoinfra-resource-preset c3-c2-m4 \
--mongoinfra-disk-type network-ssd \
--mongoinfra-disk-size 10 \
--host type=mongoinfra,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--host type=mongoinfra,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--host type=mongoinfra,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--network-name mynet \
--security-group-ids enp6saqnq4ie244g67sb
The configuration file for a cluster with standard sharding is as follows:
resource "yandex_mdb_mongodb_cluster" "mymg" {
name = "mymg"
environment = "PRODUCTION"
network_id = yandex_vpc_network.mynet.id
security_group_ids = [ yandex_vpc_security_group.mymg-sg.id ]
deletion_protection = true
cluster_config {
version = "7.0"
}
resources_mongod {
resource_preset_id = "s2.micro"
disk_type_id = "network-ssd"
disk_size = 10
}
resources_mongoinfra {
resource_preset_id = "c3-c2-m4"
disk_type_id = "network-ssd"
disk_size = 10
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongod"
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongoinfra"
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongoinfra"
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongoinfra"
}
}
resource "yandex_mdb_mongodb_database" "db1" {
cluster_id = yandex_mdb_mongodb_cluster.mymg.id
name = "db1"
}
resource "yandex_mdb_mongodb_user" "user1" {
cluster_id = yandex_mdb_mongodb_cluster.mymg.id
name = "user1"
password = "user1user1"
permission {
database_name = "db1"
}
depends_on = [
yandex_mdb_mongodb_database.db1
]
}
resource "yandex_vpc_network" "mynet" {
name = "mynet"
}
resource "yandex_vpc_security_group" "mymg-sg" {
name = "mymg-sg"
network_id = yandex_vpc_network.mynet.id
ingress {
description = "Yandex StoreDoc"
port = 27018
protocol = "TCP"
v4_cidr_blocks = [ "0.0.0.0/0" ]
}
}
resource "yandex_vpc_subnet" "mysubnet" {
name = "mysubnet"
zone = "ru-central1-a"
network_id = yandex_vpc_network.mynet.id
v4_cidr_blocks = ["10.5.0.0/24"]
}
Advanced sharding
Create a multi-host Yandex StoreDoc cluster along with its supporting network:
- One
MONGODhost. - Two
MONGOShosts. - Three
MONGOCFGhosts.
Cluster test specifications:
- Name:
mymg. - Environment:
PRODUCTION. - Deletion protection: Enabled.
- Version:
7.0. - Database:
db1. - Username:
user1. - Password:
user1user1. - Host class:
s2.micro. - Network SSD storage:
network-ssd. - Storage size: 10 GB.
Network specifications:
-
Availability zone:
ru-central1-a. -
Network:
mynet. -
Security group:
mymg-sgwithenp6saqnq4ie244g67sbID. Terraform creates a group containing a rule allowing incoming public TCP connections on port27018. -
Subnet:
mysubnet. -
Range:
10.5.0.0/24(only for Terraform).
To create a Yandex StoreDoc cluster with advanced sharding, run this command:
yc managed-mongodb cluster create \
--name mymg \
--environment production \
--deletion-protection \
--mongodb-version 7.0 \
--database name=db1 \
--user name=user1,password=user1user1 \
--mongod-resource-preset s2.micro \
--mongod-disk-type network-ssd \
--mongod-disk-size 10 \
--host type=mongod,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--mongos-resource-preset s2.micro \
--mongos-disk-type network-ssd \
--mongos-disk-size 10 \
--host type=mongos,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--host type=mongos,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--mongocfg-resource-preset s2.micro \
--mongocfg-disk-type network-ssd \
--mongocfg-disk-size 10 \
--host type=mongocfg,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--host type=mongocfg,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--host type=mongocfg,`
`zone-id=ru-central1-a,`
`subnet-name=mysubnet \
--network-name mynet \
--security-group-ids enp6saqnq4ie244g67sb
The configuration file for a cluster with advanced sharding is as follows:
resource "yandex_mdb_mongodb_cluster" "mymg" {
name = "mymg"
environment = "PRODUCTION"
network_id = yandex_vpc_network.mynet.id
security_group_ids = [ yandex_vpc_security_group.mymg-sg.id ]
deletion_protection = true
cluster_config {
version = "7.0"
}
resources_mongod {
resource_preset_id = "s2.micro"
disk_type_id = "network-ssd"
disk_size = 10
}
resources_mongos {
resource_preset_id = "s2.micro"
disk_type_id = "network-ssd"
disk_size = 10
}
resources_mongocfg {
resource_preset_id = "s2.micro"
disk_type_id = "network-ssd"
disk_size = 10
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongod"
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongos"
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongos"
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongocfg"
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongocfg"
}
host {
zone_id = "ru-central1-a"
subnet_id = yandex_vpc_subnet.mysubnet.id
type = "mongocfg"
}
}
resource "yandex_mdb_mongodb_database" "db1" {
cluster_id = yandex_mdb_mongodb_cluster.mymg.id
name = "db1"
}
resource "yandex_mdb_mongodb_user" "user1" {
cluster_id = yandex_mdb_mongodb_cluster.mymg.id
name = "user1"
password = "user1user1"
permission {
database_name = "db1"
}
depends_on = [
yandex_mdb_mongodb_database.db1
]
}
resource "yandex_vpc_network" "mynet" {
name = "mynet"
}
resource "yandex_vpc_security_group" "mymg-sg" {
name = "mymg-sg"
network_id = yandex_vpc_network.mynet.id
ingress {
description = "Yandex StoreDoc"
port = 27018
protocol = "TCP"
v4_cidr_blocks = [ "0.0.0.0/0" ]
}
}
resource "yandex_vpc_subnet" "mysubnet" {
name = "mysubnet"
zone = "ru-central1-a"
network_id = yandex_vpc_network.mynet.id
v4_cidr_blocks = ["10.5.0.0/24"]
}