Skip to content

Commit 0e5b4df

Browse files
authored
add tencentcloud_clickhouse_instance_nodes datasource (#2483)
* add tencentcloud_clickhouse_instance_nodes datasource * add changelog 2483.txt
1 parent 490a1cd commit 0e5b4df

File tree

15 files changed

+672
-31
lines changed

15 files changed

+672
-31
lines changed

.changelog/2483.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_clickhouse_instance_nodes
3+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.591
3838
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.800
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.539
40-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.745
40+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.843
4141
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627
4242
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfw v1.0.759
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/chdfs v1.0.600
@@ -46,7 +46,7 @@ require (
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.693
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.711
49-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.839
49+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.843
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
5252
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.539 h1:0L6nZhT
848848
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.539/go.mod h1:6Syk7W5fdDf0BLvX+RXL5obQ6unkt3Id4aN2QqVrV6U=
849849
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.745 h1:y3CtDHGwJ8VDpAlNjluxZMdPbj4MQTD0RFIwQjKei4Q=
850850
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.745/go.mod h1:DxjJ8NLE8FGPaQP5k08z1gUqQCSwBuXgPs0u869VoyE=
851+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.843 h1:3Xr3UPscUfi5jAzCtwQjDfDf4TPsbUxsCrDdHo6xIRI=
852+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch v1.0.843/go.mod h1:XTZXr3hF0pPTd3jD/vm90FhJEOvILL3d2u43Q52xZX8=
851853
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwpg v1.0.772 h1:tn8b0VAqKV4cglYrubtwONiHfXhoyZSmYMmgL/oX/RU=
852854
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwpg v1.0.772/go.mod h1:vkWjnf7Qvtesn0efpiaVj5mIQsQhomkA2keE2yskfmg=
853855
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.627 h1:nChNdoCUWQZciiJj3gRCWoHBO/8LituLQOdCRREIrS4=
@@ -940,6 +942,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.833 h1:EE3P
940942
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.833/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
941943
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.839 h1:VGVFNQDaUpDsPkJrh8I9qOxHZ1yj5sJmg9ngsUvTAHM=
942944
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.839/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
945+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.843 h1:ewSxQuJAqdjE3RqFIaDhM/88lIe10JfUFbS4hMQHK5M=
946+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.843/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
943947
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
944948
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
945949
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 h1:2egy69SP/wPsmnfozcQVZ6tUY6F6N/TpEe/7xtXrc/8=

tencentcloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ func Provider() *schema.Provider {
981981
"tencentcloud_kubernetes_cluster_node_pools": tke.DataSourceTencentCloudKubernetesClusterNodePools(),
982982
"tencentcloud_clickhouse_spec": cdwch.DataSourceTencentCloudClickhouseSpec(),
983983
"tencentcloud_clickhouse_instance_shards": cdwch.DataSourceTencentCloudClickhouseInstanceShards(),
984+
"tencentcloud_clickhouse_instance_nodes": cdwch.DataSourceTencentCloudClickhouseInstanceNodes(),
984985
},
985986

986987
ResourcesMap: map[string]*schema.Resource{

tencentcloud/provider.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,7 @@ ClickHouse(CDWCH)
19241924
tencentcloud_clickhouse_backup_tables
19251925
tencentcloud_clickhouse_spec
19261926
tencentcloud_clickhouse_instance_shards
1927+
tencentcloud_clickhouse_instance_nodes
19271928

19281929
Resource
19291930
tencentcloud_clickhouse_instance
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
package cdwch
2+
3+
import (
4+
"context"
5+
6+
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
clickhouse "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwch/v20200915"
11+
12+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
13+
)
14+
15+
func DataSourceTencentCloudClickhouseInstanceNodes() *schema.Resource {
16+
return &schema.Resource{
17+
Read: dataSourceTencentCloudClickhouseInstanceNodesRead,
18+
Schema: map[string]*schema.Schema{
19+
"instance_id": {
20+
Required: true,
21+
Type: schema.TypeString,
22+
Description: "InstanceId.",
23+
},
24+
25+
"node_role": {
26+
Optional: true,
27+
Type: schema.TypeString,
28+
Description: "Cluster role type, default is `data` data node.",
29+
},
30+
31+
"display_policy": {
32+
Optional: true,
33+
Type: schema.TypeString,
34+
Description: "Display strategy, display all when All.",
35+
},
36+
37+
"force_all": {
38+
Optional: true,
39+
Type: schema.TypeBool,
40+
Description: "When true, returns all nodes, that is, the Limit is infinitely large.",
41+
},
42+
43+
"instance_nodes_list": {
44+
Computed: true,
45+
Type: schema.TypeList,
46+
Description: "Total number of instance nodes.",
47+
Elem: &schema.Resource{
48+
Schema: map[string]*schema.Schema{
49+
"ip": {
50+
Type: schema.TypeString,
51+
Computed: true,
52+
Description: "IP Address.",
53+
},
54+
"spec": {
55+
Type: schema.TypeString,
56+
Computed: true,
57+
Description: "Model, such as S1.",
58+
},
59+
"core": {
60+
Type: schema.TypeInt,
61+
Computed: true,
62+
Description: "CPU cores.",
63+
},
64+
"memory": {
65+
Type: schema.TypeInt,
66+
Computed: true,
67+
Description: "Memory size.",
68+
},
69+
"disk_type": {
70+
Type: schema.TypeString,
71+
Computed: true,
72+
Description: "Disk type.",
73+
},
74+
"disk_size": {
75+
Type: schema.TypeInt,
76+
Computed: true,
77+
Description: "Disk size.",
78+
},
79+
"cluster": {
80+
Type: schema.TypeString,
81+
Computed: true,
82+
Description: "Name of the clickhouse cluster to which it belongs.",
83+
},
84+
"node_groups": {
85+
Type: schema.TypeList,
86+
Computed: true,
87+
Description: "Group information to which the node belongs.",
88+
Elem: &schema.Resource{
89+
Schema: map[string]*schema.Schema{
90+
"group_name": {
91+
Type: schema.TypeString,
92+
Computed: true,
93+
Description: "Group Name.",
94+
},
95+
"shard_name": {
96+
Type: schema.TypeString,
97+
Computed: true,
98+
Description: "Fragmented variable name.",
99+
},
100+
"replica_name": {
101+
Type: schema.TypeString,
102+
Computed: true,
103+
Description: "Copy variable name.",
104+
},
105+
},
106+
},
107+
},
108+
"rip": {
109+
Type: schema.TypeString,
110+
Computed: true,
111+
Description: "VPC IP.",
112+
},
113+
"is_ch_proxy": {
114+
Type: schema.TypeBool,
115+
Computed: true,
116+
Description: "When true, it indicates that the chproxy process has been deployed on the node.",
117+
},
118+
},
119+
},
120+
},
121+
122+
"result_output_file": {
123+
Type: schema.TypeString,
124+
Optional: true,
125+
Description: "Used to save results.",
126+
},
127+
},
128+
}
129+
}
130+
131+
func dataSourceTencentCloudClickhouseInstanceNodesRead(d *schema.ResourceData, meta interface{}) error {
132+
defer tccommon.LogElapsed("data_source.tencentcloud_clickhouse_instance_nodes.read")()
133+
defer tccommon.InconsistentCheck(d, meta)()
134+
135+
logId := tccommon.GetLogId(tccommon.ContextNil)
136+
137+
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
138+
139+
paramMap := make(map[string]interface{})
140+
if v, ok := d.GetOk("instance_id"); ok {
141+
paramMap["InstanceId"] = helper.String(v.(string))
142+
}
143+
144+
if v, ok := d.GetOk("node_role"); ok {
145+
paramMap["NodeRole"] = helper.String(v.(string))
146+
}
147+
148+
if v, ok := d.GetOk("display_policy"); ok {
149+
paramMap["DisplayPolicy"] = helper.String(v.(string))
150+
}
151+
152+
if v, ok := d.GetOkExists("force_all"); ok {
153+
paramMap["ForceAll"] = helper.Bool(v.(bool))
154+
}
155+
156+
service := CdwchService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
157+
158+
var instanceNodesList []*clickhouse.InstanceNode
159+
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
160+
result, e := service.DescribeClickhouseInstanceNodesByFilter(ctx, paramMap)
161+
if e != nil {
162+
return tccommon.RetryError(e)
163+
}
164+
instanceNodesList = result
165+
return nil
166+
})
167+
if err != nil {
168+
return err
169+
}
170+
171+
tmpList := make([]map[string]interface{}, 0, len(instanceNodesList))
172+
173+
if instanceNodesList != nil {
174+
for _, instanceNode := range instanceNodesList {
175+
instanceNodeMap := map[string]interface{}{}
176+
177+
if instanceNode.Ip != nil {
178+
instanceNodeMap["ip"] = instanceNode.Ip
179+
}
180+
181+
if instanceNode.Spec != nil {
182+
instanceNodeMap["spec"] = instanceNode.Spec
183+
}
184+
185+
if instanceNode.Core != nil {
186+
instanceNodeMap["core"] = instanceNode.Core
187+
}
188+
189+
if instanceNode.Memory != nil {
190+
instanceNodeMap["memory"] = instanceNode.Memory
191+
}
192+
193+
if instanceNode.DiskType != nil {
194+
instanceNodeMap["disk_type"] = instanceNode.DiskType
195+
}
196+
197+
if instanceNode.DiskSize != nil {
198+
instanceNodeMap["disk_size"] = instanceNode.DiskSize
199+
}
200+
201+
if instanceNode.Cluster != nil {
202+
instanceNodeMap["cluster"] = instanceNode.Cluster
203+
}
204+
205+
if instanceNode.NodeGroups != nil {
206+
var nodeGroupsList []interface{}
207+
for _, nodeGroups := range instanceNode.NodeGroups {
208+
nodeGroupsMap := map[string]interface{}{}
209+
210+
if nodeGroups.GroupName != nil {
211+
nodeGroupsMap["group_name"] = nodeGroups.GroupName
212+
}
213+
214+
if nodeGroups.ShardName != nil {
215+
nodeGroupsMap["shard_name"] = nodeGroups.ShardName
216+
}
217+
218+
if nodeGroups.ReplicaName != nil {
219+
nodeGroupsMap["replica_name"] = nodeGroups.ReplicaName
220+
}
221+
222+
nodeGroupsList = append(nodeGroupsList, nodeGroupsMap)
223+
}
224+
225+
instanceNodeMap["node_groups"] = nodeGroupsList
226+
}
227+
228+
if instanceNode.Rip != nil {
229+
instanceNodeMap["rip"] = instanceNode.Rip
230+
}
231+
232+
if instanceNode.IsCHProxy != nil {
233+
instanceNodeMap["is_ch_proxy"] = instanceNode.IsCHProxy
234+
}
235+
236+
tmpList = append(tmpList, instanceNodeMap)
237+
}
238+
239+
_ = d.Set("instance_nodes_list", tmpList)
240+
}
241+
242+
d.SetId(helper.BuildToken())
243+
244+
output, ok := d.GetOk("result_output_file")
245+
if ok && output.(string) != "" {
246+
if e := tccommon.WriteToFile(output.(string), tmpList); e != nil {
247+
return e
248+
}
249+
}
250+
return nil
251+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Use this data source to query detailed information of clickhouse instance_nodes
2+
3+
Example Usage
4+
5+
```hcl
6+
data "tencentcloud_clickhouse_instance_nodes" "instance_nodes" {
7+
instance_id = "cdwch-mvfjh373"
8+
node_role = "data"
9+
display_policy = "all"
10+
force_all = true
11+
}
12+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cdwch_test
2+
3+
import (
4+
"testing"
5+
6+
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
)
10+
11+
func TestAccTencentCloudClickhouseInstanceNodesDataSource_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { tcacctest.AccPreCheck(t) },
15+
Providers: tcacctest.AccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccClickhouseInstanceNodesDataSource,
19+
Check: resource.ComposeTestCheckFunc(tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_clickhouse_instance_nodes.instance_nodes")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccClickhouseInstanceNodesDataSource = `
26+
data "tencentcloud_clickhouse_instance_nodes" "instance_nodes" {
27+
instance_id = "cdwch-mvfjh373"
28+
node_role = "data"
29+
display_policy = "all"
30+
force_all = true
31+
}
32+
`

0 commit comments

Comments
 (0)