Skip to content

Commit 201afe9

Browse files
tongyimingmikatong
andauthored
fix: tcaplusdb support tdr (#1263)
* fix: tcaplusdb support tdr * fix: tcaplusdb support tdr Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 460454d commit 201afe9

File tree

4 files changed

+117
-21
lines changed

4 files changed

+117
-21
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
data "tencentcloud_vpc_subnets" "gz3" {
2+
availability_zone = "ap-guangzhou-3"
3+
is_default = true
4+
}
5+
6+
locals {
7+
vpc_id = data.tencentcloud_vpc_subnets.gz3.instance_list.0.vpc_id
8+
subnet_id = data.tencentcloud_vpc_subnets.gz3.instance_list.0.subnet_id
9+
}
10+
11+
resource "tencentcloud_tcaplus_cluster" "foo" {
12+
idl_type = "TDR"
13+
cluster_name = "keep_tdr_tcaplus_cluster"
14+
vpc_id = local.vpc_id
15+
subnet_id = local.subnet_id
16+
password = "1qaA2k1wgvfa3ZZZ"
17+
old_password_expire_last = 3600
18+
}
19+
20+
resource "tencentcloud_tcaplus_tablegroup" "tablegroup" {
21+
cluster_id = tencentcloud_tcaplus_cluster.foo.id
22+
tablegroup_name = "keep_tdr_table_group"
23+
}

tencentcloud/basic_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ locals {
585585

586586
const defaultTcaPlusClusterName = "keep-tcaplus-cluster"
587587
const defaultTcaPlusClusterTableGroup = "keep_table_group"
588+
const defaultTcaPlusTdrClusterName = "keep_tdr_tcaplus_cluster"
589+
const defaultTcaPlusTdrClusterTableGroup = "keep_tdr_table_group"
588590
const defaultTcaPlusClusterTable = "keep_players"
589591
const defaultTcaPlusVar = `
590592
variable "tcaplus_cluster" {
@@ -598,6 +600,14 @@ variable "tcaplus_table_group" {
598600
variable "tcaplus_table" {
599601
default = "` + defaultTcaPlusClusterTable + `"
600602
}
603+
604+
variable "tcaplus_tcr_cluster" {
605+
default = "` + defaultTcaPlusTdrClusterName + `"
606+
}
607+
608+
variable "tcaplus_tcr_table_group" {
609+
default = "` + defaultTcaPlusTdrClusterTableGroup + `"
610+
}
601611
`
602612
const defaultTcaPlusData = defaultTcaPlusVar + `
603613
data "tencentcloud_tcaplus_clusters" "tcaplus" {
@@ -609,10 +619,21 @@ data "tencentcloud_tcaplus_tablegroups" "group" {
609619
tablegroup_name = var.tcaplus_table_group
610620
}
611621
622+
data "tencentcloud_tcaplus_clusters" "tdr_tcaplus" {
623+
cluster_name = "keep_tdr_tcaplus_cluster"
624+
}
625+
626+
data "tencentcloud_tcaplus_tablegroups" "tdr_group" {
627+
cluster_id = data.tencentcloud_tcaplus_clusters.tdr_tcaplus.list.0.cluster_id
628+
tablegroup_name = "keep_tdr_table_group"
629+
}
630+
612631
locals {
613632
tcaplus_id = data.tencentcloud_tcaplus_clusters.tcaplus.list.0.cluster_id
633+
tcr_tcaplus_id = data.tencentcloud_tcaplus_clusters.tdr_tcaplus.list.0.cluster_id
614634
tcaplus_table_group = var.tcaplus_table_group
615635
tcaplus_table_group_id = data.tencentcloud_tcaplus_tablegroups.group.list.0.tablegroup_id
636+
tcr_tcaplus_table_group_id = data.tencentcloud_tcaplus_tablegroups.tdr_group.list.0.tablegroup_id
616637
tcaplus_table = var.tcaplus_table
617638
}
618639
`

tencentcloud/resource_tc_tcaplus_idl.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ func resourceTencentCloudTcaplusIdlCreate(d *schema.ResourceData, meta interface
230230
tableInfos = append(tableInfos, infoMap)
231231
continue
232232
}
233-
infoMap["key_fields"] = *tableInfo.KeyFields
234-
infoMap["sum_key_field_size"] = *tableInfo.SumKeyFieldSize
235-
infoMap["value_fields"] = *tableInfo.ValueFields
236-
infoMap["sum_value_field_size"] = *tableInfo.SumValueFieldSize
237-
infoMap["index_key_set"] = *tableInfo.IndexKeySet
238-
infoMap["table_name"] = *tableInfo.TableName
233+
infoMap["key_fields"] = tableInfo.KeyFields
234+
infoMap["sum_key_field_size"] = tableInfo.SumKeyFieldSize
235+
infoMap["value_fields"] = tableInfo.ValueFields
236+
infoMap["sum_value_field_size"] = tableInfo.SumValueFieldSize
237+
infoMap["index_key_set"] = tableInfo.IndexKeySet
238+
infoMap["table_name"] = tableInfo.TableName
239239
tableInfos = append(tableInfos, infoMap)
240240
}
241241

@@ -293,12 +293,12 @@ func resourceTencentCloudTcaplusIdlRead(d *schema.ResourceData, meta interface{}
293293
tableInfos = append(tableInfos, infoMap)
294294
continue
295295
}
296-
infoMap["key_fields"] = *tableInfo.KeyFields
297-
infoMap["sum_key_field_size"] = *tableInfo.SumKeyFieldSize
298-
infoMap["value_fields"] = *tableInfo.ValueFields
299-
infoMap["sum_value_field_size"] = *tableInfo.SumValueFieldSize
300-
infoMap["index_key_set"] = *tableInfo.IndexKeySet
301-
infoMap["table_name"] = *tableInfo.TableName
296+
infoMap["key_fields"] = tableInfo.KeyFields
297+
infoMap["sum_key_field_size"] = tableInfo.SumKeyFieldSize
298+
infoMap["value_fields"] = tableInfo.ValueFields
299+
infoMap["sum_value_field_size"] = tableInfo.SumValueFieldSize
300+
infoMap["index_key_set"] = tableInfo.IndexKeySet
301+
infoMap["table_name"] = tableInfo.TableName
302302
tableInfos = append(tableInfos, infoMap)
303303
}
304304

tencentcloud/resource_tc_tcaplus_idl_test.go

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ func TestAccTencentCloudTcaplusIdlResource(t *testing.T) {
4343
},
4444
})
4545
}
46+
47+
func TestAccTencentCloudTcaplusTdrIdlResource(t *testing.T) {
48+
t.Parallel()
49+
resource.Test(t, resource.TestCase{
50+
PreCheck: func() { testAccPreCheck(t) },
51+
Providers: testAccProviders,
52+
CheckDestroy: testAccCheckTcaplusIdlDestroy,
53+
Steps: []resource.TestStep{
54+
{
55+
Config: testAccTcaplusIdlTdr,
56+
Check: resource.ComposeTestCheckFunc(
57+
testAccCheckTcaplusIdlExists("tencentcloud_tcaplus_idl.test_tdr_idl"),
58+
resource.TestCheckResourceAttrSet("tencentcloud_tcaplus_idl.test_tdr_idl", "cluster_id"),
59+
resource.TestCheckResourceAttr("tencentcloud_tcaplus_idl.test_tdr_idl", "file_name", "auth_info"),
60+
resource.TestCheckResourceAttr("tencentcloud_tcaplus_idl.test_tdr_idl", "file_type", "TDR"),
61+
resource.TestCheckResourceAttr("tencentcloud_tcaplus_idl.test_tdr_idl", "file_ext_type", "xml"),
62+
resource.TestCheckResourceAttr("tencentcloud_tcaplus_idl.test_tdr_idl", "table_infos.#", "1"),
63+
),
64+
},
65+
},
66+
})
67+
}
68+
4669
func testAccCheckTcaplusIdlDestroy(s *terraform.State) error {
4770
for _, rs := range s.RootModule().Resources {
4871
if rs.Type != testTcaplusIdlResourceName {
@@ -57,17 +80,24 @@ func testAccCheckTcaplusIdlDestroy(s *terraform.State) error {
5780
if err := json.Unmarshal([]byte(rs.Primary.ID), &tcaplusIdlId); err != nil {
5881
return fmt.Errorf("idl id is broken,%s", err.Error())
5982
}
60-
parseTableInfos, err := service.DesOldIdlFiles(ctx, tcaplusIdlId)
61-
if err != nil {
62-
parseTableInfos, err = service.DesOldIdlFiles(ctx, tcaplusIdlId)
63-
}
64-
if err != nil {
65-
return err
66-
}
67-
if len(parseTableInfos) == 0 {
83+
outerr := resource.Retry(readRetryTimeout, func() *resource.RetryError {
84+
infos, err := service.DescribeIdlFileInfos(ctx, tcaplusIdlId.ClusterId)
85+
if err != nil {
86+
return retryError(err)
87+
}
88+
if len(infos) == 0 {
89+
return nil
90+
}
91+
for _, info := range infos {
92+
if *info.FileId == tcaplusIdlId.FileId {
93+
return retryError(fmt.Errorf("delete failed!"))
94+
}
95+
}
6896
return nil
97+
})
98+
if outerr != nil {
99+
return fmt.Errorf("delete tcaplus idl %s fail, still on server", rs.Primary.ID)
69100
}
70-
return fmt.Errorf("delete tcaplus idl %s fail, still on server", rs.Primary.ID)
71101
}
72102
return nil
73103
}
@@ -137,3 +167,25 @@ resource "tencentcloud_tcaplus_idl" "test_idl" {
137167
EOF
138168
}
139169
`
170+
171+
const testAccTcaplusIdlTdr = defaultTcaPlusData + `
172+
resource "tencentcloud_tcaplus_idl" "test_tdr_idl" {
173+
cluster_id = data.tencentcloud_tcaplus_clusters.tdr_tcaplus.list.0.cluster_id
174+
tablegroup_id = data.tencentcloud_tcaplus_tablegroups.tdr_group.list.0.tablegroup_id
175+
file_name = "auth_info"
176+
file_type = "TDR"
177+
file_ext_type = "xml"
178+
file_content = <<EOF
179+
<?xml version="1.0" encoding="GBK" standalone="yes" ?>
180+
<metalib name="user" tagsetversion="1" version="1">
181+
<struct name="user_info" version="1" primarykey="id" splittablekey="id">
182+
<entry name="id" type="string" size="100" desc="id" />
183+
<entry name="username" type="string" size="100" desc="username" />
184+
<entry name="age" type="int" desc="age" />
185+
<entry name="createat" type="uint64" desc="创建时间" />
186+
<entry name="updateat" type="uint64" desc="更新时间" />
187+
</struct>
188+
</metalib>
189+
EOF
190+
}
191+
`

0 commit comments

Comments
 (0)