Creating a MongoDB cluster
A MongoDB cluster is one or more database hosts across which you can configure replication. Replication is enabled by default in any cluster consisting of more than one host, where the primary host accepts write requests and asynchronously replicates the changes in the secondary hosts.
Note
- The number of hosts you can create together with a MongoDB cluster depends on the selected disk type and host class.
- Available disk types depend on the selected host class.
Creating a cluster
To create a Managed Service for MongoDB cluster, you need the vpc.user role and the managed-mongodb.editor role or higher. For information on assigning roles, see the Identity and Access Management documentation.
To create a Managed Service for MongoDB cluster:
-
In the management console
, select the folder where you want to create a DB cluster. -
Select Managed Service for MongoDB.
-
Click Create cluster.
-
Under Basic parameters:
-
Enter a name in the Cluster name field. The cluster name must be unique within the cloud.
-
(Optional) Enter a cluster Description.
-
Select the environment where you want to create the cluster (you cannot change the environment once the cluster is created):
PRODUCTION
: For stable versions of your apps.PRESTABLE
: For testing purposes. The prestable environment is similar to the production environment and likewise covered by the SLA, but it is the first to get new features, improvements, and bug fixes. In the prestable environment, you can test compatibility of new versions with your application.
-
Specify the DBMS version.
-
-
Under Host class, select:
- One of the available platforms.
- Configuration type: memory-optimized, cpu-optimized, standard, or burstable.
- Host class: Defines the technical specifications of the VMs where the DB hosts will be deployed. When you change the host class for the cluster, the characteristics of all existing hosts change, too.
-
Under Size of storage:
-
Select the disk type.
Warning
You cannot change disk type after you create a cluster.
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 SSD storage: In increments of 93 GB.
-
Select the storage size to be used for data and backups. For more information on how backups consume storage space, see Backups.
-
-
Under Database, specify the DB attributes:
-
DB 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_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names. -
Username.
-
User password. The password must be at least 8 characters long.
-
-
Under Network settings, select:
- Cloud network for the cluster.
- Security groups for the cluster network traffic. You may also need to set up security groups to connect to the cluster.
-
Under Hosts, add the DB hosts created with the cluster:
- Click Add host.
- Select an availability zone.
- Select a subnet in the specified availability zone. If there is no subnet, create one.
- If the host must be available outside Yandex Cloud, enable Public access. You cannot change this setting after you create a host.
To ensure fault tolerance, you need at least 3 hosts for
local-ssd
andnetwork-ssd-nonreplicated
disk types. For more information, see Storage.By default, hosts are created in different availability zones. Read more about host management.
-
Configure 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:00
UTC. -
Retention period for automatic backups, days
Retention period for automatic backups. If an automatic backup expires, it is deleted. The default is 7 days. This feature is at the Preview stage. For more information, see Backups.
Changing the retention period affects both new automatic backups and existing backups. For example, if the original retention period was 7 days and the remaining lifetime of a separate automatic backup is 1 day, then when the retention period increases to 9 days, the remaining lifetime of this backup becomes 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.
-
Statistics sampling: Enable this option to use the Performance diagnostics in Managed Service for MongoDB tool in the cluster. This feature is at the Preview stage.
-
Deletion protection: Manages protection of the cluster, its databases, and users against accidental deletion.
Enabled deletion protection will not prevent a manual connection with the purpose to delete database contents.
-
-
Configure the DBMS settings, if required.
Note
Some MongoDB settings depend on the selected host class.
-
Click Create cluster.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To create a Managed Service for MongoDB cluster:
-
Check whether the folder has any subnets for the cluster hosts:
yc vpc subnet list
If there are no subnets in the folder, create the required subnets in VPC.
-
View a description of the create cluster CLI command:
yc managed-mongodb cluster create --help
-
Specify the cluster parameters in the create command (the example below does not list all possible parameters):
yc managed-mongodb cluster create \ --name <cluster_name> \ --environment=<environment> \ --network-name <network_name> \ --host zone-id=<availability_zone>,` `subnet-id=<subnet_ID>,` `assign-public-ip=<public_access> \ --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> \ --performance-diagnostics=<enable_diagnostics> \ --deletion-protection=<deletion_protection>
You need to specify the
subnet-id
if the selected availability zone has two or more subnets.Where:
-
--environment
: Environment,prestable
orproduction
. -
--host
: Host parameters:zone-id
: Availability zone.subnet-id
: Subnet ID. Specify if two or more subnets are created in the selected availability zone.assign-public-ip
: Internet access to the host via a public IP address,true
orfalse
.
-
--mongod-disk-type
: Disk type.Warning
You cannot change disk type after you create a cluster.
-
--performance-diagnostics
: Enables cluster performance diagnostics,true
orfalse
. -
--deletion-protection
: Cluster deletion protection,true
orfalse
.
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_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names.Enabled deletion protection will not prevent a manual connection with the purpose to delete database contents.
Note
When creating a cluster, the
anytime
maintenance mode is set by default. You can set a specific maintenance period when updating the cluster settings. -
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To create a Managed Service for MongoDB cluster:
-
In the configuration file, describe the parameters of 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:
resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { name = "<cluster_name>" environment = "<environment>" network_id = "<network_ID>" security_group_ids = [ "<list_of_security_group_IDs>" ] deletion_protection = <cluster_deletion_protection> cluster_config { version = "<MongoDB_version>" } resources_mongod { resource_preset_id = "<host_class>" disk_type_id = "<disk_type>" disk_size = <storage_size_in_GB> } host { zone_id = "<availability_zone>" subnet_id = "<subnet_ID>" assign_public_ip = <public_access> } } resource "yandex_mdb_mongodb_database" "<DB_name>" { cluster_id = "<cluster_ID>" name = "<DB_name>" } resource "yandex_mdb_mongodb_user" "<username>" { cluster_id = <cluster_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 = "<network_ID>" v4_cidr_blocks = ["<range>"] }
Where:
-
environment
: Environment,PRESTABLE
orPRODUCTION
. -
host
: Host parameters:zone_id
: Availability zone.subnet_id
: ID of a subnet in the selected availability zone.assign_public_ip
: Public access to the host,true
orfalse
.
-
deletion_protection
: Cluster deletion protection,true
orfalse
. -
version
: MongoDB version, 5.0, 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_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names.Enabled deletion protection will not prevent a manual connection with the purpose to delete database contents.
To set up the maintenance window (for disabled clusters as well), add the
maintenance_window
block 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
: Anytime.weekly
: By schedule.
day
: Day of the week for theweekly
type inDDD
format, e.g.,MON
.hour
: Hour of the day for theweekly
type in theHH
format, e.g.,21
.
For more information about the resources you can create with Terraform, see the provider documentation
. -
-
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Create a cluster.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
After this, all required resources will be created in the specified folder, and the host FQDNs will be displayed in the terminal. You can check the new resources and their configuration using the management console
.Timeouts
The Terraform provider sets the following timeouts for Managed Service for MongoDB 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 } }
-
To create a Managed Service for MongoDB cluster, use the create REST API method for the Cluster resource or the ClusterService/Create gRPC API call and provide the following in the request:
-
ID of the folder to host the cluster, in the
folderId
parameter. -
Cluster name in the
name
parameter. -
Cluster environment in the
environment
parameter. -
Network ID in the
networkId
parameter. -
Cluster configuration in the
configSpec
parameter. -
Configuration of the cluster hosts in one or more
hostSpecs
parameters. -
Security group IDs in the
securityGroupIds
parameter. -
Database configuration in one or more
databaseSpecs
parameters.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_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names. -
User settings in one or more
userSpecs
parameters. -
Cluster deletion protection settings in the
deletionProtection
parameter.Cluster deletion protection will not prevent a manual connection to a cluster to delete data.
Warning
If you specified security group IDs when creating a cluster, you may also need to additionally configure security groups to connect to the cluster.
Creating a cluster copy
You can create a MongoDB cluster with the settings of another one you previously created. To do so, you need to import the configuration of the source MongoDB cluster to Terraform. This way, you can either create an identical copy or use the imported configuration as the baseline and modify it as needed. Importing a configuration is a good idea when the source MongoDB cluster has a lot of settings and you need to create a similar one.
To create a MongoDB 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 the same working directory, place a
.tf
file with the following contents:resource "yandex_mdb_mongodb_cluster" "old" { }
-
Write the ID of the initial MongoDB cluster to the environment variable:
export MONGODB_CLUSTER_ID=<cluster_ID>
You can request the ID with a list of clusters in the folder.
-
Import the settings of the initial MongoDB cluster into the Terraform configuration:
terraform import yandex_mdb_mongodb_cluster.old ${MONGODB_CLUSTER_ID}
-
Get the imported configuration:
terraform show
-
Copy it from the terminal and paste it into the
.tf
file. -
Place the file in the new
imported-cluster
directory. -
Modify the copied configuration so that you can create a new cluster from it:
- Specify the new cluster name in the
resource
string and thename
parameter. - Delete
created_at
,health
,id
,sharded
, andstatus
. - In the
host
sections, deletehealth
andname
. - If the
maintenance_window
section hastype = "ANYTIME"
, delete thehour
parameter. - Delete all
user
sections (if any). You can add database users using the separateyandex_mdb_mongodb_user
resource. - Optionally, make further changes if you need to customize the configuration.
- Specify the new cluster name in the
-
Get the authentication credentials in the
imported-cluster
directory. -
In the same directory, 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 the
imported-cluster
directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file. -
Check that the Terraform configuration files are correct:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of 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 Managed Service for MongoDB 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
To create a cluster with a single host, provide a single --host
parameter.
Create a Managed Service for MongoDB cluster with the following test specifications:
- Name:
mymg
- Environment:
production
- Network:
default
- Security group ID:
enp6saqnq4ie244g67sb
- Host:
s2.micro
, subnet:b0rcctk2rvtr********
, availability zone:ru-central1-a
- Network SSD storage (
network-ssd
): 20 GB - User:
user1
, password:user1user1
- Database:
db1
- Protection against accidental cluster deletion: Enabled
Run the following 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=true
Create a Managed Service for MongoDB cluster and a network for it with 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
host
blocks: One. -
Subnet:
mysubnet
. Network settings:- Availability zone:
ru-central1-a
. - Range:
10.5.0.0/24
.
- Availability zone:
-
Security group:
mymg-sg
. The group rules allow TCP connections to the cluster from the internet via port27018
. -
Network SSD storage:
network-ssd
. -
Storage size: 20 GB.
-
User:
user1
. -
Password:
user1user1
. -
Database:
db1
. -
Protection against accidental cluster deletion: 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 = "MongoDB"
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 sharded clusters
You can create Managed Service for MongoDB clusters with standard or advanced sharding. For more information about sharding types, see Sharding management.
Standard sharding
Create a Managed Service for MongoDB cluster and a network for it with multiple hosts:
- One
MONGOD
host - Three
MONGOINFRA
hosts
Cluster test specifications:
- Name:
mymg
. - Environment:
PRODUCTION
. - Protection against accidental cluster deletion: Enabled.
- Version:
7.0
. - Database:
db1
. - User:
user1
. - Password:
user1user1
. MONGOD
host class:s2.micro
.MONGOINFRA
host class:c3-c2-m4
.- Network SSD storage:
network-ssd
. - Storage size: 10 GB.
Network specifications:
-
Network:
mynet
. -
Security group:
mymg-sg
withenp6saqnq4ie244g67sb
ID. In Terraform, a group is created with the rule allowing TCP connections to the cluster from the internet on port27018
. -
Subnet:
mysubnet
. -
Availability zone:
ru-central1-a
. -
Range:
10.5.0.0/24
(only for Terraform).
To create a Managed Service for MongoDB cluster with standard sharding, run this command:
yc managed-mongodb cluster create \
--name mymg \
--environment production \
--deletion-protection=true \
--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 = "MongoDB"
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 Managed Service for MongoDB cluster and a network for it with multiple hosts:
- One
MONGOD
host - Two
MONGOS
hosts - Three
MONGOCFG
hosts
Cluster test specifications:
- Name:
mymg
. - Environment:
PRODUCTION
. - Protection against accidental cluster deletion: Enabled.
- Version:
7.0
. - Database:
db1
. - User:
user1
. - Password:
user1user1
. - Host class:
s2.micro
. - Network SSD storage:
network-ssd
. - Storage size: 10 GB.
Network specifications:
- Network:
mynet
. - Security group:
mymg-sg
withenp6saqnq4ie244g67sb
ID. In Terraform, a group is created with the rule allowing TCP connections to the cluster from the internet on port27018
. - Subnet:
mysubnet
. - Availability zone:
ru-central1-a
. - Range:
10.5.0.0/24
(only for Terraform).
To create a Managed Service for MongoDB cluster with advanced sharding, run this command:
yc managed-mongodb cluster create \
--name mymg \
--environment production \
--deletion-protection=true \
--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 = "MongoDB"
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"]
}