Skip to content

Commit 2b71317

Browse files
committed
Postgresql RDS query configurations
1 parent a02edbd commit 2b71317

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Introduction
2+
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
本示例用于在阿里云查询RDS PostgreSQL实例的相关配置,涉及到专有网络VPC,交换机,RDS PostgreSQL实例的创建,与实例可用区资源,可购买的实例规格,实例地域信息,实例列表等资源的查询。
5+
本示例来自[通过 Terraform 查询实例相关配置](http://help.aliyun.com/document_detail/456026.htm)
6+
<!-- DOCS_DESCRIPTION_CN -->
7+
8+
<!-- DOCS_DESCRIPTION_EN -->
9+
This example is used to to query the configurations of an ApsaraDB RDS for PostgreSQL instance on Alibaba Cloud, which involves the creation of resources such as Virtual Private Cloud, virtual Switches,ApsaraDB RDS for PostgreSQL instance,and the query of instance resources such as instance zones resources, purchasable instance specifications, instance region information, instance lists, etc.
10+
This example is from [Query instance configurations](http://help.aliyun.com/document_detail/456026.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_instance.instance](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_instance) | resource |
29+
| [alicloud_vpc.main](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
30+
| [alicloud_vswitch.main](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
31+
| [alicloud_db_instance_classes.queryclasses](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/db_instance_classes) | data source |
32+
| [alicloud_db_instances.queryinstance](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/db_instances) | data source |
33+
| [alicloud_db_instances.queryinstances](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/db_instances) | data source |
34+
| [alicloud_db_zones.queryzones](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/db_zones) | data source |
35+
| [alicloud_regions.query_regions](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/regions) | data source |
36+
37+
## Inputs
38+
39+
| Name | Description | Type | Default | Required |
40+
|------|-------------|------|---------|:--------:|
41+
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | n/a | `string` | `"pg.n2.2c.2m"` | no |
42+
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `"cn-hangzhou"` | no |
43+
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | n/a | `string` | `"cn-hangzhou-b"` | no |
44+
<!-- END_TF_DOCS -->
45+
## Documentation
46+
<!-- docs-link -->
47+
48+
The template is based on Aliyun document: [Postgresql RDS query configurations](http://help.aliyun.com/document_detail/456026.htm)
49+
50+
<!-- docs-link -->
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
41+
# 查询可用区资源
42+
data "alicloud_db_zones" "queryzones" {
43+
instance_charge_type = "PostPaid"
44+
engine = "PostgreSQL"
45+
db_instance_storage_type = "cloud_essd"
46+
}
47+
48+
# 询可购买的实例规格
49+
data "alicloud_db_instance_classes" "queryclasses" {
50+
instance_charge_type = "PostPaid"
51+
engine = "PostgreSQL"
52+
db_instance_storage_type = "cloud_essd"
53+
}
54+
55+
# 查询地域信息
56+
data "alicloud_regions" "query_regions" {
57+
}
58+
59+
# 查询实例列表
60+
data "alicloud_db_instances" "queryinstances" {
61+
}
62+
63+
# 查询指定实例
64+
data "alicloud_db_instances" "queryinstance" {
65+
ids = [alicloud_db_instance.instance.id]
66+
# 查询指定地域(环境变量中设置的地域)下所有实例
67+
# ids = []
68+
engine = "PostgreSQL"
69+
}
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)