Skip to content

Commit 8026327

Browse files
authored
Feat/example tcaplus (#1979)
* example readjust: tencentcloud_kubernetes_serverless_node_pool * add pre-commit-local * adjust e2e case * update example
1 parent 431fbb1 commit 8026327

File tree

9 files changed

+244
-117
lines changed

9 files changed

+244
-117
lines changed
Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
1+
locals {
2+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
3+
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
4+
}
5+
16
data "tencentcloud_vpc_subnets" "vpc" {
27
is_default = true
38
availability_zone = var.availability_zone
49
}
510

6-
resource "tencentcloud_tcaplus_cluster" "test_cluster" {
11+
resource "tencentcloud_tcaplus_cluster" "example" {
712
idl_type = "PROTO"
8-
cluster_name = "tf_tcaplus_g_table"
9-
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
10-
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
11-
password = "1qaA2k1wgvfa3ZZZ"
13+
cluster_name = "tf_example_tcaplus_cluster"
14+
vpc_id = local.vpc_id
15+
subnet_id = local.subnet_id
16+
password = "your_pw_123111"
1217
old_password_expire_last = 3600
1318
}
1419

15-
resource "tencentcloud_tcaplus_idl" "test_idl" {
16-
cluster_id = tencentcloud_tcaplus_cluster.test_cluster.id
17-
tablegroup_id = tencentcloud_tcaplus_tablegroup.test_tablegroup.id
18-
file_name = "tf_idl_test_guagua"
20+
resource "tencentcloud_tcaplus_tablegroup" "example" {
21+
cluster_id = tencentcloud_tcaplus_cluster.example.id
22+
tablegroup_name = "tf_example_group_name"
23+
}
24+
25+
resource "tencentcloud_tcaplus_idl" "main" {
26+
cluster_id = tencentcloud_tcaplus_cluster.example.id
27+
tablegroup_id = tencentcloud_tcaplus_tablegroup.example.id
28+
file_name = "tf_example_tcaplus_idl"
1929
file_type = "PROTO"
2030
file_ext_type = "proto"
2131
file_content = <<EOF
2232
syntax = "proto2";
2333
package myTcaplusTable;
2434
import "tcaplusservice.optionv1.proto";
25-
message tb_online_guagua {
35+
message tb_online {
2636
option(tcaplusservice.tcaplus_primary_key) = "uin,name,region";
2737
required int64 uin = 1;
2838
required string name = 2;
@@ -46,21 +56,3 @@ resource "tencentcloud_tcaplus_idl" "test_idl" {
4656
}
4757
EOF
4858
}
49-
50-
resource "tencentcloud_tcaplus_tablegroup" "test_tablegroup" {
51-
cluster_id = tencentcloud_tcaplus_cluster.test_cluster.id
52-
tablegroup_name = "tf_test_tablegroup"
53-
}
54-
55-
resource "tencentcloud_tcaplus_table" "test_table" {
56-
cluster_id = tencentcloud_tcaplus_cluster.test_cluster.id
57-
tablegroup_id = tencentcloud_tcaplus_tablegroup.test_tablegroup.id
58-
table_name = "tb_online_guagua"
59-
table_type = "GENERIC"
60-
description = "test"
61-
idl_id = tencentcloud_tcaplus_idl.test_idl.id
62-
table_idl_type = "PROTO"
63-
reserved_read_cu = 1000
64-
reserved_write_cu = 20
65-
reserved_volume = 1
66-
}

tencentcloud/resource_tc_tcaplus_cluster.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@ Use this resource to create TcaplusDB cluster.
55
66
Example Usage
77
8+
Create a new tcaplus cluster instance
9+
810
```hcl
9-
resource "tencentcloud_tcaplus_cluster" "test" {
11+
locals {
12+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
13+
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
14+
}
15+
16+
variable "availability_zone" {
17+
default = "ap-guangzhou-3"
18+
}
19+
20+
data "tencentcloud_vpc_subnets" "vpc" {
21+
is_default = true
22+
availability_zone = var.availability_zone
23+
}
24+
25+
resource "tencentcloud_tcaplus_cluster" "example" {
1026
idl_type = "PROTO"
11-
cluster_name = "tf_tcaplus_cluster_test"
12-
vpc_id = "vpc-7k6gzox6"
13-
subnet_id = "subnet-akwgvfa3"
14-
password = "1qaA2k1wgvfa3ZZZ"
27+
cluster_name = "tf_example_tcaplus_cluster"
28+
vpc_id = local.vpc_id
29+
subnet_id = local.subnet_id
30+
password = "your_pw_123111"
1531
old_password_expire_last = 3600
1632
}
1733
```
@@ -21,7 +37,7 @@ Import
2137
tcaplus cluster can be imported using the id, e.g.
2238
2339
```
24-
$ terraform import tencentcloud_tcaplus_cluster.test 26655801
40+
$ terraform import tencentcloud_tcaplus_cluster.example cluster_id
2541
```
2642
2743
*/

tencentcloud/resource_tc_tcaplus_idl.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,43 @@ Use this resource to create TcaplusDB IDL file.
33
44
Example Usage
55
6+
Create a tcaplus database idl file
7+
8+
The file will be with a specified cluster and tablegroup.
9+
610
```hcl
7-
resource "tencentcloud_tcaplus_cluster" "test" {
11+
locals {
12+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
13+
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
14+
}
15+
16+
variable "availability_zone" {
17+
default = "ap-guangzhou-3"
18+
}
19+
20+
data "tencentcloud_vpc_subnets" "vpc" {
21+
is_default = true
22+
availability_zone = var.availability_zone
23+
}
24+
25+
resource "tencentcloud_tcaplus_cluster" "example" {
826
idl_type = "PROTO"
9-
cluster_name = "tf_tcaplus_cluster_test"
10-
vpc_id = "vpc-7k6gzox6"
11-
subnet_id = "subnet-akwgvfa3"
12-
password = "1qaA2k1wgvfa3ZZZ"
27+
cluster_name = "tf_example_tcaplus_cluster"
28+
vpc_id = local.vpc_id
29+
subnet_id = local.subnet_id
30+
password = "your_pw_123111"
1331
old_password_expire_last = 3600
1432
}
1533
16-
resource "tencentcloud_tcaplus_tablegroup" "tablegroup" {
17-
cluster_id = tencentcloud_tcaplus_cluster.test.id
18-
tablegroup_name = "tf_test_group_name"
34+
resource "tencentcloud_tcaplus_tablegroup" "example" {
35+
cluster_id = tencentcloud_tcaplus_cluster.example.id
36+
tablegroup_name = "tf_example_group_name"
1937
}
2038
2139
resource "tencentcloud_tcaplus_idl" "main" {
22-
cluster_id = tencentcloud_tcaplus_cluster.test.id
23-
tablegroup_id = tencentcloud_tcaplus_tablegroup.tablegroup.id
24-
file_name = "tf_idl_test"
40+
cluster_id = tencentcloud_tcaplus_cluster.example.id
41+
tablegroup_id = tencentcloud_tcaplus_tablegroup.example.id
42+
file_name = "tf_example_tcaplus_idl"
2543
file_type = "PROTO"
2644
file_ext_type = "proto"
2745
file_content = <<EOF
@@ -52,7 +70,6 @@ resource "tencentcloud_tcaplus_idl" "main" {
5270
}
5371
EOF
5472
}
55-
5673
```
5774
*/
5875
package tencentcloud

tencentcloud/resource_tc_tcaplus_table.go

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,51 @@ Use this resource to create TcaplusDB table.
33
44
Example Usage
55
6+
Create a tcaplus database table
7+
8+
The tcaplus database table should be pre-defined in the idl file.
9+
610
```hcl
7-
resource "tencentcloud_tcaplus_cluster" "test" {
11+
locals {
12+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
13+
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
14+
}
15+
16+
variable "availability_zone" {
17+
default = "ap-guangzhou-3"
18+
}
19+
20+
data "tencentcloud_vpc_subnets" "vpc" {
21+
is_default = true
22+
availability_zone = var.availability_zone
23+
}
24+
25+
resource "tencentcloud_tcaplus_cluster" "example" {
826
idl_type = "PROTO"
9-
cluster_name = "tf_tcaplus_cluster_test"
10-
vpc_id = "vpc-7k6gzox6"
11-
subnet_id = "subnet-akwgvfa3"
12-
password = "1qaA2k1wgvfa3ZZZ"
27+
cluster_name = "tf_example_tcaplus_cluster"
28+
vpc_id = local.vpc_id
29+
subnet_id = local.subnet_id
30+
password = "your_pw_123111"
1331
old_password_expire_last = 3600
1432
}
1533
16-
resource "tencentcloud_tcaplus_tablegroup" "tablegroup" {
17-
cluster_id = tencentcloud_tcaplus_cluster.test.id
18-
tablegroup_name = "tf_test_group_name"
34+
resource "tencentcloud_tcaplus_tablegroup" "example" {
35+
cluster_id = tencentcloud_tcaplus_cluster.example.id
36+
tablegroup_name = "tf_example_group_name"
1937
}
2038
21-
resource "tencentcloud_tcaplus_idl" "main" {
22-
cluster_id = tencentcloud_tcaplus_cluster.test.id
23-
tablegroup_id = tencentcloud_tcaplus_tablegroup.tablegroup.id
24-
file_name = "tf_idl_test_2"
39+
resource "tencentcloud_tcaplus_idl" "example" {
40+
cluster_id = tencentcloud_tcaplus_cluster.example.id
41+
tablegroup_id = tencentcloud_tcaplus_tablegroup.example.id
42+
file_name = "tf_example_tcaplus_idl"
2543
file_type = "PROTO"
2644
file_ext_type = "proto"
2745
file_content = <<EOF
2846
syntax = "proto2";
2947
package myTcaplusTable;
3048
import "tcaplusservice.optionv1.proto";
31-
message tb_online {
32-
option(tcaplusservice.tcaplus_primary_key) = "uin,name,region";
49+
message example_table { # refer the table name
50+
option(tcaplusservice.tcaplus_primary_key) = "uin,name,region";
3351
required int64 uin = 1;
3452
required string name = 2;
3553
required int32 region = 3;
@@ -53,13 +71,13 @@ resource "tencentcloud_tcaplus_idl" "main" {
5371
EOF
5472
}
5573
56-
resource "tencentcloud_tcaplus_table" "table" {
57-
cluster_id = tencentcloud_tcaplus_cluster.test.id
58-
tablegroup_id = tencentcloud_tcaplus_tablegroup.tablegroup.id
59-
table_name = "tb_online"
74+
resource "tencentcloud_tcaplus_table" "example" {
75+
cluster_id = tencentcloud_tcaplus_cluster.example.id
76+
tablegroup_id = tencentcloud_tcaplus_tablegroup.example.id
77+
table_name = "example_table"
6078
table_type = "GENERIC"
6179
description = "test"
62-
idl_id = tencentcloud_tcaplus_idl.main.id
80+
idl_id = tencentcloud_tcaplus_idl.example.id
6381
table_idl_type = "PROTO"
6482
reserved_read_cu = 1000
6583
reserved_write_cu = 20

tencentcloud/resource_tc_tcaplus_tablegroup.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,35 @@ Use this resource to create TcaplusDB table group.
33
44
Example Usage
55
6+
Create a tcaplusdb table group
7+
68
```hcl
7-
resource "tencentcloud_tcaplus_cluster" "test" {
9+
locals {
10+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
11+
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
12+
}
13+
14+
variable "availability_zone" {
15+
default = "ap-guangzhou-3"
16+
}
17+
18+
data "tencentcloud_vpc_subnets" "vpc" {
19+
is_default = true
20+
availability_zone = var.availability_zone
21+
}
22+
23+
resource "tencentcloud_tcaplus_cluster" "example" {
824
idl_type = "PROTO"
9-
cluster_name = "tf_tcaplus_cluster_test"
10-
vpc_id = "vpc-7k6gzox6"
11-
subnet_id = "subnet-akwgvfa3"
12-
password = "1qaA2k1wgvfa3ZZZ"
25+
cluster_name = "tf_example_tcaplus_cluster"
26+
vpc_id = local.vpc_id
27+
subnet_id = local.subnet_id
28+
password = "your_pw_123111"
1329
old_password_expire_last = 3600
1430
}
1531
16-
resource "tencentcloud_tcaplus_tablegroup" "tablegroup" {
17-
cluster_id = tencentcloud_tcaplus_cluster.test.id
18-
tablegroup_name = "tf_test_group_name"
32+
resource "tencentcloud_tcaplus_tablegroup" "example" {
33+
cluster_id = tencentcloud_tcaplus_cluster.example.id
34+
tablegroup_name = "tf_example_group_name"
1935
}
2036
```
2137
*/

website/docs/r/tcaplus_cluster.html.markdown

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,29 @@ Use this resource to create TcaplusDB cluster.
1515

1616
## Example Usage
1717

18+
### Create a new tcaplus cluster instance
19+
1820
```hcl
19-
resource "tencentcloud_tcaplus_cluster" "test" {
21+
locals {
22+
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
23+
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
24+
}
25+
26+
variable "availability_zone" {
27+
default = "ap-guangzhou-3"
28+
}
29+
30+
data "tencentcloud_vpc_subnets" "vpc" {
31+
is_default = true
32+
availability_zone = var.availability_zone
33+
}
34+
35+
resource "tencentcloud_tcaplus_cluster" "example" {
2036
idl_type = "PROTO"
21-
cluster_name = "tf_tcaplus_cluster_test"
22-
vpc_id = "vpc-7k6gzox6"
23-
subnet_id = "subnet-akwgvfa3"
24-
password = "1qaA2k1wgvfa3ZZZ"
37+
cluster_name = "tf_example_tcaplus_cluster"
38+
vpc_id = local.vpc_id
39+
subnet_id = local.subnet_id
40+
password = "your_pw_123111"
2541
old_password_expire_last = 3600
2642
}
2743
```
@@ -56,6 +72,6 @@ In addition to all arguments above, the following attributes are exported:
5672
tcaplus cluster can be imported using the id, e.g.
5773

5874
```
59-
$ terraform import tencentcloud_tcaplus_cluster.test 26655801
75+
$ terraform import tencentcloud_tcaplus_cluster.example cluster_id
6076
```
6177

0 commit comments

Comments
 (0)