Skip to content

Commit 28f4a05

Browse files
authored
fix: tcr - block creating while replication region same with current (#1385)
* fix: tcr - block creating while replication region same with current * changelog 1385
1 parent 090824e commit 28f4a05

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

.changelog/1385.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_tcr_instance: fix: tcr - block creating while replication region same with current
3+
```

tencentcloud/extension_tcr.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,50 @@ const (
44
TCR_VPC_DNS_STATUS_ENABLED = "ENABLED"
55
TCR_VPC_DNS_STATUS_DISABLED = "DISABLED"
66
)
7+
8+
// FIXME: temp data, use api request instead if support
9+
var RegionIdMap = map[string]string{
10+
"ap-guangzhou": "1",
11+
"ap-shanghai": "4",
12+
"ap-hongkong": "5",
13+
"na-toronto": "6",
14+
"ap-shanghai-fsi": "7",
15+
"ap-beijing": "8",
16+
"ap-singapore": "9",
17+
"ap-shenzhen-fsi": "11",
18+
"ap-guangzhou-open": "12",
19+
"ap-shanghai-ysx": "13",
20+
"na-siliconvalley": "15",
21+
"ap-chengdu": "16",
22+
"eu-frankfurt": "17",
23+
"ap-seoul": "18",
24+
"ap-chongqing": "19",
25+
"ap-mumbai": "21",
26+
"na-ashburn": "22",
27+
"ap-bangkok": "23",
28+
"eu-moscow": "24",
29+
"ap-tokyo": "25",
30+
"ap-jinan-ec": "31",
31+
"ap-hangzhou-ec": "32",
32+
"ap-nanjing": "33",
33+
"ap-fuzhou-ec": "34",
34+
"ap-wuhan-ec": "35",
35+
"ap-tianjin": "36",
36+
"ap-shenzhen": "37",
37+
"ap-taipei": "39",
38+
"ap-changsha-ec": "45",
39+
"ap-beijing-fsi": "46",
40+
"ap-shijiazhuang-ec": "53",
41+
"ap-qingyuan": "54",
42+
"ap-hefei-ec": "55",
43+
"ap-shenyang-ec": "56",
44+
"ap-xian-ec": "57",
45+
"ap-xibei-ec": "58",
46+
"ap-zhengzhou-ec": "71",
47+
"ap-jakarta": "72",
48+
"ap-qingyuan-xinan": "73",
49+
"sa-saopaulo": "74",
50+
"ap-guiyang": "76",
51+
"ap-shenzhen-sycft": "77",
52+
"ap-shanghai-adc": "78",
53+
}

tencentcloud/resource_tc_tcr_instance.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ func resourceTencentCloudTcrInstanceCreate(d *schema.ResourceData, meta interfac
234234
return fmt.Errorf("`open_public_operation` must be `true` if `security_policy` set")
235235
}
236236

237+
// Check if replicas region same with current
238+
if v, ok := d.Get("replications").([]interface{}); ok {
239+
providerRegionId := RegionIdMap[client.Region]
240+
for i := range v {
241+
rep := v[i].(map[string]interface{})
242+
repRegion := fmt.Sprintf("%d", rep["region_id"].(int))
243+
if repRegion == providerRegionId {
244+
return fmt.Errorf("replication %s region is same with instance region %s (%s)", repRegion, providerRegionId, client.Region)
245+
}
246+
}
247+
}
248+
237249
outErr = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
238250
instanceId, inErr = tcrService.CreateTCRInstance(ctx, name, insType, map[string]string{})
239251
if inErr != nil {

0 commit comments

Comments
 (0)