Skip to content

Commit a103eb9

Browse files
committed
Manage RDS account
1 parent a02edbd commit a103eb9

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Introduction
2+
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
本示例用于在阿里云上创建、修改、查询和删除RDS PostgreSQL实例账号。
5+
本示例来自[通过 Terraform 管理RDS账号](http://help.aliyun.com/document_detail/456029.htm)
6+
<!-- DOCS_DESCRIPTION_CN -->
7+
8+
<!-- DOCS_DESCRIPTION_EN -->
9+
This example is used to create, modify, query, and delete an account for an ApsaraDB RDS for PostgreSQL instance on Alibaba Cloud.
10+
This example is from [Manage an RDS account](http://help.aliyun.com/document_detail/456029.htm).
11+
<!-- DOCS_DESCRIPTION_EN -->
12+
13+
<!-- BEGIN_TF_DOCS -->
14+
## Providers
15+
16+
| Name | Version |
17+
|------|---------|
18+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
19+
20+
## Modules
21+
22+
No modules.
23+
24+
## Resources
25+
26+
| Name | Type |
27+
|------|------|
28+
| [alicloud_db_account.account](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_account) | resource |
29+
| [alicloud_db_instance.instance](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_instance) | resource |
30+
| [alicloud_vpc.main](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
31+
| [alicloud_vswitch.main](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
32+
| [alicloud_rds_accounts.queryaccounts](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/rds_accounts) | data source |
33+
34+
## Inputs
35+
36+
| Name | Description | Type | Default | Required |
37+
|------|-------------|------|---------|:--------:|
38+
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | n/a | `string` | `"pg.n2.2c.2m"` | no |
39+
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `"cn-hangzhou"` | no |
40+
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | n/a | `string` | `"cn-hangzhou-b"` | no |
41+
<!-- END_TF_DOCS -->
42+
## Documentation
43+
<!-- docs-link -->
44+
45+
The template is based on Aliyun document: [Manage RDS account](http://help.aliyun.com/document_detail/456029.htm)
46+
47+
<!-- docs-link -->
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
# 如果不需要创建VPC和交换机,使用已有的VPC和交换机
40+
# vswitch_id = "vsw-****"
41+
# 创建多个配置相同的RDS PostgreSQL实例,x为需要创建的实例数量
42+
#count = x
43+
}
44+
45+
# 创建账号
46+
resource "alicloud_db_account" "account" {
47+
db_instance_id = alicloud_db_instance.instance.id
48+
account_name = "tf_account_test"
49+
account_password = "Test123@rds"
50+
}
51+
52+
# 查询账号
53+
data "alicloud_rds_accounts" "queryaccounts" {
54+
depends_on = [alicloud_db_account.account]
55+
db_instance_id = alicloud_db_instance.instance.id
56+
}
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)