Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions solution/tech-solution/rtsorarctebcc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Introduction
<!-- DOCS_DESCRIPTION_CN -->
本示例用于实现解决方案[RDS 到 Redis 实时同步方案](https://www.aliyun.com/solution/tech-solution/rtsorarctebcc), 涉及到涉及到专有网络(VPC)、交换机(VSwitch)、云数据库(RDS)MySQL版、云数据库 Tair(兼容 Redis)等资源的创建。
<!-- DOCS_DESCRIPTION_CN -->

<!-- DOCS_DESCRIPTION_EN -->
This example demonstrates the implementation of the solution [Real time synchronization solution from RDS to Redis](https://www.aliyun.com/solution/tech-solution/rtsorarctebcc). It involves the creation, configuration, and deployment of resources such as Virtual Private Cloud (VPC), VSwitch, Elastic Compute Service (ECS), ApsaraDB RDS, Tair (Redis OSS-compatible).
<!-- DOCS_DESCRIPTION_EN -->

<!-- BEGIN_TF_DOCS -->
## Providers

| Name | Version |
|------|---------|
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [alicloud_db_account.account](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_account) | resource |
| [alicloud_db_database.database](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_database) | resource |
| [alicloud_db_instance.rds](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_instance) | resource |
| [alicloud_dts_synchronization_instance.dts](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/dts_synchronization_instance) | resource |
| [alicloud_dts_synchronization_job.job](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/dts_synchronization_job) | resource |
| [alicloud_kvstore_instance.redis](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/kvstore_instance) | resource |
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
| [alicloud_vswitch.vswitch](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
| [alicloud_db_instance_classes.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/db_instance_classes) | data source |
| [alicloud_kvstore_zones.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/kvstore_zones) | data source |
| [alicloud_regions.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/regions) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_db_name"></a> [db\_name](#input\_db\_name) | RDS数据库名称。由2到16个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾。 | `string` | `"demodb"` | no |
| <a name="input_db_password"></a> [db\_password](#input\_db\_password) | RDS数据库密码,由字母、数字、下划线(\_)组成,长度为8~32个字符,必须包含3种不同类型的字符。 | `string` | n/a | yes |
| <a name="input_dts_job_name"></a> [dts\_job\_name](#input\_dts\_job\_name) | 同步任务名称。建议配置具有业务意义的名称(无唯一性要求),便于后续识别。 | `string` | `"mysql2redis_dts"` | no |
| <a name="input_rds_db_user"></a> [rds\_db\_user](#input\_rds\_db\_user) | RDS数据库账号。由2到16个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾。 | `string` | `"demouser123"` | no |
| <a name="input_redis_instance_class"></a> [redis\_instance\_class](#input\_redis\_instance\_class) | Tair规格。选择机型前请先确认当前可用区下该机型是否有库存,为节省测试成本,推荐使用2GB的规格,例如:tair.rdb.2g | `string` | `"tair.rdb.2g"` | no |
| <a name="input_redis_password"></a> [redis\_password](#input\_redis\_password) | 实例密码。长度8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()\_+-=) | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | 地域 | `string` | `"cn-hangzhou"` | no |
<!-- END_TF_DOCS -->
99 changes: 99 additions & 0 deletions solution/tech-solution/rtsorarctebcc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
locals {
db_name = "demodb"
dts_job_name = "mysql2redis_dts"
}

data "alicloud_regions" "default" {
current = true
}

data "alicloud_kvstore_zones" "default" {
instance_charge_type = "PostPaid"
engine = "Redis"
product_type = "OnECS"

}

data "alicloud_db_instance_classes" "default" {
zone_id = data.alicloud_kvstore_zones.default.zones.0.id
engine = "MySQL"
engine_version = "8.0"
instance_charge_type = "PostPaid"
category = "Basic"
db_instance_storage_type = "cloud_essd"
}
resource "alicloud_vpc" "vpc" {
cidr_block = "192.168.0.0/16"
}

resource "alicloud_vswitch" "vswitch" {
vpc_id = alicloud_vpc.vpc.id
cidr_block = "192.168.0.0/24"
zone_id = data.alicloud_kvstore_zones.default.zones.0.id
}

resource "alicloud_db_instance" "rds" {
engine = "MySQL"
engine_version = "8.0"
instance_type = data.alicloud_db_instance_classes.default.instance_classes.0.instance_class
instance_storage = 100
vswitch_id = alicloud_vswitch.vswitch.id
security_ips = ["192.168.0.0/16"]
category = "HighAvailability"
}

# 创建数据库账号
resource "alicloud_db_account" "account" {
db_instance_id = alicloud_db_instance.rds.id
account_name = var.rds_db_user
account_password = var.db_password
account_type = "Normal"
}

# 创建数据库
resource "alicloud_db_database" "database" {
instance_id = alicloud_db_instance.rds.id
name = local.db_name
character_set = "utf8mb4"
}

resource "alicloud_kvstore_instance" "redis" {
instance_class = var.redis_instance_class
vswitch_id = alicloud_vswitch.vswitch.id
security_ips = ["192.168.0.0/16"]
password = var.redis_password
engine_version = "6.0"
zone_id = data.alicloud_kvstore_zones.default.zones.0.id
}

resource "alicloud_dts_synchronization_instance" "dts" {
payment_type = "PayAsYouGo"
source_endpoint_engine_name = "MySQL"
destination_endpoint_engine_name = "Redis"
instance_class = "small"
source_endpoint_region = data.alicloud_regions.default.regions.0.id
destination_endpoint_region = data.alicloud_regions.default.regions.0.id
sync_architecture = "oneway"
}

resource "alicloud_dts_synchronization_job" "job" {
dts_instance_id = alicloud_dts_synchronization_instance.dts.id
dts_job_name = var.dts_job_name
source_endpoint_region = data.alicloud_regions.default.regions.0.id
source_endpoint_engine_name = "MySQL"
source_endpoint_instance_type = "RDS"
source_endpoint_instance_id = alicloud_db_instance.rds.id
source_endpoint_user_name = var.rds_db_user
source_endpoint_password = var.db_password
source_endpoint_database_name = local.db_name
destination_endpoint_engine_name = "REDIS"
destination_endpoint_instance_type = "REDIS"
destination_endpoint_instance_id = alicloud_kvstore_instance.redis.id
destination_endpoint_password = var.redis_password
db_list = jsonencode({
db_name = { name = local.db_name, all = true }
})
structure_initialization = false
data_initialization = true
data_synchronization = true
}
29 changes: 29 additions & 0 deletions solution/tech-solution/rtsorarctebcc/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "vpc_id" {
description = "VPC ID"
value = alicloud_vpc.vpc.id
}

output "vswitch_id" {
description = "VSwitch ID"
value = alicloud_vswitch.vswitch.id
}

output "rds_instance_id" {
description = "RDS Instance ID"
value = alicloud_db_instance.rds.id
}

output "redis_instance_id" {
description = "Redis Instance ID"
value = alicloud_kvstore_instance.redis.id
}

output "dts_instance_id" {
description = "DTS Instance ID"
value = alicloud_dts_synchronization_instance.dts.id
}

output "dts_job_id" {
description = "DTS Job ID"
value = alicloud_dts_synchronization_job.job.id
}
3 changes: 3 additions & 0 deletions solution/tech-solution/rtsorarctebcc/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "alicloud" {
region = var.region
}
49 changes: 49 additions & 0 deletions solution/tech-solution/rtsorarctebcc/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
variable "region" {
description = "地域"
type = string
default = "cn-hangzhou"
}

variable "rds_db_user" {
type = string
description = "RDS数据库账号。由2到16个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾。"
default = "demouser123"
validation {
condition = can(regex("^[a-z][a-z0-9_]{1,15}[a-z0-9]$", var.rds_db_user))
error_message = "由2到16个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾。"
}
}

variable "db_name" {
type = string
description = "RDS数据库名称。由2到16个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾。"
default = "demodb"
validation {
condition = can(regex("^[a-z][a-z0-9_]{1,15}[a-z0-9]$", var.db_name))
error_message = "由2到16个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾。"
}
}

variable "db_password" {
type = string
description = "RDS数据库密码,由字母、数字、下划线(_)组成,长度为8~32个字符,必须包含3种不同类型的字符。"
sensitive = true
}

variable "dts_job_name" {
type = string
description = "同步任务名称。建议配置具有业务意义的名称(无唯一性要求),便于后续识别。"
default = "mysql2redis_dts"
}

variable "redis_instance_class" {
type = string
description = "Tair规格。选择机型前请先确认当前可用区下该机型是否有库存,为节省测试成本,推荐使用2GB的规格,例如:tair.rdb.2g"
default = "tair.rdb.2g"
}

variable "redis_password" {
type = string
description = "实例密码。长度8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)"
sensitive = true
}
Loading