Skip to content

Commit 3127e2e

Browse files
authored
fix/sqlserver (#2008)
* fix/sqlserver * fix/sqlserver
1 parent 2c3926c commit 3127e2e

File tree

6 files changed

+100
-21
lines changed

6 files changed

+100
-21
lines changed

.changelog/2008.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_cynosdb_proxy: Add return value `ro_instances`
3+
```
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
package tencentcloud
22

33
import (
4+
"fmt"
45
"testing"
6+
"time"
57

68
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
79
)
810

911
// go test -i; go test -test.run TestAccTencentCloudCynosdbDescribeInstanceSlowQueriesDataSource_basic -v
1012
func TestAccTencentCloudCynosdbDescribeInstanceSlowQueriesDataSource_basic(t *testing.T) {
1113
t.Parallel()
14+
loc, _ := time.LoadLocation("Asia/Chongqing")
15+
startTime := time.Now().AddDate(0, 0, -7).In(loc).Format("2006-01-02 15:04:05")
16+
endTime := time.Now().In(loc).Format("2006-01-02 15:04:05")
1217
resource.Test(t, resource.TestCase{
1318
PreCheck: func() {
1419
testAccPreCheck(t)
1520
},
1621
Providers: testAccProviders,
1722
Steps: []resource.TestStep{
1823
{
19-
Config: testAccCynosdbDescribeInstanceSlowQueriesDataSource,
24+
Config: fmt.Sprintf(testAccCynosdbDescribeInstanceSlowQueriesDataSource, startTime, endTime),
2025
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_cynosdb_describe_instance_slow_queries.describe_instance_slow_queries")),
2126
},
2227
},
2328
})
2429
}
2530

26-
const testAccCynosdbDescribeInstanceSlowQueriesDataSource = `
31+
const testAccCynosdbDescribeInstanceSlowQueriesDataSource = CommonCynosdb + `
2732
data "tencentcloud_cynosdb_describe_instance_slow_queries" "describe_instance_slow_queries" {
28-
cluster_id = "cynosdbmysql-bws8h88b"
29-
start_time = "2023-06-01 12:00:00"
30-
end_time = "2023-06-19 14:00:00"
33+
cluster_id = var.cynosdb_cluster_id
34+
start_time = "%s"
35+
end_time = "%s"
3136
}
3237
`

tencentcloud/resource_tc_cynosdb_proxy.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,25 @@ func resourceTencentCloudCynosdbProxy() *schema.Resource {
132132
},
133133
},
134134
},
135+
"ro_instances": {
136+
Computed: true,
137+
Type: schema.TypeList,
138+
Description: "Read only instance list.",
139+
Elem: &schema.Resource{
140+
Schema: map[string]*schema.Schema{
141+
"instance_id": {
142+
Type: schema.TypeString,
143+
Optional: true,
144+
Description: "instance id.",
145+
},
146+
"weight": {
147+
Type: schema.TypeInt,
148+
Optional: true,
149+
Description: "weight.",
150+
},
151+
},
152+
},
153+
},
135154
},
136155
}
137156
}
@@ -355,6 +374,18 @@ func resourceTencentCloudCynosdbProxyRead(d *schema.ResourceData, meta interface
355374
}
356375
}
357376

377+
InstanceWeights := proxyGroupRwInfo.ProxyGroupRwInfo.InstanceWeights
378+
if InstanceWeights != nil {
379+
tmpList := []interface{}{}
380+
for _, v := range InstanceWeights {
381+
tmpMap := make(map[string]interface{})
382+
tmpMap["instance_id"] = v.InstanceId
383+
tmpMap["weight"] = v.Weight
384+
tmpList = append(tmpList, tmpMap)
385+
}
386+
_ = d.Set("ro_instances", tmpList)
387+
}
388+
358389
proxyNodes := proxyGroupRwInfo.ProxyNodes
359390
if proxyNodes != nil {
360391
zoneMap := make(map[string]int)

tencentcloud/resource_tc_cynosdb_proxy_end_point.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
1616
```
1717
1818
Set `vip` and `vport`
19+
1920
```hcl
2021
resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
2122
cluster_id = "cynosdbmysql-bws8h88b"
@@ -31,6 +32,7 @@ resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
3132
```
3233
3334
Open connection pool
35+
3436
```hcl
3537
resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
3638
cluster_id = "cynosdbmysql-bws8h88b"
@@ -49,6 +51,7 @@ resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
4951
```
5052
5153
Close connection pool
54+
5255
```hcl
5356
resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
5457
cluster_id = "cynosdbmysql-bws8h88b"
@@ -65,6 +68,7 @@ resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
6568
```
6669
6770
if `rw_type` is `READWRITE`
71+
6872
```hcl
6973
resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
7074
cluster_id = "cynosdbmysql-bws8h88b"
@@ -85,6 +89,7 @@ resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
8589
```
8690
8791
if `rw_type` is `READONLY`
92+
8893
```hcl
8994
resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
9095
cluster_id = "cynosdbmysql-bws8h88b"
@@ -102,6 +107,7 @@ resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
102107
```
103108
104109
Comprehensive parameter examples
110+
105111
```hcl
106112
resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
107113
cluster_id = "cynosdbmysql-bws8h88b"

tencentcloud/resource_tc_cynosdb_proxy_end_point_test.go

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
// go test -i; go test -test.run TestAccTencentCloudCynosdbProxyEndPointResource_basic -v
1414
func TestAccTencentCloudCynosdbProxyEndPointResource_basic(t *testing.T) {
15-
t.Parallel()
1615
resource.Test(t, resource.TestCase{
1716
PreCheck: func() {
1817
testAccPreCheck(t)
@@ -105,17 +104,34 @@ func testAccCheckCynosdbProxyEndPointExists(n string) resource.TestCheckFunc {
105104
}
106105
}
107106

108-
const testAccCynosdbProxyEndPoint = `
107+
const testAccCynosdbProxyEndPoint = CommonCynosdb + DefaultCrsVar + `
108+
resource "tencentcloud_cynosdb_proxy" "proxy" {
109+
cluster_id = var.cynosdb_cluster_id
110+
cpu = 2
111+
mem = 4000
112+
unique_vpc_id = var.vpc_id
113+
unique_subnet_id = var.subnet_id
114+
connection_pool_type = "SessionConnectionPool"
115+
open_connection_pool = "yes"
116+
connection_pool_time_out = 30
117+
security_group_ids = ["sg-baxfiao5"]
118+
description = "desc sample"
119+
proxy_zones {
120+
proxy_node_zone = "ap-guangzhou-7"
121+
proxy_node_count = 2
122+
}
123+
}
124+
109125
resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
110-
cluster_id = "cynosdbmysql-bws8h88b"
111-
unique_vpc_id = "vpc-4owdpnwr"
112-
unique_subnet_id = "subnet-dwj7ipnc"
113-
vip = "172.16.112.118"
126+
cluster_id = tencentcloud_cynosdb_proxy.proxy.cluster_id
127+
unique_vpc_id = var.vpc_id
128+
unique_subnet_id = var.subnet_id
129+
vip = "172.16.96.128"
114130
vport = "3306"
115131
connection_pool_type = "SessionConnectionPool"
116132
open_connection_pool = "yes"
117133
connection_pool_time_out = 30
118-
security_group_ids = ["sg-7kpsbxdb"]
134+
security_group_ids = ["sg-baxfiao5"]
119135
description = "desc value"
120136
weight_mode = "system"
121137
auto_add_ro = "yes"
@@ -126,29 +142,46 @@ resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
126142
trans_split = true
127143
access_mode = "nearby"
128144
instance_weights {
129-
instance_id = "cynosdbmysql-ins-afqx1hy0"
145+
instance_id = tencentcloud_cynosdb_proxy.proxy.ro_instances.0.instance_id
130146
weight = 1
131147
}
132148
}
133149
`
134150

135-
const testAccCynosdbProxyEndPointUpdate = `
151+
const testAccCynosdbProxyEndPointUpdate = CommonCynosdb + DefaultCrsVar + `
152+
resource "tencentcloud_cynosdb_proxy" "proxy" {
153+
cluster_id = var.cynosdb_cluster_id
154+
cpu = 2
155+
mem = 4000
156+
unique_vpc_id = var.vpc_id
157+
unique_subnet_id = var.subnet_id
158+
connection_pool_type = "SessionConnectionPool"
159+
open_connection_pool = "yes"
160+
connection_pool_time_out = 30
161+
security_group_ids = ["sg-baxfiao5"]
162+
description = "desc sample"
163+
proxy_zones {
164+
proxy_node_zone = "ap-guangzhou-7"
165+
proxy_node_count = 2
166+
}
167+
}
168+
136169
resource "tencentcloud_cynosdb_proxy_end_point" "proxy_end_point" {
137-
cluster_id = "cynosdbmysql-bws8h88b"
138-
unique_vpc_id = "vpc-4owdpnwr"
139-
unique_subnet_id = "subnet-dwj7ipnc"
140-
vip = "172.16.112.126"
170+
cluster_id = tencentcloud_cynosdb_proxy.proxy.cluster_id
171+
unique_vpc_id = var.vpc_id
172+
unique_subnet_id = var.subnet_id
173+
vip = "172.16.96.158"
141174
vport = "3306"
142175
open_connection_pool = "no"
143-
security_group_ids = ["sg-7kpsbxdb"]
176+
security_group_ids = ["sg-baxfiao5"]
144177
description = "desc value"
145178
weight_mode = "system"
146179
auto_add_ro = "no"
147-
rw_type = "READONLY"
180+
rw_type = "READWRITE"
148181
trans_split = true
149182
access_mode = "balance"
150183
instance_weights {
151-
instance_id = "cynosdbmysql-ins-rikr6z4o"
184+
instance_id = tencentcloud_cynosdb_proxy.proxy.ro_instances.0.instance_id
152185
weight = 1
153186
}
154187
}

website/docs/r/cynosdb_proxy.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ In addition to all arguments above, the following attributes are exported:
6060

6161
* `id` - ID of the resource.
6262
* `proxy_group_id` - Proxy Group Id.
63+
* `ro_instances` - Read only instance list.
6364

6465

0 commit comments

Comments
 (0)