Skip to content

Commit 3eb0252

Browse files
吕戈xiaozhu36
authored andcommitted
add Terraform ADB module
1 parent 3229793 commit 3eb0252

File tree

13 files changed

+432
-2
lines changed

13 files changed

+432
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- **NEW:** `adb` [GH-1]( https://github.com/terraform-alicloud-modules/terraform-alicloud-analyticdb-mysql/pull/1)
2+

README-CN.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Terraform module which creates ADB cluster resources on Alibaba Cloud
2+
terraform-alicloud-analyticdb-mysql
3+
=====================================================================
4+
5+
6+
本 Module 用于在阿里云的 VPC 下创建一个[ADB 云数据库](https://help.aliyun.com/product/92664.html)
7+
8+
本 Module 支持创建以下资源:
9+
10+
* [ADB 数据库实例 (adb cluster)](https://www.terraform.io/docs/providers/alicloud/r/adb_cluster.html)
11+
12+
## Terraform 版本
13+
14+
本模版要求使用 Terraform 0.12 和阿里云 Provider 1.71.0+。
15+
16+
## 用法
17+
-----
18+
### 你可以通过以下步骤增加terraform模板。
19+
20+
增加module资源到你的模板文件,例如main.tf
21+
22+
```hcl
23+
module "adb" {
24+
source = "terraform-alicloud-modules/adb/alicloud"
25+
profile = "Your-Profile-Name"
26+
region = "cn-shenzhen"
27+
#################
28+
# ADB Cluster
29+
#################
30+
db_cluster_version = "3.0"
31+
db_cluster_category = "Cluster"
32+
db_node_class = "C8"
33+
db_node_count = 2
34+
db_node_storage = 200
35+
pay_type = "PostPaid"
36+
vswitch_id = "vsw-wz9dtqayzctoqh*******"
37+
description = "tf-module-adb"
38+
availability_zone = "cn-shenzhen-e"
39+
}
40+
```
41+
42+
## 示例
43+
44+
* [ADB实例创建示例](https://github.com/terraform-alicloud-modules/terraform-alicloud-analyticdb-mysql/tree/master/examples/complete)
45+
46+
## 注意事项
47+
48+
* 本 Module 使用的 AccessKey 和 SecretKey 可以直接从 `profile``shared_credentials_file` 中获取。如果未设置,可通过下载安装 [aliyun-cli](https://github.com/aliyun/aliyun-cli#installation) 后进行配置。
49+
50+
提交问题
51+
-------
52+
如果在使用该 Terraform Module 的过程中有任何问题,可以直接创建一个 [Provider Issue](https://github.com/terraform-providers/terraform-provider-alicloud/issues/new),我们将根据问题描述提供解决方案。
53+
54+
**注意:** 不建议在该 Module 仓库中直接提交 Issue。
55+
56+
作者
57+
-------
58+
Created and maintained by quanyun.
59+
60+
许可
61+
----
62+
Apache 2 Licensed. See LICENSE for full details.
63+
64+
参考
65+
---------
66+
* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud)
67+
* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/)
68+
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)
69+
70+

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,72 @@
1-
# terraform-alicloud-analyticdb-mysql
2-
Terraform module for creating Analyticdb MySQL on Alibaba Cloud.
1+
Terraform module which creates a ADB cluster on Alibaba Cloud.
2+
terraform-alicloud-analyticdb-mysql
3+
=====================================================================
4+
5+
English | [简体中文](https://github.com/terraform-alicloud-modules/terraform-alicloud-analyticdb-mysql/blob/master/README-CN.md)
6+
7+
Terraform module which creates ADB cluster resources on Alibaba Cloud
8+
9+
These types of resources are supported:
10+
11+
* [Alicloud adb cluster](https://www.terraform.io/docs/providers/alicloud/r/adb_cluster.html)
12+
13+
----------------------
14+
15+
## Terraform versions
16+
17+
This module requires Terraform 0.12 and Terraform Provider AliCloud 1.71.0+.
18+
19+
## Usage
20+
-----
21+
### You can use this in your terraform template with the following steps.
22+
23+
Adding a module resource to your template, e.g. main.tf
24+
25+
```hcl
26+
module "adb" {
27+
source = "terraform-alicloud-modules/adb/alicloud"
28+
profile = "Your-Profile-Name"
29+
region = "cn-shenzhen"
30+
#################
31+
# ADB Cluster
32+
#################
33+
db_cluster_version = "3.0"
34+
db_cluster_category = "Cluster"
35+
db_node_class = "C8"
36+
db_node_count = 2
37+
db_node_storage = 200
38+
pay_type = "PostPaid"
39+
vswitch_id = "vsw-wz9dtqayzctoqh*******"
40+
description = "tf-module-adb"
41+
availability_zone = "cn-shenzhen-e"
42+
}
43+
```
44+
45+
## Examples
46+
47+
* [example](https://github.com/terraform-alicloud-modules/terraform-alicloud-analyticdb-mysql/tree/master/examples/complete)
48+
49+
## Notes
50+
51+
* This module using AccessKey and SecretKey are from `profile` and `shared_credentials_file`.
52+
If you have not set them yet, please install [aliyun-cli](https://github.com/aliyun/aliyun-cli#installation) and configure it.
53+
54+
Submit Issues
55+
-------------
56+
If you have any problems when using this module, please opening a [provider issue](https://github.com/terraform-providers/terraform-provider-alicloud/issues/new) and let us know.
57+
58+
**Note:** There does not recommend to open an issue on this repo.
59+
60+
Authors
61+
---------
62+
Created and maintained by quanyun.
63+
64+
License
65+
----
66+
Apache 2 Licensed. See LICENSE for full details.
67+
68+
Reference
69+
---------
70+
* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud)
71+
* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/)
72+
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)

examples/complete/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Complete ADB example
2+
3+
Configuration in this directory creates set of ADB resources including ADB cluster
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+

examples/complete/main.tf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
variable "region" {
2+
default = "cn-shenzhen"
3+
}
4+
5+
variable "profile" {
6+
default = "default"
7+
}
8+
9+
provider "alicloud" {
10+
region = var.region
11+
profile = var.profile
12+
}
13+
14+
data "alicloud_zones" "default" {
15+
available_resource_creation = "ADB"
16+
enable_details = true
17+
}
18+
19+
data "alicloud_vpcs" "default" {
20+
is_default = true
21+
}
22+
23+
data "alicloud_vswitches" "default" {
24+
vpc_id = data.alicloud_vpcs.default.ids.0
25+
zone_id = data.alicloud_zones.default.zones.0.id
26+
}
27+
28+
module "adb_example" {
29+
source = "../.."
30+
region = var.region
31+
description = "tf-module-adb-cluster-example"
32+
db_cluster_version = "3.0"
33+
db_cluster_category = "Cluster"
34+
db_node_class = "C8"
35+
db_node_count = 2
36+
db_node_storage = 200
37+
pay_type = "PostPaid"
38+
vswitch_id = data.alicloud_vswitches.default.ids.0
39+
availability_zone = data.alicloud_zones.default.zones.0.id
40+
}

examples/complete/output.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#################
2+
# ADB Cluster
3+
#################
4+
output "this_adb_cluster_id" {
5+
description = "The ID of the ADB cluster."
6+
value = module.adb_example.this_adb_cluster_id
7+
}
8+
9+
output "this_adb_description" {
10+
description = "The description of ADB cluster."
11+
value = module.adb_example.this_adb_description
12+
}
13+
14+
output "this_adb_cluster_zone_id" {
15+
description = "The Zone to launch the ADB cluster."
16+
value = module.adb_example.this_adb_cluster_zone_id
17+
}
18+
19+
output "this_adb_cluster_vswitch_id" {
20+
description = "The virtual switch ID to launch ADB cluster in one VPC. "
21+
value = module.adb_example.this_adb_cluster_vswitch_id
22+
}
23+
24+
output "this_adb_cluster_db_cluster_version" {
25+
description = "The version of the ADB cluster."
26+
value = module.adb_example.this_adb_cluster_db_cluster_version
27+
}
28+
29+
output "this_adb_cluster_db_cluster_category" {
30+
description = "The catrgory type of the ADB cluster. "
31+
value = module.adb_example.this_adb_cluster_db_cluster_category
32+
}
33+
34+
output "this_adb_cluster_db_node_count" {
35+
description = "The node count of the ADB cluster."
36+
value = module.adb_example.this_adb_cluster_db_node_count
37+
}
38+
39+
output "this_adb_cluster_db_node_class" {
40+
description = "The node class of the ADB cluster. "
41+
value = module.adb_example.this_adb_cluster_db_node_class
42+
}
43+
44+
output "this_adb_cluster_db_node_storage" {
45+
description = "The node storage of the ADB cluster."
46+
value = module.adb_example.this_adb_cluster_db_node_storage
47+
}
48+
49+
output "this_adb_cluster_pay_type" {
50+
description = "The pay type"
51+
value = module.adb_example.this_adb_cluster_pay_type
52+
}

examples/complete/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

locals.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
locals {
2+
# Get ID of ADB cluster
3+
this_cluster_id = var.existing_cluster_id != "" ? var.existing_cluster_id : concat(alicloud_adb_cluster.this.*.id, [""])[0]
4+
}

main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
provider "alicloud" {
2+
profile = var.profile != "" ? var.profile : null
3+
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
4+
region = var.region != "" ? var.region : null
5+
skip_region_validation = var.skip_region_validation
6+
configuration_source = "terraform-alicloud-modules/adb"
7+
}
8+
9+
resource "alicloud_adb_cluster" "this" {
10+
count = var.existing_cluster_id != "" ? 0 : var.create_cluster ? 1 : 0
11+
description = var.description
12+
zone_id = var.availability_zone
13+
db_cluster_version = var.db_cluster_version
14+
db_cluster_category = var.db_cluster_category
15+
db_node_class = var.db_node_class
16+
db_node_count = var.db_node_count
17+
db_node_storage = var.db_node_storage
18+
pay_type = var.pay_type
19+
vswitch_id = var.vswitch_id
20+
}
21+

0 commit comments

Comments
 (0)