Skip to content

Commit 08ca9d1

Browse files
Rich-yixiaozhu36
authored andcommitted
Add multiple zones
1 parent 46694b6 commit 08ca9d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4872
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ override.tf.json
2727

2828
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
2929
# example: *tfplan*
30+
*idea*

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 1.0.0 (Unreleased)
2+
3+
- **NEW:** `rds-postgres` [GH-1]( https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/pull/1)
4+
5+
- Add multiple zones [GH-2]( https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/pull/2)

README-CN.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
terraform-alicloud-rds-postgres
2+
-------
3+
4+
本 Module 用于在阿里云的 VPC 下创建一个[Postgre SQL 云数据库](https://help.aliyun.com/document_detail/26092.html),并为其配置云监控。
5+
6+
本 Module 支持创建以下资源:
7+
8+
* [Postgre SQL 数据库实例 (db_instance)](https://www.terraform.io/docs/providers/alicloud/r/db_instance.html)
9+
* [Account 数据库用户实例 (db_account)](https://www.terraform.io/docs/providers/alicloud/r/db_account.html)
10+
* [Database 数据库实例 (db_database)](https://www.terraform.io/docs/providers/alicloud/r/db_database.html)
11+
* [BackupPolicy 备份实例 (db_backup_policy)](https://www.terraform.io/docs/providers/alicloud/r/db_backup_policy.html)
12+
* [CmsAlarm 云监控实例 (cms_alarm)](https://www.terraform.io/docs/providers/alicloud/r/cms_alarm.html)
13+
14+
15+
## Terraform 版本
16+
17+
本模板要求使用版本 Terraform 0.12 和阿里云 Provider 1.71.0+。
18+
19+
## 用法
20+
21+
#### 创建新的Rds实例
22+
23+
```hcl
24+
module "postgres" {
25+
source = "terraform-alicloud-modules/rds-postgres/alicloud"
26+
region = "cn-hangzhou"
27+
28+
#################
29+
# Rds Instance
30+
#################
31+
engine_version = "10.0"
32+
instance_storage = 20
33+
instance_charge_type = "Postpaid"
34+
vswitch_id = "vsw-bp1tili2u5kxxxxxx"
35+
instance_name = "PostgreSQLInstance"
36+
instance_type = "rds.pg.s1.small"
37+
security_group_ids = ["sg-2ze7v4p5skehxxxxxxxx"]
38+
security_ips = ["11.193.xx.xx/24", "101.37.xx.xx/24"]
39+
tags = {
40+
Env = "Private"
41+
Location = "Secret"
42+
}
43+
44+
####################
45+
# Rds Backup policy
46+
####################
47+
preferred_backup_period = ["Monday", "Wednesday"]
48+
preferred_backup_time = "00:00Z-01:00Z"
49+
backup_retention_period = 7
50+
log_backup_retention_period = 7
51+
enable_backup_log = true
52+
allocate_public_connection = false
53+
54+
###########
55+
#databases
56+
###########
57+
privilege = "ReadOnly"
58+
databases = [
59+
{
60+
name = "dbuser1"
61+
character_set = "UTF8"
62+
description = "db1"
63+
},
64+
{
65+
name = "dbuser2"
66+
character_set = "UTF8"
67+
description = "db2"
68+
},
69+
]
70+
71+
#######################
72+
# Rds Database account
73+
#######################
74+
account_privilege = "DBOwner"
75+
account_name = "account_name1"
76+
account_password = "yourpassword123"
77+
78+
#############
79+
# Alarm Rule
80+
#############
81+
alarm_rule_name = "CmsAlarmForPostgreSQL"
82+
alarm_rule_statistics = "Average"
83+
alarm_rule_period = 300
84+
alarm_rule_operator = "<="
85+
alarm_rule_threshold = 35
86+
alarm_rule_triggered_count = 2
87+
alarm_rule_contact_groups = ["postgre"]
88+
}
89+
```
90+
91+
### 使用已经存在的Rds实例
92+
93+
```hcl
94+
module "postgres" {
95+
source = "terraform-alicloud-modules/rds-postgres/alicloud"
96+
region = "cn-beijing"
97+
98+
#################
99+
# Rds Instance
100+
#################
101+
existing_instance_id = "pgm-2zehbutrxxxxxx"
102+
103+
#################
104+
# Rds Backup policy
105+
#################
106+
create_backup_policy=true
107+
preferred_backup_period = ["Monday", "Wednesday"]
108+
preferred_backup_time = "00:00Z-01:00Z"
109+
backup_retention_period = 7
110+
log_backup_retention_period = 7
111+
enable_backup_log = true
112+
allocate_public_connection = false
113+
114+
###########
115+
#databases
116+
###########
117+
databases = [
118+
{
119+
name = "postgre_sqldb"
120+
character_set = "UTF8"
121+
description = "db1"
122+
}
123+
]
124+
125+
#######################
126+
# Rds Database Account
127+
#######################
128+
account_privilege = "DBOwner"
129+
account_name = "account_name"
130+
account_password = "yourpassword123"
131+
tags = {
132+
Env = "Private"
133+
Location = "Secret"
134+
}
135+
136+
#############
137+
# Alarm Rule
138+
#############
139+
alarm_rule_name = "CmsAlarmForPostgreSQL"
140+
alarm_rule_statistics = "Average"
141+
alarm_rule_period = 300
142+
alarm_rule_operator = "<="
143+
alarm_rule_threshold = 35
144+
alarm_rule_triggered_count = 2
145+
alarm_rule_contact_groups = ["postgre"]
146+
}
147+
```
148+
149+
## 示例
150+
151+
* [创建 Postgres 完整示例](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/examples/complete)
152+
* [使用已经存在的 Rds 实例创建 Postgres 示例](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/examples/using-existing-rds-instance)
153+
154+
## 模块
155+
156+
* [database 模块](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/database)
157+
* [postgres-10-basic 模块](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-10-basic)
158+
* [postgres-10-high-availability 模块](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-10-high-availability)
159+
* [postgres-11-basic 模块](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-11-basic)
160+
* [postgres-11-high-availability 模块](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-11-high-availability)
161+
* [postgres-12-basic 模块](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-12-basic)
162+
163+
## 注意事项
164+
165+
* 本 Module 使用的 AccessKey 和 SecretKey 可以直接从 `profile``shared_credentials_file` 中获取。如果未设置,可通过下载安装 [aliyun-cli](https://github.com/aliyun/aliyun-cli#installation) 后进行配置。
166+
167+
作者
168+
-------
169+
Created and maintained by He Guimin(@xiaozhu36, heguimin36@163.com) and Yi Jincheng(yi785301535@163.com)
170+
171+
许可
172+
----
173+
Apache 2 Licensed. See LICENSE for full details.
174+
175+
参考
176+
---------
177+
* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud)
178+
* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/)
179+
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)
180+
181+

README.md

Lines changed: 184 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,184 @@
1-
# terraform-provider-rds-postgres
2-
Terraform module which create a PostgreSQL database based on Alibaba Cloud RDS Service.
1+
Terraform module which create a PostgreSQL database based on Alibaba Cloud RDS Service.
2+
terraform-provider-rds-postgres
3+
------------
4+
5+
English | [简体中文](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/blob/master/README-CN.md)
6+
7+
Terraform module which creates rds-postgres database and sets CMS alarm for it on Alibaba Cloud.
8+
9+
These types of resources are supported:
10+
11+
* [Alicloud_db_instance](https://www.terraform.io/docs/providers/alicloud/r/db_instance.html)
12+
* [Alicloud_db_account](https://www.terraform.io/docs/providers/alicloud/r/db_account.html)
13+
* [Alicloud_db_database](https://www.terraform.io/docs/providers/alicloud/r/db_database.html)
14+
* [Alicloud_db_backup_policy](https://www.terraform.io/docs/providers/alicloud/r/db_backup_policy.html)
15+
* [alicloud_cms_alarm](https://www.terraform.io/docs/providers/alicloud/r/alarm_rule.html)
16+
17+
18+
## Terraform versions
19+
20+
This module requires Terraform 0.12 and Terraform Provider Alicloud 1.71.0+.
21+
22+
## Usage
23+
24+
For new instance
25+
26+
```hcl
27+
module "postgres" {
28+
source = "terraform-alicloud-modules/rds-postgres/alicloud"
29+
region = "cn-hangzhou"
30+
31+
#################
32+
# Rds Instance
33+
#################
34+
engine_version = "10.0"
35+
instance_storage = 20
36+
instance_charge_type = "Postpaid"
37+
vswitch_id = "vsw-bp1tili2u5kxxxxxx"
38+
instance_name = "PostgreSQLInstance"
39+
instance_type = "rds.pg.s1.small"
40+
security_group_ids = ["sg-2ze7v4p5skehxxxxxxxx"]
41+
security_ips = ["11.193.xx.xx/24", "101.37.xx.xx/24"]
42+
tags = {
43+
Env = "Private"
44+
Location = "Secret"
45+
}
46+
47+
####################
48+
# Rds Backup policy
49+
####################
50+
preferred_backup_period = ["Monday", "Wednesday"]
51+
preferred_backup_time = "00:00Z-01:00Z"
52+
backup_retention_period = 7
53+
log_backup_retention_period = 7
54+
enable_backup_log = true
55+
allocate_public_connection = false
56+
57+
###########
58+
#databases
59+
###########
60+
privilege = "ReadOnly"
61+
databases = [
62+
{
63+
name = "dbuser1"
64+
character_set = "UTF8"
65+
description = "db1"
66+
},
67+
{
68+
name = "dbuser2"
69+
character_set = "UTF8"
70+
description = "db2"
71+
},
72+
]
73+
74+
#######################
75+
# Rds Database account
76+
#######################
77+
account_privilege = "DBOwner"
78+
account_name = "account_name1"
79+
account_password = "yourpassword123"
80+
81+
#############
82+
# Alarm Rule
83+
#############
84+
alarm_rule_name = "CmsAlarmForPostgreSQL"
85+
alarm_rule_statistics = "Average"
86+
alarm_rule_period = 300
87+
alarm_rule_operator = "<="
88+
alarm_rule_threshold = 35
89+
alarm_rule_triggered_count = 2
90+
alarm_rule_contact_groups = ["postgre"]
91+
}
92+
```
93+
94+
For existing instance
95+
```hcl
96+
module "postgres" {
97+
source = "terraform-alicloud-modules/rds-postgres/alicloud"
98+
region = "cn-beijing"
99+
100+
#################
101+
# Rds Instance
102+
#################
103+
existing_instance_id = "pgm-2zehbutrxxxxxx"
104+
105+
#################
106+
# Rds Backup policy
107+
#################
108+
create_backup_policy=true
109+
preferred_backup_period = ["Monday", "Wednesday"]
110+
preferred_backup_time = "00:00Z-01:00Z"
111+
backup_retention_period = 7
112+
log_backup_retention_period = 7
113+
enable_backup_log = true
114+
allocate_public_connection = false
115+
116+
###########
117+
#databases
118+
###########
119+
databases = [
120+
{
121+
name = "postgre_sqldb"
122+
character_set = "UTF8"
123+
description = "db1"
124+
}
125+
]
126+
127+
#######################
128+
# Rds Database Account
129+
#######################
130+
account_privilege = "DBOwner"
131+
account_name = "account_name"
132+
account_password = "yourpassword123"
133+
tags = {
134+
Env = "Private"
135+
Location = "Secret"
136+
}
137+
138+
#############
139+
# Alarm Rule
140+
#############
141+
alarm_rule_name = "CmsAlarmForPostgreSQL"
142+
alarm_rule_statistics = "Average"
143+
alarm_rule_period = 300
144+
alarm_rule_operator = "<="
145+
alarm_rule_threshold = 35
146+
alarm_rule_triggered_count = 2
147+
alarm_rule_contact_groups = ["postgre"]
148+
}
149+
```
150+
151+
152+
## Examples
153+
154+
* [Complete Example](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/examples/complete)
155+
* [Using exising Rds Instance Example](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/examples/using-existing-rds-instance)
156+
157+
## Modules
158+
159+
* [database](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/database)
160+
* [postgres-10-basic](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-10-basic)
161+
* [postgres-10-high-availability](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-10-high-availability)
162+
* [postgres-11-basic](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-11-basic)
163+
* [postgres-11-high-availability](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-11-high-availability)
164+
* [postgres-12-basic](https://github.com/terraform-alicloud-modules/terraform-alicloud-rds-postgres/tree/master/modules/postgres-12-basic)
165+
166+
## Notes
167+
168+
* This module using AccessKey and SecretKey are from 'profile' and 'shared_credentials_file'.
169+
If you have not set them yet, please install [aliyun-cli](https://github.com/aliyun/aliyun-cli#installation) and configure it.
170+
171+
Authors
172+
-------
173+
Created and maintained by He Guimin(@xiaozhu36, heguimin36@163.com) and Yi Jincheng(yi785301535@163.com)
174+
175+
License
176+
----
177+
Apache 2 Licensed. See LICENSE for full details.
178+
179+
Reference
180+
---------
181+
* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud)
182+
* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/)
183+
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)
184+

example/complete/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Complete RDS example for PostgreSQL
2+
3+
## Usage
4+
5+
To run this example you need to execute:
6+
7+
```bash
8+
$ terraform init
9+
$ terraform plan
10+
$ terraform apply
11+
```
12+
13+
Note that this example will create resources which cost money. Run 'terraform destroy' when you don't need these resources.
14+
15+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

0 commit comments

Comments
 (0)