Skip to content

Commit 24da8b3

Browse files
lsy1968shanye997
authored andcommitted
Manage postgresql instance
1 parent cb41495 commit 24da8b3

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
## Providers
3+
4+
| Name | Version |
5+
|------|---------|
6+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
7+
8+
## Modules
9+
10+
No modules.
11+
12+
## Resources
13+
14+
| Name | Type |
15+
|------|------|
16+
| [alicloud_db_instance.instance](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_instance) | resource |
17+
| [alicloud_vpc.main](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
18+
| [alicloud_vswitch.main](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
19+
20+
## Inputs
21+
22+
| Name | Description | Type | Default | Required |
23+
|------|-------------|------|---------|:--------:|
24+
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | n/a | `string` | `"pg.n2.2c.2m"` | no |
25+
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `"cn-hangzhou"` | no |
26+
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | n/a | `string` | `"cn-hangzhou-b"` | no |
27+
<!-- END_TF_DOCS -->
28+
29+
## Documentation
30+
<!-- docs-link -->
31+
32+
The template is based on Aliyun document: [Manage postgresql instance](http://help.aliyun.com/document_detail/456025.htm)
33+
34+
<!-- docs-link -->
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
variable "region" {
2+
default = "cn-hangzhou"
3+
}
4+
5+
provider "alicloud" {
6+
region = var.region
7+
}
8+
9+
variable "zone_id" {
10+
default = "cn-hangzhou-b"
11+
}
12+
13+
variable "instance_type" {
14+
default = "pg.n2.2c.2m"
15+
}
16+
17+
# 创建VPC
18+
resource "alicloud_vpc" "main" {
19+
vpc_name = "alicloud"
20+
cidr_block = "172.16.0.0/16"
21+
}
22+
23+
# 创建交换机
24+
resource "alicloud_vswitch" "main" {
25+
vpc_id = alicloud_vpc.main.id
26+
cidr_block = "172.16.192.0/20"
27+
zone_id = var.zone_id
28+
depends_on = [alicloud_vpc.main]
29+
}
30+
31+
# 创建RDS PostgreSQL实例
32+
resource "alicloud_db_instance" "instance" {
33+
engine = "PostgreSQL"
34+
engine_version = "13.0"
35+
instance_type = var.instance_type
36+
instance_storage = "30"
37+
instance_charge_type = "Postpaid"
38+
vswitch_id = alicloud_vswitch.main.id
39+
# 修改实例名称
40+
# instance_name = "terraformtest"
41+
# 修改实例配置(以修改RDS PostgreSQL实例的存储空间为50 GB为例)
42+
# instance_storage = "50"
43+
# 设置存储空间自动扩容
44+
# storage_auto_scale = "Enable"
45+
# storage_threshold = "30"
46+
# storage_upper_bound = "100"
47+
# 修改实例可维护时间段
48+
# maintain_time = "05:00Z-06:00Z"
49+
# 修改实例资源组
50+
# resource_group_id = "rg-****"
51+
# 修改实例可用性检测方式(仅高可用实例)
52+
# tcp_connection_type = "SHORT"
53+
# 如果不需要创建VPC和交换机,使用已有的VPC和交换机
54+
# vswitch_id = "vsw-****"
55+
# 创建多个配置相同的RDS PostgreSQL实例,x为需要创建的实例数量
56+
#count = x
57+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
terraform {
2+
required_providers {
3+
alicloud = {
4+
source = "aliyun/alicloud"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)