Skip to content

Commit 1e00f1c

Browse files
gitmknanonymous
andauthored
feat: support gatewayNode (#1913)
* feat: support gateway * feat: add changelog --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent add2879 commit 1e00f1c

File tree

7 files changed

+321
-0
lines changed

7 files changed

+321
-0
lines changed

.changelog/1913.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-data-source
2+
tencentcloud_tse_gateway_nodes
3+
```
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
Use this data source to query detailed information of tse gateway_nodes
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_tse_gateway_nodes" "gateway_nodes" {
8+
gateway_id = "gateway-ddbb709b"
9+
group_id = "group-013c0d8e"
10+
}
11+
```
12+
*/
13+
package tencentcloud
14+
15+
import (
16+
"context"
17+
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
20+
tse "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse/v20201207"
21+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
22+
)
23+
24+
func dataSourceTencentCloudTseGatewayNodes() *schema.Resource {
25+
return &schema.Resource{
26+
Read: dataSourceTencentCloudTseGatewayNodesRead,
27+
Schema: map[string]*schema.Schema{
28+
"gateway_id": {
29+
Required: true,
30+
Type: schema.TypeString,
31+
Description: "gateway ID.",
32+
},
33+
34+
"group_id": {
35+
Optional: true,
36+
Type: schema.TypeString,
37+
Description: "gateway group ID.",
38+
},
39+
40+
"node_list": {
41+
Type: schema.TypeList,
42+
Computed: true,
43+
Description: "nodes information.",
44+
Elem: &schema.Resource{
45+
Schema: map[string]*schema.Schema{
46+
"node_id": {
47+
Type: schema.TypeString,
48+
Computed: true,
49+
Description: "gateway node id.",
50+
},
51+
"node_ip": {
52+
Type: schema.TypeString,
53+
Computed: true,
54+
Description: "gateway node ip.",
55+
},
56+
"zone_id": {
57+
Type: schema.TypeString,
58+
Computed: true,
59+
Description: "Zone idNote: This field may return null, indicating that a valid value is not available.",
60+
},
61+
"zone": {
62+
Type: schema.TypeString,
63+
Computed: true,
64+
Description: "ZoneNote: This field may return null, indicating that a valid value is not available.",
65+
},
66+
"group_id": {
67+
Type: schema.TypeString,
68+
Computed: true,
69+
Description: "Group IDNote: This field may return null, indicating that a valid value is not available.",
70+
},
71+
"group_name": {
72+
Type: schema.TypeString,
73+
Computed: true,
74+
Description: "Group nameNote: This field may return null, indicating that a valid value is not available.",
75+
},
76+
"status": {
77+
Type: schema.TypeString,
78+
Computed: true,
79+
Description: "statusNote: This field may return null, indicating that a valid value is not available.",
80+
},
81+
},
82+
},
83+
},
84+
85+
"result_output_file": {
86+
Type: schema.TypeString,
87+
Optional: true,
88+
Description: "Used to save results.",
89+
},
90+
},
91+
}
92+
}
93+
94+
func dataSourceTencentCloudTseGatewayNodesRead(d *schema.ResourceData, meta interface{}) error {
95+
defer logElapsed("data_source.tencentcloud_tse_gateway_nodes.read")()
96+
defer inconsistentCheck(d, meta)()
97+
98+
logId := getLogId(contextNil)
99+
100+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
101+
102+
paramMap := make(map[string]interface{})
103+
if v, ok := d.GetOk("gateway_id"); ok {
104+
paramMap["GatewayId"] = helper.String(v.(string))
105+
}
106+
107+
if v, ok := d.GetOk("group_id"); ok {
108+
paramMap["GroupId"] = helper.String(v.(string))
109+
}
110+
111+
service := TseService{client: meta.(*TencentCloudClient).apiV3Conn}
112+
113+
var result []*tse.CloudNativeAPIGatewayNode
114+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
115+
response, e := service.DescribeTseGatewayNodesByFilter(ctx, paramMap)
116+
if e != nil {
117+
return retryError(e)
118+
}
119+
result = response
120+
return nil
121+
})
122+
if err != nil {
123+
return err
124+
}
125+
126+
ids := make([]string, 0, len(result))
127+
nodeListList := []interface{}{}
128+
if result != nil {
129+
for _, nodeList := range result {
130+
nodeListMap := map[string]interface{}{}
131+
132+
if nodeList.NodeId != nil {
133+
nodeListMap["node_id"] = nodeList.NodeId
134+
}
135+
136+
if nodeList.NodeIp != nil {
137+
nodeListMap["node_ip"] = nodeList.NodeIp
138+
}
139+
140+
if nodeList.ZoneId != nil {
141+
nodeListMap["zone_id"] = nodeList.ZoneId
142+
}
143+
144+
if nodeList.Zone != nil {
145+
nodeListMap["zone"] = nodeList.Zone
146+
}
147+
148+
if nodeList.GroupId != nil {
149+
nodeListMap["group_id"] = nodeList.GroupId
150+
}
151+
152+
if nodeList.GroupName != nil {
153+
nodeListMap["group_name"] = nodeList.GroupName
154+
}
155+
156+
if nodeList.Status != nil {
157+
nodeListMap["status"] = nodeList.Status
158+
}
159+
160+
nodeListList = append(nodeListList, nodeListMap)
161+
ids = append(ids, *nodeList.NodeId)
162+
}
163+
164+
_ = d.Set("node_list", nodeListList)
165+
}
166+
167+
d.SetId(helper.DataResourceIdsHash(ids))
168+
output, ok := d.GetOk("result_output_file")
169+
if ok && output.(string) != "" {
170+
if e := writeToFile(output.(string), nodeListList); e != nil {
171+
return e
172+
}
173+
}
174+
return nil
175+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudTseGatewayNodesDataSource_basic -v
10+
func TestAccTencentCloudTseGatewayNodesDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccTseGatewayNodesDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_tse_gateway_nodes.gateway_nodes"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_nodes.gateway_nodes", "node_list.#"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_nodes.gateway_nodes", "node_list.0.group_id"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_nodes.gateway_nodes", "node_list.0.group_name"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_nodes.gateway_nodes", "node_list.0.node_id"),
26+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_nodes.gateway_nodes", "node_list.0.node_ip"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_nodes.gateway_nodes", "node_list.0.status"),
28+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_nodes.gateway_nodes", "node_list.0.zone"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_tse_gateway_nodes.gateway_nodes", "node_list.0.zone_id"),
30+
),
31+
},
32+
},
33+
})
34+
}
35+
36+
const testAccTseGatewayNodesDataSource = `
37+
38+
data "tencentcloud_tse_gateway_nodes" "gateway_nodes" {
39+
gateway_id = "gateway-ddbb709b"
40+
group_id = "group-013c0d8e"
41+
}
42+
43+
`

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,7 @@ Tencent Cloud Service Engine(TSE)
15161516
tencentcloud_tse_zookeeper_replicas
15171517
tencentcloud_tse_zookeeper_server_interfaces
15181518
tencentcloud_tse_nacos_server_interfaces
1519+
tencentcloud_tse_gateway_nodes
15191520
15201521
Resource
15211522
tencentcloud_tse_instance
@@ -2128,6 +2129,7 @@ func Provider() *schema.Provider {
21282129
"tencentcloud_tse_nacos_server_interfaces": dataSourceTencentCloudTseNacosServerInterfaces(),
21292130
"tencentcloud_tse_zookeeper_replicas": dataSourceTencentCloudTseZookeeperReplicas(),
21302131
"tencentcloud_tse_zookeeper_server_interfaces": dataSourceTencentCloudTseZookeeperServerInterfaces(),
2132+
"tencentcloud_tse_gateway_nodes": dataSourceTencentCloudTseGatewayNodes(),
21312133
"tencentcloud_lighthouse_modify_instance_bundle": dataSourceTencentCloudLighthouseModifyInstanceBundle(),
21322134
"tencentcloud_lighthouse_zone": dataSourceTencentCloudLighthouseZone(),
21332135
"tencentcloud_lighthouse_scene": dataSourceTencentCloudLighthouseScene(),

tencentcloud/service_tencentcloud_tse.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,54 @@ func (me *TseService) DescribeTseNacosServerInterfacesByFilter(ctx context.Conte
363363

364364
return
365365
}
366+
367+
func (me *TseService) DescribeTseGatewayNodesByFilter(ctx context.Context, param map[string]interface{}) (gatewayNodes []*tse.CloudNativeAPIGatewayNode, errRet error) {
368+
var (
369+
logId = getLogId(ctx)
370+
request = tse.NewDescribeCloudNativeAPIGatewayNodesRequest()
371+
)
372+
373+
defer func() {
374+
if errRet != nil {
375+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
376+
}
377+
}()
378+
379+
for k, v := range param {
380+
if k == "GatewayId" {
381+
request.GatewayId = v.(*string)
382+
}
383+
if k == "GroupId" {
384+
request.GroupId = v.(*string)
385+
}
386+
}
387+
388+
ratelimit.Check(request.GetAction())
389+
390+
var (
391+
offset int64 = 0
392+
limit int64 = 20
393+
)
394+
for {
395+
request.Offset = &offset
396+
request.Limit = &limit
397+
response, err := me.client.UseTseClient().DescribeCloudNativeAPIGatewayNodes(request)
398+
if err != nil {
399+
errRet = err
400+
return
401+
}
402+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
403+
404+
if response == nil || len(response.Response.Result.NodeList) < 1 {
405+
break
406+
}
407+
gatewayNodes = append(gatewayNodes, response.Response.Result.NodeList...)
408+
if len(response.Response.Result.NodeList) < int(limit) {
409+
break
410+
}
411+
412+
offset += limit
413+
}
414+
415+
return
416+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
subcategory: "Tencent Cloud Service Engine(TSE)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_tse_gateway_nodes"
5+
sidebar_current: "docs-tencentcloud-datasource-tse_gateway_nodes"
6+
description: |-
7+
Use this data source to query detailed information of tse gateway_nodes
8+
---
9+
10+
# tencentcloud_tse_gateway_nodes
11+
12+
Use this data source to query detailed information of tse gateway_nodes
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "tencentcloud_tse_gateway_nodes" "gateway_nodes" {
18+
gateway_id = "gateway-ddbb709b"
19+
group_id = "group-013c0d8e"
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `gateway_id` - (Required, String) gateway ID.
28+
* `group_id` - (Optional, String) gateway group ID.
29+
* `result_output_file` - (Optional, String) Used to save results.
30+
31+
## Attributes Reference
32+
33+
In addition to all arguments above, the following attributes are exported:
34+
35+
* `node_list` - nodes information.
36+
* `group_id` - Group IDNote: This field may return null, indicating that a valid value is not available.
37+
* `group_name` - Group nameNote: This field may return null, indicating that a valid value is not available.
38+
* `node_id` - gateway node id.
39+
* `node_ip` - gateway node ip.
40+
* `status` - statusNote: This field may return null, indicating that a valid value is not available.
41+
* `zone_id` - Zone idNote: This field may return null, indicating that a valid value is not available.
42+
* `zone` - ZoneNote: This field may return null, indicating that a valid value is not available.
43+
44+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,9 @@
28262826
<li>
28272827
<a href="/docs/providers/tencentcloud/d/tse_nacos_server_interfaces.html">tencentcloud_tse_nacos_server_interfaces</a>
28282828
</li>
2829+
<li>
2830+
<a href="/docs/providers/tencentcloud/d/tse_gateway_nodes.html">tencentcloud_tse_gateway_nodes</a>
2831+
</li>
28292832
</ul>
28302833
</li>
28312834
<li>

0 commit comments

Comments
 (0)