alicloud_mongodb_instance
Provides a MongoDB instance resource supports replica set instances only. the MongoDB provides stable, reliable, and automatic scalable database services. It offers a full range of database solutions, such as disaster recovery, backup, recovery, monitoring, and alarms. You can see detail product introduction MongoDB documentation
-> NOTE: Available since v1.37.0.
-> NOTE: Destroying a PrePaid instance fails with an error since v1.294.0. To destroy it, unsubscribe the instance in the Alibaba Cloud console or wait for it to expire. To remove the instance from the state only, run terraform state rm.
-> NOTE: Create MongoDB instance or change instance type and storage would cost 5~10 minutes. Please make full preparation
Example Usage
Create a Mongodb instance
variable "name" {
default = "terraform-example"
}
data "alicloud_mongodb_zones" "default" {
}
locals {
index = length(data.alicloud_mongodb_zones.default.zones) - 1
zone_id = data.alicloud_mongodb_zones.default.zones[local.index].id
}
resource "alicloud_vpc" "default" {
vpc_name = var.name
cidr_block = "172.17.3.0/24"
}
resource "alicloud_vswitch" "default" {
vswitch_name = var.name
cidr_block = "172.17.3.0/24"
vpc_id = alicloud_vpc.default.id
zone_id = local.zone_id
}
resource "alicloud_mongodb_instance" "default" {
engine_version = "4.2"
db_instance_class = "dds.mongo.mid"
db_instance_storage = 10
vswitch_id = alicloud_vswitch.default.id
security_ip_list = ["10.168.1.12", "100.69.7.112"]
name = var.name
tags = {
Created = "TF"
For = "example"
}
}
Need more examples? VIEW MORE EXAMPLES
Module Support
You can use to the existing mongodb module to create a MongoDB instance resource one-click.
Argument Reference
The following arguments are supported:
-
engine_version- (Required) Database version. Value options can refer to the latest docs CreateDBInstanceEngineVersion. NOTE: From version 1.225.0,engine_versioncan be modified. -
db_instance_class- (Required) Instance specification. see Instance specifications. -
db_instance_storage- (Required, Int) User-defined DB instance storage space.Unit: GB. Value range:- Custom storage space.
- 10-GB increments.
-
storage_engine(Optional, ForceNew) The storage engine of the instance. Default value:WiredTiger. Valid values:WiredTiger,RocksDB. -
storage_type- (Optional, Available since v1.199.0) The storage type of the instance. Valid values:cloud_essd1,cloud_essd2,cloud_essd3,cloud_auto,local_ssd. NOTE: From version 1.229.0,storage_typecan be modified. However,storage_typecan only be modified tocloud_auto. -
provisioned_iops- (Optional, Int, Available since v1.229.0) The provisioned IOPS. Valid values:0to50000. -
vpc_id- (Optional, ForceNew, Available since v1.161.0) The ID of the VPC. -> NOTE:vpc_idis valid only whennetwork_typeis set toVPC. -
vswitch_id- (Optional, ForceNew) The virtual switch ID to launch DB instances in one VPC. -
zone_id- (Optional, ForceNew) The Zone to launch the DB instance. it supports multiple zone. If it is a multi-zone andvswitch_idis specified, the vswitch must in one of them. The multiple zone ID can be retrieved by settingmultito "true" in the data sourcealicloud_zones. -
secondary_zone_id- (Optional, Available since v1.199.0) Configure the available area where the slave node (Secondary node) is located to realize multi-available area deployment. NOTE: This parameter value cannot be the same aszone_idandhidden_zone_idparameter values. From version 1.253.0,secondary_zone_idcan be modified. -
hidden_zone_id- (Optional, Available since v1.199.0) Configure the zone where the hidden node is located to deploy multiple zones. NOTE: This parameter value cannot be the same aszone_idandsecondary_zone_idparameter values. From version 1.253.0,hidden_zone_idcan be modified. -
security_group_id- (Optional, Available since v1.73.0) The Security Group ID of ECS. -
replication_factor- (Optional, Int) Number of replica set nodes. Valid values:1,3,5,7. -
network_type- (Optional, ForceNew, Available since v1.161.0) The network type of the instance. Valid values:VPC.-> NOTE: From 2022.2.21,
network_typecannot be set toClassic. For more information, seeProduct Notification -
name- (Optional) The name of DB instance. It must be 2 to 256 characters in length. -
instance_charge_type- (Optional) The billing method of the instance. Default value:PostPaid. Valid values:PrePaid,PostPaid. NOTE: It can be modified fromPostPaidtoPrePaidafter version 1.63.0. -
period- (Optional, Int) The duration that you will buy DB instance (in month). It is valid wheninstance_charge_typeisPrePaid. Default value:1. Valid values: [1~9], 12, 24, 36. -
security_ip_list- (Optional, List) List of IP addresses allowed to access all databases of an instance. The list contains up to 1,000 IP addresses, separated by commas. Supported formats include 0.0.0.0/0, 10.23.12.24 (IP), and 10.23.12.24/24 (Classless Inter-Domain Routing (CIDR) mode. /24 represents the length of the prefix in an IP address. The range of the prefix length is [1,32]). -
security_ip_groups- (Optional, Set) The list of named security IP groups. Each element represents a separate IP whitelist group managed independently fromsecurity_ip_list(which manages thedefaultgroup). Seesecurity_ip_groupsbelow. -
account_password- (Optional, Sensitive) Password of the root account. It is a string of 6 to 32 characters and is composed of letters, numbers, and underlines. -
account_password_wo- (Optional, Available since v2.2.0) The write-only password of the account. It is only sent to the server when the resource is created or theaccount_password_wo_versionchanges and is never stored in the state or plan. -
account_password_wo_version- (Optional, Available since v2.2.0) The version of the write-only password. The write-only password is re-sent to the server only when this argument changes, so it must be changed wheneveraccount_password_wochanges. -
kms_encrypted_password- (Optional, Available since v1.57.1) An KMS encrypts password used to a instance. If theaccount_passwordis filled in, this field will be ignored. -
kms_encryption_context- (Optional, MapString, Available since v1.57.1) An KMS encryption context used to decryptkms_encrypted_passwordbefore creating or updating instance withkms_encrypted_password. See Encryption Context. It is valid whenkms_encrypted_passwordis set. -
encrypted- (Optional, ForceNew, Bool, Available since v1.212.0) Whether to enable cloud disk encryption. Default value:false. Valid values:true,false. -
cloud_disk_encryption_key- (Optional, ForceNew, Available since v1.212.0) The ID of the encryption key. -
readonly_replicas- (Optional, Int, Available since v1.199.0) The number of read-only nodes in the replica set instance. Default value: 0. Valid values: 0 to 5. -
resource_group_id- (Optional, Available since v1.161.0) The ID of the Resource Group. -
auto_renew- (Optional, Bool, Available since v1.141.0) Auto renew for prepaid. Default value:false. Valid values:true,false. -
auto_renew_duration- (Optional, Int, Available since v1.271.0) The auto-renewal period. Unit: months. Valid values:1to12.-> NOTE: If
auto_renewis set totrue,auto_renew_durationmust be set. -
src_db_instance_id- (Optional, Available since v1.271.0) The source instance ID. -
restore_time- (Optional, Available since v1.271.0) The point in time to which you want to restore the instance. You can specify any point in time within the last seven days. The time must be in the yyyy-MM-ddTHH:mm:ssZ format and in UTC.-> NOTE: You must specify
src_db_instance_idandrestore_timeonly when you clone an instance based on a point in time. -
backup_time- (Optional, Available since v1.42.0) MongoDB instance backup time. It is required whenbackup_periodwas existed. In the format of HH:mmZ- HH:mmZ. Time setting interval is one hour. If not set, the system will return a default, like "23:00Z-24:00Z". -
backup_period- (Optional, List, Available since v1.42.0) MongoDB Instance backup period. It is required whenbackup_timewas existed. Valid values: [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]. Default to [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]. -
backup_retention_period- (Optional, Int, Available since v1.213.1) The retention period of full backups. -
backup_retention_policy_on_cluster_deletion- (Optional, Int, Available since v1.235.0) The backup retention policy configured for the instance. Valid values:0: All backup sets are immediately deleted when the instance is released.1: Automatic backup is performed when the instance is released and the backup set is retained for a long period of time.2: Automatic backup is performed when the instance is released and all backup sets are retained for a long period of time.
-
enable_backup_log- (Optional, Int, Available since v1.230.1) Specifies whether to enable the log backup feature. Valid values:0: The log backup feature is disabled.1: The log backup feature is enabled.
-
log_backup_retention_period- (Optional, Int, Available since v1.230.1) The number of days for which log backups are retained. Valid values:7to730. NOTE:log_backup_retention_periodis valid only whenenable_backup_logis set to1. -
snapshot_backup_type- (Optional, Available since v1.212.0) The snapshot backup type. Default value:Standard. Valid values:Standard: standard backup.Flash: single-digit second backup.
-
backup_interval- (Optional, Available since v1.212.0) The frequency at which high-frequency backups are created. Valid values:-1,15,30,60,120,180,240,360,480,720. -
ssl_action- (Optional, Available since v1.78.0) Actions performed on SSL functions. Valid values:Open: turn on SSL encryption.Close: turn off SSL encryption.Update: update SSL certificate.
-> NOTE: Once
ssl_actionis set, it isn't allowed to be removed from the Terraform code. -
force_encryption- (Optional, Available since v1.271.0) Specifies whether to forcibly enable SSL encryption for connections. Valid values:1: Forcibly enable SSL encryption.0: Do not forcibly enable SSL encryption.
-> NOTE:
force_encryptionis supported only for MongoDB 7.0 and 8.0 instances that use cloud disks. After you enable forced SSL encryption, only SSL connections to the instance are allowed. -
maintain_start_time- (Optional, Available since v1.56.0) The start time of the operation and maintenance time period of the instance, in the format of HH:mmZ (UTC time). -
maintain_end_time- (Optional, Available since v1.56.0) The end time of the operation and maintenance time period of the instance, in the format of HH:mmZ (UTC time).-> NOTE: The start time to the end time must be 1 hour. For example, the MaintainStartTime is 01:00Z, then the MaintainEndTime must be 02:00Z.
-
effective_time- (Optional, Available since v1.215.0) The time when the changed configurations take effect. Valid values:Immediately,MaintainTime. -
order_type- (Optional, Available since v1.134.0) The type of configuration changes performed. Default value:DOWNGRADE. Valid values:UPGRADE: The specifications are upgraded.DOWNGRADE: The specifications are downgraded.
-> NOTE:
order_typeis only applicable to instances wheninstance_charge_typeisPrePaid. -
tde_status- (Optional, Available since v1.73.0) The TDE(Transparent Data Encryption) status. Note:tde_statuscannot be set todisabledafter it is enabled, see Transparent Data Encryption for more details. -
encryptor_name- (Optional, Available since v1.212.0) The encryption method. NOTE:encryptor_nameis valid only whentde_statusis set toenabled. -
encryption_key- (Optional, Available since v1.212.0) The ID of the custom key. -
role_arn- (Optional, Available since v1.212.0) The Alibaba Cloud Resource Name (ARN) of the specified Resource Access Management (RAM) role. -
db_instance_release_protection- (Optional, Bool, Available since v1.253.0) Indicates whether release protection is enabled for the instance. Valid values:true,false. -
parameters- (Optional, Set, Available since v1.203.0) Set of parameters needs to be set after mongodb instance was launched. Seeparametersbelow. -
global_security_group_list- (Optional, List, Available since v1.257.0) The list of Global Security Group Ids. -
tags- (Optional, Available since v1.66.0) A mapping of tags to assign to the resource.
security_ip_groups
The security_ip_groups supports the following:
security_ip_group_name- (Optional) The name of the security IP group. If not specified, the default group namedefaultis used. Each named group is managed independently fromsecurity_ip_list(which manages thedefaultgroup).security_ip_list- (Optional) The IP addresses in the security IP group. The list contains up to 1,000 IP addresses, separated by commas. Supported formats include 0.0.0.0/0, 10.23.12.24 (IP), and 10.23.12.24/24 (Classless Inter-Domain Routing (CIDR) mode. /24 represents the length of the prefix in an IP address. The range of the prefix length is [1,32]).security_ip_group_attribute- (Optional) The attribute of the security IP group. It must be 1 to 120 characters in length and can contain letters and digits. Do not set this attribute tohidden; otherwise the group will be ignored by Read.
parameters
The parameters supports the following:
name- (Required) The name of the parameter.value- (Required) The value of the parameter.
Attributes Reference
The following attributes are exported:
id- The ID of the MongoDB.retention_period- Instance data backup retention days. Available since v1.42.0.replica_set_name- The name of the mongo replica set.ssl_status- Status of the SSL feature.key_ids- (Available since v1.271.0) A list of instance keys.zone_infos- (Available since v1.271.0) The information of nodes in the zone.ins_name- The ID of the node.node_type- The type of the node.role_id- The role ID.role_type- The role of the node.zone_id- The zone ID of the node.
replica_sets- Replica set instance information.vpc_id- The private network ID of the node.vswitch_id- The virtual switch ID to launch DB instances in one VPC.network_type- The network type of the node.vpc_cloud_instance_id- VPC instance ID.replica_set_role- The role of the node.connection_domain- The connection address of the node.connection_port- The connection port of the node.role_id- The id of the role.
Timeouts
-> NOTE: Available since v1.53.0.
The timeouts block allows you to specify timeouts for certain actions:
create- (Defaults to 30 mins) Used when creating the MongoDB instance (until it reaches the initialRunningstatus).update- (Defaults to 120 mins) Used when updating the MongoDB instance (until it reaches the initialRunningstatus).delete- (Defaults to 30 mins) Used when deleting the MongoDB instance.
Import
MongoDB instance can be imported using the id, e.g.
$ terraform import alicloud_mongodb_instance.example <id>