Skip to content

Commit e79b65f

Browse files
Rich-yixiaozhu36
authored andcommitted
Add redis module
1 parent b19af89 commit e79b65f

22 files changed

+1141
-1
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,17 @@ override.tf.json
2727

2828
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
2929
# example: *tfplan*
30+
31+
# terraform log
32+
*.log
33+
34+
# auto-generated key pair file
35+
*.pem
36+
37+
# tools files
38+
.DS_Store
39+
.idea
40+
41+
# others
42+
*.bak
43+
*.bk

README-CN.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
Terraform module which creates redis instnace and other resources on Alibaba Cloud
2+
# terraform-alicloud-redis
3+
=====================================================================
4+
5+
6+
本 Module 用于在阿里云的 VPC 下创建一个[Redis云数据库](https://help.aliyun.com/document_detail/26342.html).
7+
8+
本 Module 支持创建以下资源:
9+
10+
* [Redis 数据库实例_(redis_instance)](https://www.terraform.io/docs/providers/alicloud/d/kvstore_instances.html)
11+
* [Redis 数据库实例的备份策略_(redis_backup_policy)](https://www.terraform.io/docs/providers/alicloud/r/kvstore_backup_policy.html)
12+
* [Redis 数据库的账号_(redis_account)](https://www.terraform.io/docs/providers/alicloud/r/kvstore_account.html)
13+
14+
## Terraform 版本
15+
16+
本模板要求使用版本 Terraform 0.12。
17+
18+
## 用法
19+
20+
```hcl
21+
module "redis_example" {
22+
source = "terraform-alicloud-modules/redis/alicloud/"
23+
#################
24+
# Redis Instance
25+
#################
26+
engine = "Redis"
27+
engine_version = "5.0"
28+
region = "cn-beijing"
29+
instance_name = "myInstance"
30+
instance_class = "redis.master.mid.default"
31+
period = 1
32+
vswitch_id = "vsw-bp1tili2u5kpgdk84osjk"
33+
security_ips = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
34+
availability_zone = "cn-beijing-f"
35+
vswitch_id = "vsw-2zeuq8sx0ikfj73ev2iah"
36+
security_ips = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
37+
instance_charge_type = "PostPaid"
38+
tags = {
39+
Env = "Private"
40+
Location = "Secret"
41+
}
42+
43+
#################
44+
# Redis Accounts
45+
#################
46+
47+
accounts = [
48+
{
49+
account_name = "user1"
50+
account_password = "plan111111"
51+
account_privilege = "RoleReadOnly"
52+
account_type = "Normal"
53+
},
54+
{
55+
account_name = "user2"
56+
account_password = "plan222222"
57+
},
58+
]
59+
60+
#####################
61+
# Redis backup_policy
62+
#####################
63+
64+
backup_policy_backup_time = "02:00Z-03:00Z"
65+
backup_policy_backup_period = ["Monday", "Wednesday", "Friday"]
66+
}
67+
```
68+
69+
## 示例
70+
71+
* [Redis 实例完整创建示例创建示例](https://github.com/terraform-alicloud-modules/terraform-alicloud-redis/tree/master/examples/redis)
72+
73+
## 注意事项
74+
75+
* 本 Module 使用的 AccessKey 和 SecretKey 可以直接从 `profile``shared_credentials_file` 中获取。如果未设置,可通过下载安装 [aliyun-cli](https://github.com/aliyun/aliyun-cli#installation) 后进行配置.
76+
77+
作者
78+
-------
79+
Created and maintained by Yi Jincheng(yi785301535@163.com)
80+
81+
许可
82+
----
83+
Apache 2 Licensed. See LICENSE for full details.
84+
85+
参考
86+
---------
87+
* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud)
88+
* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/)
89+
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)
90+
91+

README.md

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,98 @@
1-
# terraform-alicloud-redis
21
Terraform module which creates redis instnace and other resources on Alibaba Cloud
2+
# terraform-alicloud-redis
3+
=====================================================================
4+
5+
English | [简体中文](https://github.com/terraform-alicloud-modules/terraform-alicloud-redis/blob/master/README-CN.md)
6+
7+
Terraform module which creates Redis instnace and other resources on Alibaba Cloud
8+
9+
These types of resources are supported:
10+
11+
* [Alicloud_kvstore_instances](https://www.terraform.io/docs/providers/alicloud/d/kvstore_instances.html)
12+
* [Alicloud_kvstore_backup_policy](https://www.terraform.io/docs/providers/alicloud/r/kvstore_backup_policy.html)
13+
* [Alicloud_kvstore_account](https://www.terraform.io/docs/providers/alicloud/r/kvstore_account.html)
14+
15+
----------------------
16+
## Terraform versions
17+
18+
This module requires Terraform 0.12.
19+
20+
21+
Usage
22+
-----
23+
You can use this in your terraform template with the following steps.
24+
25+
1. Adding a module resource to your template, e.g. main.tf
26+
27+
```hcl
28+
module "redis_example" {
29+
source = "terraform-alicloud-modules/redis/alicloud/"
30+
#################
31+
# Redis Instance
32+
#################
33+
engine = "Redis"
34+
engine_version = "5.0"
35+
region = "cn-beijing"
36+
instance_name = "myInstance"
37+
instance_class = "redis.master.mid.default"
38+
period = 1
39+
vswitch_id = "vsw-bp1tili2u5kpgdk84osjk"
40+
security_ips = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
41+
availability_zone = "cn-beijing-f"
42+
vswitch_id = "vsw-2zeuq8sx0ikfj73ev2iah"
43+
security_ips = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
44+
instance_charge_type = "PostPaid"
45+
tags = {
46+
Env = "Private"
47+
Location = "Secret"
48+
}
49+
50+
#################
51+
# Redis Accounts
52+
#################
53+
54+
accounts = [
55+
{
56+
account_name = "user1"
57+
account_password = "plan111111"
58+
account_privilege = "RoleReadOnly"
59+
account_type = "Normal"
60+
},
61+
{
62+
account_name = "user2"
63+
account_password = "plan222222"
64+
},
65+
]
66+
67+
#################
68+
# Redis backup_policy
69+
#################
70+
71+
backup_policy_backup_time = "02:00Z-03:00Z"
72+
backup_policy_backup_period = ["Monday", "Wednesday", "Friday"]
73+
}
74+
```
75+
## Examples
76+
77+
* [Redis example](https://github.com/terraform-alicloud-modules/terraform-alicloud-redis/tree/master/examples/redis)
78+
79+
## Notes
80+
81+
* This module using AccessKey and SecretKey are from `profile` and `shared_credentials_file`.
82+
If you have not set them yet, please install [aliyun-cli](https://github.com/aliyun/aliyun-cli#installation) and configure it.
83+
84+
85+
Authors
86+
---------
87+
Created and maintained by Yi Jincheng(yi785301535@163.com)
88+
89+
License
90+
----
91+
Apache 2 Licensed. See LICENSE for full details.
92+
93+
Reference
94+
---------
95+
* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud)
96+
* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/)
97+
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)
98+

examples/redis/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 Redis
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 -->

examples/redis/main.tf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
variable "region" {
2+
default = "cn-beijing"
3+
}
4+
provider "alicloud" {
5+
region = var.region
6+
}
7+
data "alicloud_vpcs" "default" {
8+
is_default = true
9+
}
10+
data "alicloud_zones" "default" {
11+
available_resource_creation = "KVStore"
12+
multi = true
13+
enable_details = true
14+
}
15+
resource "alicloud_vswitch" "this" {
16+
name = "redis_vpc"
17+
availability_zone = data.alicloud_zones.default.zones.0.multi_zone_ids.0
18+
vpc_id = data.alicloud_vpcs.default.vpcs.0.id
19+
cidr_block = cidrsubnet(data.alicloud_vpcs.default.vpcs.0.cidr_block, 4, 2)
20+
}
21+
module "redis_example" {
22+
source = "../../modules/redis"
23+
region = var.region
24+
25+
#################
26+
# Redis Instance
27+
#################
28+
29+
instance_name = "myInstance"
30+
instance_class = "redis.master.mid.default"
31+
period = 1
32+
availability_zone = data.alicloud_zones.default.zones.0.multi_zone_ids.0
33+
vswitch_id = alicloud_vswitch.this.id
34+
security_ips = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
35+
tags = {
36+
Env = "Private"
37+
Location = "Secret"
38+
}
39+
40+
#################
41+
# Redis backup_policy
42+
#################
43+
44+
backup_policy_backup_time = "02:00Z-03:00Z"
45+
backup_policy_backup_period = ["Monday", "Wednesday", "Friday"]
46+
47+
#################
48+
# Redis account
49+
#################
50+
51+
accounts = [
52+
{
53+
account_name = "user1"
54+
account_password = "plan111111"
55+
account_privilege = "RoleReadOnly"
56+
account_type = "Normal"
57+
},
58+
{
59+
account_name = "user2"
60+
account_password = "plan222222"
61+
},
62+
]
63+
}

0 commit comments

Comments
 (0)