» yandex_mdb_mongodb_cluster

Manages a MongoDB cluster within the Yandex.Cloud. For more information, see the official documentation.

» Example Usage

Example of creating a Single Node MongoDB.

resource "yandex_vpc_network" "foo" {}

resource "yandex_vpc_subnet" "foo" {
  zone           = "ru-central1-a"
  network_id     = "${yandex_vpc_network.foo.id}"
  v4_cidr_blocks = ["10.1.0.0/24"]
}

resource "yandex_mdb_mongodb_cluster" "foo" {
  name        = "test"
  environment = "PRESTABLE"
  network_id  = "${yandex_vpc_network.foo.id}"

  cluster_config {
    version = "4.2"
  }

  labels = {
    test_key = "test_value"
  }

  database {
    name = "testdb"
  }

  user {
    name     = "john"
    password = "password"
    permission {
      database_name = "testdb"
    }
  }

  resources {
    resource_preset_id = "b1.nano"
    disk_size          = 16
    disk_type_id       = "network-hdd"
  }

  host {
    zone_id   = "ru-central1-a"
    subnet_id = "${yandex_vpc_subnet.foo.id}"
  }
}

» Argument Reference

The following arguments are supported:

  • name - (Required) Name of the MongoDB cluster. Provided by the client when the cluster is created.

  • network_id - (Required) ID of the network, to which the MongoDB cluster belongs.

  • environment - (Required) Deployment environment of the MongoDB cluster. Can be either PRESTABLE or PRODUCTION.

  • cluster_config - (Required) Configuration of the MongoDB subcluster. The structure is documented below.

  • user - (Required) A user of the MongoDB cluster. The structure is documented below.

  • database - (Required) A database of the MongoDB cluster. The structure is documented below.

  • host - (Required) A host of the MongoDB cluster. The structure is documented below.

  • resources - (Required) Resources allocated to hosts of the MongoDB cluster. The structure is documented below.


  • version - (Optional) Version of the MongoDB server software. Can be either 3.6, 4.0 and 4.2.

  • description - (Optional) Description of the MongoDB cluster.

  • folder_id - (Optional) The ID of the folder that the resource belongs to. If it is not provided, the default provider folder is used.

  • labels - (Optional) A set of key/value label pairs to assign to the MongoDB cluster.

  • access - (Optional) Access policy to the MongoDB cluster. The structure is documented below.


The cluster_config block supports:

  • version - (Required) Version of MongoDB (either 4.2, 4.0 or 3.6).

  • feature_compatibility_version - (Optional) Feature compatibility version of MongoDB. If not provided version is taken. Can be either 4.2, 4.0 and 3.6.

  • backup_window_start - (Optional) Time to start the daily backup, in the UTC timezone. The structure is documented below.

  • access - (Optional) Shows whether cluster has access to data lens. The structure is documented below.

The backup_window_start block supports:

  • hours - (Optional) The hour at which backup will be started.

  • minutes - (Optional) The minute at which backup will be started.

The resources block supports:

The user block supports:

  • name - (Required) The name of the user.

  • password - (Required) The password of the user.

  • permission - (Optional) Set of permissions granted to the user. The structure is documented below.

The permission block supports:

The database block supports:

  • name - (Required) The name of the database.

The host block supports:

  • name - (Computed) The fully qualified domain name of the host. Computed on server side.

  • zone_id - (Required) The availability zone where the MongoDB host will be created. For more information see the official documentation.

  • role - (Optional) The role of the cluster (either PRIMARY or SECONDARY).

  • health - (Computed) The health of the host.

  • subnet_id - (Required) The ID of the subnet, to which the host belongs. The subnet must be a part of the network to which the cluster belongs.

  • assign_public_ip -(Optional) Should this host have assigned public IP assigned. Can be either true or false.

  • shard_name - (Optional) The name of the shard to which the host belongs.

  • type - (Optional) type of mongo daemon which runs on this host (mongod, mongos or monogcfg). Defaults to mongod.

The access block supports:

  • data_lens - (Optional) Allow access for DataLens.

» Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • created_at - Creation timestamp of the key.

  • health - Aggregated health of the cluster. Can be either ALIVE, DEGRADED, DEAD or HEALTH_UNKNOWN. For more information see health field of JSON representation in the official documentation.

  • status - Status of the cluster. Can be either CREATING, STARTING, RUNNING, UPDATING, STOPPING, STOPPED, ERROR or STATUS_UNKNOWN. For more information see status field of JSON representation in the official documentation.

  • cluster_id - The ID of the cluster.

  • sharded - MongoDB Cluster mode enabled/disabled.

» Import

A cluster can be imported using the id of the resource, e.g.

$ terraform import yandex_mdb_mongodb_cluster.foo cluster_id