Skip to content

Commit cc74c03

Browse files
authored
feat:support database_net_env when the access type is ccn. (#2201)
* feat:support database_net_env when the access type is ccn. * add changelog * adjust e2e case * adjust e2e
1 parent 9fba0c9 commit cc74c03

File tree

4 files changed

+331
-53
lines changed

4 files changed

+331
-53
lines changed

.changelog/2201.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_dts_sync_config: Support `database_net_env` field when the access type is ccn.
3+
```

tencentcloud/resource_tc_dts_sync_config.go

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Provides a resource to create a dts sync_config
33
44
Example Usage
55
6+
Sync mysql database to cynosdb through cdb access type
7+
68
```hcl
79
resource "tencentcloud_cynosdb_cluster" "foo" {
810
available_zone = var.availability_zone
@@ -90,7 +92,7 @@ resource "tencentcloud_dts_sync_config" "sync_config" {
9092
src_info {
9193
region = "ap-guangzhou"
9294
instance_id = "cdb-fitq5t9h"
93-
user = "keep_dts"
95+
user = "your_user_name"
9496
password = "*"
9597
db_name = "tf_ci_test"
9698
vpc_id = local.vpc_id
@@ -109,6 +111,85 @@ resource "tencentcloud_dts_sync_config" "sync_config" {
109111
}
110112
```
111113
114+
Sync mysql database using CCN to route from ap-shanghai to ap-guangzhou
115+
116+
```hcl
117+
locals {
118+
vpc_id_sh = "vpc-evtcyb3g"
119+
subnet_id_sh = "subnet-1t83cxkp"
120+
src_ip = data.tencentcloud_mysql_instance.src_mysql.instance_list.0.intranet_ip
121+
src_port = data.tencentcloud_mysql_instance.src_mysql.instance_list.0.intranet_port
122+
ccn_id = data.tencentcloud_ccn_instances.ccns.instance_list.0.ccn_id
123+
dst_mysql_id = data.tencentcloud_mysql_instance.dst_mysql.instance_list.0.mysql_id
124+
}
125+
126+
variable "src_az_sh" {
127+
default = "ap-shanghai"
128+
}
129+
130+
variable "dst_az_gz" {
131+
default = "ap-guangzhou"
132+
}
133+
134+
data "tencentcloud_dts_sync_jobs" "sync_jobs" {
135+
job_name = "keep_sync_config_ccn_2_cdb"
136+
}
137+
138+
data "tencentcloud_ccn_instances" "ccns" {
139+
name = "keep-ccn-dts-sh"
140+
}
141+
142+
data "tencentcloud_mysql_instance" "src_mysql" {
143+
instance_name = "your_user_name_mysql_src"
144+
}
145+
146+
data "tencentcloud_mysql_instance" "dst_mysql" {
147+
instance_name = "your_user_name_mysql_src"
148+
}
149+
150+
resource "tencentcloud_dts_sync_config" "sync_config" {
151+
job_id = data.tencentcloud_dts_sync_jobs.sync_jobs.list.0.job_id
152+
src_access_type = "ccn"
153+
dst_access_type = "cdb"
154+
155+
job_mode = "liteMode"
156+
run_mode = "Immediate"
157+
158+
objects {
159+
mode = "Partial"
160+
databases {
161+
db_name = "tf_ci_test"
162+
new_db_name = "tf_ci_test_new"
163+
db_mode = "Partial"
164+
table_mode = "All"
165+
tables {
166+
table_name = "test"
167+
new_table_name = "test_new"
168+
}
169+
}
170+
}
171+
src_info { // shanghai to guangzhou via ccn
172+
region = var.src_az_sh
173+
user = "your_user_name"
174+
password = "your_pass_word"
175+
ip = local.src_ip
176+
port = local.src_port
177+
vpc_id = local.vpc_id_sh
178+
subnet_id = local.subnet_id_sh
179+
ccn_id = local.ccn_id
180+
database_net_env = "TencentVPC"
181+
}
182+
dst_info {
183+
region = var.dst_az_gz
184+
instance_id = local.dst_mysql_id
185+
user = "your_user_name"
186+
password = "your_pass_word"
187+
}
188+
auto_retry_time_range_minutes = 0
189+
}
190+
191+
````
192+
112193
Import
113194
114195
dts sync_config can be imported using the id, e.g.
@@ -436,6 +517,7 @@ func resourceTencentCloudDtsSyncConfig() *schema.Resource {
436517

437518
"job_name": {
438519
Optional: true,
520+
Computed: true,
439521
Type: schema.TypeString,
440522
Description: "Sync job name.",
441523
},
@@ -594,6 +676,11 @@ func resourceTencentCloudDtsSyncConfig() *schema.Resource {
594676
Optional: true,
595677
Description: "Whether to use encrypted transmission, UnEncrypted means not to use encrypted transmission, Encrypted means to use encrypted transmission, the default is UnEncrypted. Note: This field may return null, indicating that no valid value can be obtained.",
596678
},
679+
"database_net_env": {
680+
Type: schema.TypeString,
681+
Optional: true,
682+
Description: "The network environment to which the database belongs. It is required when AccessType is Cloud Network (CCN). `UserIDC` represents the user IDC. `TencentVPC` represents Tencent Cloud VPC. Note: This field may return null, indicating that no valid value can be obtained.",
683+
},
597684
},
598685
},
599686
},
@@ -733,6 +820,11 @@ func resourceTencentCloudDtsSyncConfig() *schema.Resource {
733820
Optional: true,
734821
Description: "Whether to use encrypted transmission, UnEncrypted means not to use encrypted transmission, Encrypted means to use encrypted transmission, the default is UnEncrypted. Note: This field may return null, indicating that no valid value can be obtained.",
735822
},
823+
"database_net_env": {
824+
Type: schema.TypeString,
825+
Optional: true,
826+
Description: "The network environment to which the database belongs. It is required when AccessType is Cloud Network (CCN). `UserIDC` represents the user IDC. `TencentVPC` represents Tencent Cloud VPC. Note: This field may return null, indicating that no valid value can be obtained.",
827+
},
736828
},
737829
},
738830
},
@@ -1107,6 +1199,10 @@ func resourceTencentCloudDtsSyncConfigRead(d *schema.ResourceData, meta interfac
11071199
srcInfoMap["encrypt_conn"] = syncConfig.SrcInfo.EncryptConn
11081200
}
11091201

1202+
if syncConfig.SrcInfo.DatabaseNetEnv != nil {
1203+
srcInfoMap["database_net_env"] = syncConfig.SrcInfo.DatabaseNetEnv
1204+
}
1205+
11101206
// reset the password due to the describe api always return an empty string
11111207
password := syncConfig.SrcInfo.Password
11121208
if password != nil && *password != "" {
@@ -1558,6 +1654,9 @@ func resourceTencentCloudDtsSyncConfigUpdate(d *schema.ResourceData, meta interf
15581654
if v, ok := dMap["encrypt_conn"]; ok {
15591655
endpoint.EncryptConn = helper.String(v.(string))
15601656
}
1657+
if v, ok := dMap["database_net_env"]; ok {
1658+
endpoint.DatabaseNetEnv = helper.String(v.(string))
1659+
}
15611660
request.SrcInfo = &endpoint
15621661
}
15631662
}
@@ -1640,6 +1739,9 @@ func resourceTencentCloudDtsSyncConfigUpdate(d *schema.ResourceData, meta interf
16401739
if v, ok := dMap["encrypt_conn"]; ok {
16411740
endpoint.EncryptConn = helper.String(v.(string))
16421741
}
1742+
if v, ok := dMap["database_net_env"]; ok {
1743+
endpoint.DatabaseNetEnv = helper.String(v.(string))
1744+
}
16431745
request.DstInfo = &endpoint
16441746
}
16451747
}

tencentcloud/resource_tc_dts_sync_config_test.go

Lines changed: 142 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -62,53 +62,65 @@ func TestAccTencentCloudDtsSyncConfigResource_basic(t *testing.T) {
6262
})
6363
}
6464

65+
func TestAccTencentCloudDtsSyncConfigResource_ccn(t *testing.T) {
66+
t.Parallel()
67+
resource.Test(t, resource.TestCase{
68+
PreCheck: func() {
69+
testAccPreCheck(t)
70+
},
71+
Providers: testAccProviders,
72+
Steps: []resource.TestStep{
73+
{
74+
Config: testAccDtsSyncConfig_ccn,
75+
Check: resource.ComposeTestCheckFunc(
76+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "id"),
77+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "src_access_type", "ccn"),
78+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "dst_access_type", "cdb"),
79+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "job_name"),
80+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "job_mode", "liteMode"),
81+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "run_mode", "Immediate"),
82+
// objects
83+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.#", "1"),
84+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.mode", "Partial"),
85+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.databases.#", "1"),
86+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.databases.0.db_name", "tf_ci_test"),
87+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.databases.0.new_db_name", "tf_ci_test_new"),
88+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.databases.0.db_mode", "Partial"),
89+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.databases.0.table_mode", "All"),
90+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.databases.0.tables.#", "1"),
91+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.databases.0.tables.0.table_name", "test"),
92+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "objects.0.databases.0.tables.0.new_table_name", "test_new"),
93+
// src_info dest_info
94+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "src_info.#", "1"),
95+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "src_info.0.region", "ap-shanghai"),
96+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "src_info.0.user"),
97+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "src_info.0.password"),
98+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "src_info.0.ip"),
99+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "src_info.0.port"),
100+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "src_info.0.vpc_id"),
101+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "src_info.0.subnet_id"),
102+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "src_info.0.ccn_id"),
103+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "src_info.0.database_net_env", "TencentVPC"),
104+
105+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "dst_info.#", "1"),
106+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "dst_info.0.region", "ap-guangzhou"),
107+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "dst_info.0.instance_id"),
108+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "dst_info.0.user"),
109+
resource.TestCheckResourceAttrSet("tencentcloud_dts_sync_config.sync_config", "dst_info.0.password"),
110+
111+
resource.TestCheckResourceAttr("tencentcloud_dts_sync_config.sync_config", "auto_retry_time_range_minutes", "0"),
112+
),
113+
},
114+
{
115+
ResourceName: "tencentcloud_dts_sync_config.sync_config",
116+
ImportState: true,
117+
},
118+
},
119+
})
120+
}
121+
65122
const testAccDtsSyncConfig = testAccDtsMigrateJob_vpc_config + `
66-
resource "tencentcloud_cynosdb_cluster" "foo" {
67-
available_zone = var.availability_zone
68-
vpc_id = local.vpc_id
69-
subnet_id = local.subnet_id
70-
db_type = "MYSQL"
71-
db_version = "5.7"
72-
storage_limit = 1000
73-
cluster_name = "tf-cynosdb-mysql-sync-dst"
74-
password = "cynos@123"
75-
instance_maintain_duration = 3600
76-
instance_maintain_start_time = 10800
77-
instance_maintain_weekdays = [
78-
"Fri",
79-
"Mon",
80-
"Sat",
81-
"Sun",
82-
"Thu",
83-
"Wed",
84-
"Tue",
85-
]
86-
87-
instance_cpu_core = 1
88-
instance_memory_size = 2
89-
param_items {
90-
name = "character_set_server"
91-
current_value = "utf8"
92-
}
93-
param_items {
94-
name = "time_zone"
95-
current_value = "+09:00"
96-
}
97-
param_items {
98-
name = "lower_case_table_names"
99-
current_value = "1"
100-
}
101-
102-
force_delete = true
103-
104-
rw_group_sg = [
105-
local.sg_id
106-
]
107-
ro_group_sg = [
108-
local.sg_id
109-
]
110-
prarm_template_id = var.my_param_template
111-
}
123+
112124
113125
resource "tencentcloud_dts_sync_job" "sync_job" {
114126
pay_mode = "PostPay"
@@ -157,14 +169,93 @@ resource "tencentcloud_dts_sync_config" "sync_config" {
157169
}
158170
dst_info {
159171
region = "ap-guangzhou"
160-
instance_id = tencentcloud_cynosdb_cluster.foo.id
161-
user = "root"
162-
password = "cynos@123"
172+
instance_id = "cynosdbmysql-bws8h88b"
173+
user = "keep_dts"
174+
password = "Letmein123"
163175
db_name = "tf_ci_test_new"
164-
vpc_id = local.vpc_id
165-
subnet_id = local.subnet_id
176+
vpc_id = "vpc-pewdpc0d"
177+
subnet_id = "subnet-driddx4g"
178+
}
179+
auto_retry_time_range_minutes = 0
180+
}
181+
182+
`
183+
184+
const testAccDtsSyncConfig_ccn = `
185+
186+
locals {
187+
vpc_id_sh = "vpc-evtcyb3g"
188+
subnet_id_sh = "subnet-1t83cxkp"
189+
src_ip = data.tencentcloud_mysql_instance.src_mysql.instance_list.0.intranet_ip
190+
src_port = data.tencentcloud_mysql_instance.src_mysql.instance_list.0.intranet_port
191+
ccn_id = data.tencentcloud_ccn_instances.ccns.instance_list.0.ccn_id
192+
dst_mysql_id = data.tencentcloud_mysql_instance.dst_mysql.instance_list.0.mysql_id
193+
}
194+
195+
variable "src_az_sh" {
196+
default = "ap-shanghai"
197+
}
198+
199+
variable "dst_az_gz" {
200+
default = "ap-guangzhou"
201+
}
202+
203+
data "tencentcloud_dts_sync_jobs" "sync_jobs" {
204+
job_name = "keep_sync_config_ccn_2_cdb"
205+
}
206+
207+
data "tencentcloud_ccn_instances" "ccns" {
208+
name = "keep-ccn-dts-sh"
209+
}
210+
211+
data "tencentcloud_mysql_instance" "src_mysql" {
212+
instance_name = "keep_dts_mysql_src"
213+
}
214+
215+
data "tencentcloud_mysql_instance" "dst_mysql" {
216+
instance_name = "keep_dts_mysql_src"
217+
}
218+
219+
resource "tencentcloud_dts_sync_config" "sync_config" {
220+
job_id = data.tencentcloud_dts_sync_jobs.sync_jobs.list.0.job_id
221+
src_access_type = "ccn"
222+
dst_access_type = "cdb"
223+
224+
job_mode = "liteMode"
225+
run_mode = "Immediate"
226+
227+
objects {
228+
mode = "Partial"
229+
databases {
230+
db_name = "tf_ci_test"
231+
new_db_name = "tf_ci_test_new"
232+
db_mode = "Partial"
233+
table_mode = "All"
234+
tables {
235+
table_name = "test"
236+
new_table_name = "test_new"
237+
}
238+
}
239+
}
240+
src_info { // shanghai to guangzhou via ccn
241+
region = var.src_az_sh
242+
user = "keep_dts"
243+
password = "Letmein123"
244+
ip = local.src_ip
245+
port = local.src_port
246+
vpc_id = local.vpc_id_sh
247+
subnet_id = local.subnet_id_sh
248+
ccn_id = local.ccn_id
249+
database_net_env = "TencentVPC"
250+
}
251+
dst_info {
252+
region = var.dst_az_gz
253+
instance_id = local.dst_mysql_id
254+
user = "keep_dts"
255+
password = "Letmein123"
166256
}
167257
auto_retry_time_range_minutes = 0
168258
}
169259
260+
170261
`

0 commit comments

Comments
 (0)