Skip to content

Commit 1c85540

Browse files
ajenpanxiaozhu36
authored andcommitted
add mongodb instance module and example
1 parent 3b36253 commit 1c85540

File tree

7 files changed

+221
-1
lines changed

7 files changed

+221
-1
lines changed

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
11
# terraform-alicloud-mongodb
2-
Terraform module which creates MongoDB instance and other resources on Alibaba Cloud
2+
3+
Terraform module which creates MongoDB instance on Alibaba Cloud
4+
5+
## mongodb replica instance
6+
7+
Terraform module which creates MongoDB replica instance resources on Alibaba Cloud
8+
9+
These types of resources are supported:
10+
11+
- [mongodb_instance] (https://www.terraform.io/docs/providers/alicloud/r/mongodb_instance.html)
12+
13+
## Usage
14+
15+
You can use this in your terraform template with the following steps.
16+
17+
1. Adding a module resource to your template, e.g. main.tf
18+
19+
```tf
20+
module "mongodb_instance" {
21+
source = "terraform-alicloud-modules/mongodb/alicloud"
22+
engine_version = "${var.engine_version}"
23+
db_instance_class = "${var.db_instance_class}"
24+
db_instance_storage = "${var.db_instance_storage}"
25+
name = "${var.name}"
26+
instance_charge_type = "${var.instance_charge_type}"
27+
vswitch_id = "${var.vswitch_id}"
28+
security_ip_list = "${var.security_ip_list}"
29+
}
30+
```
31+
32+
1. Setting `access_key` and `secret_key` values through environment variables:
33+
34+
- ALICLOUD_ACCESS_KEY
35+
- ALICLOUD_SECRET_KEY
36+
- ALICLOUD_REGION
37+
38+
## Input
39+
40+
| Name | Description | Type | Default | Required |
41+
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----: | :--------: | :------: |
42+
| engine_version | Database version. Value options:3.4 3.6 4.0 | string | "" | yes |
43+
| instance_type | DB Instance type. For details, see [Instance type table](https://www.alibabacloud.com/help/doc-detail/57141.htm). | string | "" | yes |
44+
| instance_storage | User-defined DB instance storage space. Value range:[10,2000] Increase progressively at a rate of 5 GB. For details, see [Instance type table](https://www.alibabacloud.com/help/doc-detail/26312.htm). | string | 10 | yes |
45+
| instance_name | The name of DB instance. It a string of 2 to 256 characters. | string | "" | no |
46+
| instance_charge_type | Valid values are PrePaid, PostPaid, Default to PostPaid. | string | PostPaid | no | "PostPaid" |
47+
| zone_id | The Zone to launch the DB instance. From version 1.8.1, it supports multiple zone. If it is a multi-zone and vswitch_id is specified, the vswitch must in the one of them. The multiple zone ID can be retrieved by setting multi to "true" in the data source alicloud_zones. | string | "" | no |
48+
| vswitch_id | VSwitch ID. If the instance type is VPC, this parameter cannot be left blank. | string | "" | no |
49+
| security_ip_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]). | list | [ ] | no |
50+
| vswitch_id | VSwitch ID. If the instance type is VPC, this parameter cannot be left blank. | string | "" | no |
51+
| storage_engine | Storage engine; optional values: WiredTiger or RocksDB. | string | WiredTiger | no |
52+
| replication_factor | Number of replica set nodes. Valid values: [3,5,7] | int | 3 | no |
53+
| account_password | Password of the root account | string | "" | no |
54+
55+
## Outputs
56+
57+
| Name | Description |
58+
| ----------------------------- | -------------------------------- |
59+
| this_db_instance_id | instance ID created |
60+
| this_db_instance_name | instance name configured |
61+
| this_db_instance_security_ips | instance security ips configured |
62+
| this_db_instance_zone_id | instance zone ID created |
63+
| this_db_instance_vswitch_id | instance vswitch ID created |

examples/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Complete MongoDB example
2+
3+
Configuration in this directory creates set of RDS resources including DB instance, DB account and Datebase.
4+
5+
## Usage
6+
7+
To run this example you need to execute:
8+
9+
```bash
10+
$ terraform init
11+
$ terraform plan
12+
$ terraform apply
13+
```
14+
15+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
16+
17+
18+
## Outputs
19+
20+
| Name | Description |
21+
| ----------------------------- | -------------------------------- |
22+
| this_db_instance_id | instance ID created |
23+
| this_db_instance_name | instance name configured |
24+
| this_db_instance_security_ips | instance security ips configured |
25+
| this_db_instance_zone_id | instance zone ID created |
26+
| this_db_instance_vswitch_id | instance vswitch ID created |
27+

examples/main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module "mongodb_instance" {
2+
source = "../"
3+
engine_version = "3.4"
4+
db_instance_class = "dds.mongo.mid"
5+
db_instance_storage = 10
6+
security_ip_list = ["10.168.1.12", "100.69.7.112"]
7+
name = "my-mongodb"
8+
vswitch_id = "${module.module_vpc.vswitch_ids}"
9+
}
10+
11+
module "module_vpc" {
12+
source = "alibaba/vpc/alicloud"
13+
vpc_name = "my_module_vpc"
14+
vswitch_name = "my_module_vswitch"
15+
vswitch_cidrs = ["172.16.1.0/24"]
16+
}
17+
18+
// Zones data source for availability_zone
19+
data "alicloud_zones" "default" {
20+
available_resource_creation = "MongoDB"
21+
}

examples/output.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "this_mongodb_instance_id" {
2+
value = "${module.mongodb_instance.this_db_instance_id}"
3+
}
4+
5+
output "this_mongodb_instance_name" {
6+
value = "${module.mongodb_instance.this_db_instance_name}"
7+
}
8+
9+
output "this_mongodb_instance_zone_id" {
10+
value = "${module.mongodb_instance.this_db_instance_zone_id}"
11+
}
12+
13+
output "this_mongodb_instance_vswitch_id" {
14+
value = "${module.mongodb_instance.this_db_instance_vswitch_id}"
15+
}
16+
17+
output "this_mongodb_instance_security_ip_list" {
18+
value = "${module.mongodb_instance.this_db_instance_security_ip_list}"
19+
}

main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
resource "alicloud_mongodb_instance" "this_instance" {
2+
engine_version = "${var.engine_version}"
3+
name = "${var.name}"
4+
instance_charge_type = "${var.instance_charge_type}"
5+
db_instance_class = "${var.db_instance_class}"
6+
db_instance_storage = "${var.db_instance_storage}"
7+
period = "${var.period}"
8+
security_ip_list = "${var.security_ip_list}"
9+
replication_factor = "${var.replication_factor}"
10+
storage_engine = "${var.storage_engine}"
11+
vswitch_id = "${var.vswitch_id}"
12+
zone_id = "${var.zone_id}"
13+
account_password = "${var.account_password}"
14+
}

outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "this_db_instance_id" {
2+
value = "${alicloud_mongodb_instance.this_instance.id}"
3+
}
4+
5+
output "this_db_instance_name" {
6+
value = "${alicloud_mongodb_instance.this_instance.name}"
7+
}
8+
9+
output "this_db_instance_zone_id" {
10+
value = "${alicloud_mongodb_instance.this_instance.zone_id}"
11+
}
12+
13+
output "this_db_instance_vswitch_id" {
14+
value = "${alicloud_mongodb_instance.this_instance.vswitch_id}"
15+
}
16+
17+
output "this_db_instance_security_ip_list" {
18+
value = "${alicloud_mongodb_instance.this_instance.security_ip_list}"
19+
}

variables.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
##############################################################
2+
#variables for alicloud_mongodb_instance
3+
##############################################################
4+
5+
variable "engine_version" {
6+
description = "The engine version to use"
7+
}
8+
9+
variable "db_instance_storage" {
10+
description = "The allocated storage in gigabytes"
11+
}
12+
13+
variable "db_instance_class" {
14+
description = "DB Instance type, for example: dds.mongo.mid. fall list is : https://www.alibabacloud.com/help/doc-detail/57141.html"
15+
}
16+
17+
variable "storage_engine" {
18+
description = "The MongoDB storage engine, WiredTiger or RocksDB"
19+
default = "WiredTiger"
20+
}
21+
22+
variable "name" {
23+
description = " The name of DB instance. It a string of 2 to 256 characters"
24+
}
25+
26+
variable "instance_charge_type" {
27+
description = "Valid values are Prepaid, PostPaid, Default to PostPaid"
28+
default = "PostPaid"
29+
}
30+
31+
variable "period" {
32+
description = "The duration that you will buy DB instance (in month). It is valid when instance_charge_type is PrePaid. Valid values: [1~9], 12, 24, 36. Default to 1"
33+
default=1
34+
}
35+
36+
variable "zone_id" {
37+
description = "The Zone to launch the DB instance. "
38+
default=""
39+
}
40+
41+
variable "vswitch_id" {
42+
description = "The VSwitch to launch the DB instance. "
43+
}
44+
45+
variable "security_ip_list" {
46+
description = " 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])."
47+
type = "list"
48+
default = []
49+
}
50+
51+
variable "account_password" {
52+
description = "Password of the root account. It is a string of 6 to 32 characters and is composed of letters, numbers, and underlines"
53+
default = ""
54+
}
55+
56+
variable "replication_factor" {
57+
description = "Number of replica set nodes. Valid values: [3,5,7]"
58+
default = 3
59+
}

0 commit comments

Comments
 (0)