Skip to content

Commit 502d5e2

Browse files
authored
feat/tdmq-data-source (#1902)
* feat/tdmq-data-source * feat/tdmq-data-source * feat/tdmq-data-source * feat/tdmq-data-source * feat/tdmq-data-source * feat/tdmq-data-source
1 parent 1839ee2 commit 502d5e2

13 files changed

+1309
-0
lines changed

.changelog/1902.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:new-data-source
2+
tencentcloud_tdmq_rocketmq_messages
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_tdmq_pro_instances
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_tdmq_pro_instance_detail
11+
```
Lines changed: 354 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
/*
2+
Use this data source to query detailed information of tdmq pro_instance_detail
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_tdmq_pro_instance_detail" "pro_instance_detail" {
8+
cluster_id = "pulsar-9n95ax58b9vn"
9+
}
10+
```
11+
*/
12+
package tencentcloud
13+
14+
import (
15+
"context"
16+
17+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
tdmq "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq/v20200217"
20+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
21+
)
22+
23+
func dataSourceTencentCloudTdmqProInstanceDetail() *schema.Resource {
24+
return &schema.Resource{
25+
Read: dataSourceTencentCloudTdmqProInstanceDetailRead,
26+
Schema: map[string]*schema.Schema{
27+
"cluster_id": {
28+
Required: true,
29+
Type: schema.TypeString,
30+
Description: "Cluster Id.",
31+
},
32+
"cluster_info": {
33+
Computed: true,
34+
Type: schema.TypeList,
35+
Description: "Cluster information.",
36+
Elem: &schema.Resource{
37+
Schema: map[string]*schema.Schema{
38+
"cluster_id": {
39+
Type: schema.TypeString,
40+
Computed: true,
41+
Description: "Cluster Id.",
42+
},
43+
"cluster_name": {
44+
Type: schema.TypeString,
45+
Computed: true,
46+
Description: "Cluster name.",
47+
},
48+
"remark": {
49+
Type: schema.TypeString,
50+
Computed: true,
51+
Description: "Descriptive information.",
52+
},
53+
"create_time": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
Description: "Creation time.",
57+
},
58+
"status": {
59+
Type: schema.TypeInt,
60+
Computed: true,
61+
Description: "Cluster status, 0: creating, 1: normal, 2: isolated.",
62+
},
63+
"version": {
64+
Type: schema.TypeString,
65+
Computed: true,
66+
Description: "cluster version.",
67+
},
68+
"node_distribution": {
69+
Type: schema.TypeList,
70+
Computed: true,
71+
Description: "Node distributionNote: This field may return null, indicating that no valid value can be obtained.",
72+
Elem: &schema.Resource{
73+
Schema: map[string]*schema.Schema{
74+
"zone_name": {
75+
Type: schema.TypeString,
76+
Computed: true,
77+
Description: "Availability zone.",
78+
},
79+
"zone_id": {
80+
Type: schema.TypeString,
81+
Computed: true,
82+
Description: "Availability zone ID.",
83+
},
84+
"node_count": {
85+
Type: schema.TypeInt,
86+
Computed: true,
87+
Description: "Number of nodes.",
88+
},
89+
},
90+
},
91+
},
92+
"max_storage": {
93+
Type: schema.TypeInt,
94+
Computed: true,
95+
Description: "Maximum storage capacity, unit: MB.",
96+
},
97+
"can_edit_route": {
98+
Type: schema.TypeBool,
99+
Computed: true,
100+
Description: "Can the route be modifiedNote: This field may return null, indicating that no valid value can be obtained.",
101+
},
102+
},
103+
},
104+
},
105+
"network_access_point_infos": {
106+
Computed: true,
107+
Type: schema.TypeList,
108+
Description: "Cluster network access point informationNote: This field may return null, indicating that no valid value can be obtained.",
109+
Elem: &schema.Resource{
110+
Schema: map[string]*schema.Schema{
111+
"vpc_id": {
112+
Type: schema.TypeString,
113+
Computed: true,
114+
Description: "The id of the vpc, the supporting network and the access point of the public network, this field is emptyNote: This field may return null, indicating that no valid value can be obtained.",
115+
},
116+
"subnet_id": {
117+
Type: schema.TypeString,
118+
Computed: true,
119+
Description: "Subnet id, support network and public network access point, this field is emptyNote: This field may return null, indicating that no valid value can be obtained.",
120+
},
121+
"endpoint": {
122+
Type: schema.TypeString,
123+
Computed: true,
124+
Description: "access address.",
125+
},
126+
"instance_id": {
127+
Type: schema.TypeString,
128+
Computed: true,
129+
Description: "instance id.",
130+
},
131+
"route_type": {
132+
Type: schema.TypeInt,
133+
Computed: true,
134+
Description: "Access point type: 0: support network access point 1: VPC access point 2: public network access point.",
135+
},
136+
},
137+
},
138+
},
139+
"cluster_spec_info": {
140+
Computed: true,
141+
Type: schema.TypeList,
142+
Description: "Cluster specification informationNote: This field may return null, indicating that no valid value can be obtained.",
143+
Elem: &schema.Resource{
144+
Schema: map[string]*schema.Schema{
145+
"spec_name": {
146+
Type: schema.TypeString,
147+
Computed: true,
148+
Description: "Cluster specification name.",
149+
},
150+
"max_tps": {
151+
Type: schema.TypeInt,
152+
Computed: true,
153+
Description: "peak tps.",
154+
},
155+
"max_band_width": {
156+
Type: schema.TypeInt,
157+
Computed: true,
158+
Description: "peak bandwidth. Unit: mbps.",
159+
},
160+
"max_namespaces": {
161+
Type: schema.TypeInt,
162+
Computed: true,
163+
Description: "Maximum number of namespaces.",
164+
},
165+
"max_topics": {
166+
Type: schema.TypeInt,
167+
Computed: true,
168+
Description: "Maximum number of topic partitions.",
169+
},
170+
"scalable_tps": {
171+
Type: schema.TypeInt,
172+
Computed: true,
173+
Description: "Elastic TPS outside specificationNote: This field may return null, indicating that no valid value can be obtained.",
174+
},
175+
},
176+
},
177+
},
178+
"result_output_file": {
179+
Type: schema.TypeString,
180+
Optional: true,
181+
Description: "Used to save results.",
182+
},
183+
},
184+
}
185+
}
186+
187+
func dataSourceTencentCloudTdmqProInstanceDetailRead(d *schema.ResourceData, meta interface{}) error {
188+
defer logElapsed("data_source.tencentcloud_tdmq_pro_instance_detail.read")()
189+
defer inconsistentCheck(d, meta)()
190+
191+
var (
192+
logId = getLogId(contextNil)
193+
ctx = context.WithValue(context.TODO(), logIdKey, logId)
194+
service = TdmqService{client: meta.(*TencentCloudClient).apiV3Conn}
195+
clusterInfo *tdmq.DescribePulsarProInstanceDetailResponseParams
196+
clusterId string
197+
)
198+
199+
paramMap := make(map[string]interface{})
200+
if v, ok := d.GetOk("cluster_id"); ok {
201+
paramMap["ClusterId"] = helper.String(v.(string))
202+
clusterId = v.(string)
203+
}
204+
205+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
206+
result, e := service.DescribeTdmqProInstanceDetailByFilter(ctx, paramMap)
207+
if e != nil {
208+
return retryError(e)
209+
}
210+
211+
clusterInfo = result
212+
return nil
213+
})
214+
215+
if err != nil {
216+
return err
217+
}
218+
219+
if clusterInfo != nil {
220+
pulsarProClusterInfoMap := map[string]interface{}{}
221+
tmpList := []interface{}{}
222+
223+
if clusterInfo.ClusterInfo.ClusterId != nil {
224+
pulsarProClusterInfoMap["cluster_id"] = clusterInfo.ClusterInfo.ClusterId
225+
}
226+
227+
if clusterInfo.ClusterInfo.ClusterName != nil {
228+
pulsarProClusterInfoMap["cluster_name"] = clusterInfo.ClusterInfo.ClusterName
229+
}
230+
231+
if clusterInfo.ClusterInfo.Remark != nil {
232+
pulsarProClusterInfoMap["remark"] = clusterInfo.ClusterInfo.Remark
233+
}
234+
235+
if clusterInfo.ClusterInfo.CreateTime != nil {
236+
pulsarProClusterInfoMap["create_time"] = clusterInfo.ClusterInfo.CreateTime
237+
}
238+
239+
if clusterInfo.ClusterInfo.Status != nil {
240+
pulsarProClusterInfoMap["status"] = clusterInfo.ClusterInfo.Status
241+
}
242+
243+
if clusterInfo.ClusterInfo.Version != nil {
244+
pulsarProClusterInfoMap["version"] = clusterInfo.ClusterInfo.Version
245+
}
246+
247+
if clusterInfo.ClusterInfo.NodeDistribution != nil {
248+
nodeDistributionList := []interface{}{}
249+
for _, nodeDistribution := range clusterInfo.ClusterInfo.NodeDistribution {
250+
nodeDistributionMap := map[string]interface{}{}
251+
252+
if nodeDistribution.ZoneName != nil {
253+
nodeDistributionMap["zone_name"] = nodeDistribution.ZoneName
254+
}
255+
256+
if nodeDistribution.ZoneId != nil {
257+
nodeDistributionMap["zone_id"] = nodeDistribution.ZoneId
258+
}
259+
260+
if nodeDistribution.NodeCount != nil {
261+
nodeDistributionMap["node_count"] = nodeDistribution.NodeCount
262+
}
263+
264+
nodeDistributionList = append(nodeDistributionList, nodeDistributionMap)
265+
}
266+
267+
pulsarProClusterInfoMap["node_distribution"] = nodeDistributionList
268+
}
269+
270+
if clusterInfo.ClusterInfo.MaxStorage != nil {
271+
pulsarProClusterInfoMap["max_storage"] = clusterInfo.ClusterInfo.MaxStorage
272+
}
273+
274+
if clusterInfo.ClusterInfo.CanEditRoute != nil {
275+
pulsarProClusterInfoMap["can_edit_route"] = clusterInfo.ClusterInfo.CanEditRoute
276+
}
277+
278+
tmpList = append(tmpList, pulsarProClusterInfoMap)
279+
_ = d.Set("cluster_info", tmpList)
280+
}
281+
282+
if clusterInfo.NetworkAccessPointInfos != nil {
283+
tmpList := []interface{}{}
284+
for _, pulsarNetworkAccessPointInfo := range clusterInfo.NetworkAccessPointInfos {
285+
pulsarNetworkAccessPointInfoMap := map[string]interface{}{}
286+
287+
if pulsarNetworkAccessPointInfo.VpcId != nil {
288+
pulsarNetworkAccessPointInfoMap["vpc_id"] = pulsarNetworkAccessPointInfo.VpcId
289+
}
290+
291+
if pulsarNetworkAccessPointInfo.SubnetId != nil {
292+
pulsarNetworkAccessPointInfoMap["subnet_id"] = pulsarNetworkAccessPointInfo.SubnetId
293+
}
294+
295+
if pulsarNetworkAccessPointInfo.Endpoint != nil {
296+
pulsarNetworkAccessPointInfoMap["endpoint"] = pulsarNetworkAccessPointInfo.Endpoint
297+
}
298+
299+
if pulsarNetworkAccessPointInfo.InstanceId != nil {
300+
pulsarNetworkAccessPointInfoMap["instance_id"] = pulsarNetworkAccessPointInfo.InstanceId
301+
}
302+
303+
if pulsarNetworkAccessPointInfo.RouteType != nil {
304+
pulsarNetworkAccessPointInfoMap["route_type"] = pulsarNetworkAccessPointInfo.RouteType
305+
}
306+
307+
tmpList = append(tmpList, pulsarNetworkAccessPointInfoMap)
308+
}
309+
310+
_ = d.Set("network_access_point_infos", tmpList)
311+
}
312+
313+
if clusterInfo.ClusterSpecInfo != nil {
314+
pulsarProClusterSpecInfoMap := map[string]interface{}{}
315+
tmpList := []interface{}{}
316+
317+
if clusterInfo.ClusterSpecInfo.SpecName != nil {
318+
pulsarProClusterSpecInfoMap["spec_name"] = clusterInfo.ClusterSpecInfo.SpecName
319+
}
320+
321+
if clusterInfo.ClusterSpecInfo.MaxTps != nil {
322+
pulsarProClusterSpecInfoMap["max_tps"] = clusterInfo.ClusterSpecInfo.MaxTps
323+
}
324+
325+
if clusterInfo.ClusterSpecInfo.MaxBandWidth != nil {
326+
pulsarProClusterSpecInfoMap["max_band_width"] = clusterInfo.ClusterSpecInfo.MaxBandWidth
327+
}
328+
329+
if clusterInfo.ClusterSpecInfo.MaxNamespaces != nil {
330+
pulsarProClusterSpecInfoMap["max_namespaces"] = clusterInfo.ClusterSpecInfo.MaxNamespaces
331+
}
332+
333+
if clusterInfo.ClusterSpecInfo.MaxTopics != nil {
334+
pulsarProClusterSpecInfoMap["max_topics"] = clusterInfo.ClusterSpecInfo.MaxTopics
335+
}
336+
337+
if clusterInfo.ClusterSpecInfo.ScalableTps != nil {
338+
pulsarProClusterSpecInfoMap["scalable_tps"] = clusterInfo.ClusterSpecInfo.ScalableTps
339+
}
340+
341+
tmpList = append(tmpList, pulsarProClusterSpecInfoMap)
342+
_ = d.Set("cluster_spec_info", tmpList)
343+
}
344+
345+
d.SetId(clusterId)
346+
output, ok := d.GetOk("result_output_file")
347+
if ok && output.(string) != "" {
348+
if e := writeToFile(output.(string), d); e != nil {
349+
return e
350+
}
351+
}
352+
353+
return nil
354+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 TestAccTencentCloudNeedFixTdmqProInstanceDetailDataSource_basic -v
10+
func TestAccTencentCloudNeedFixTdmqProInstanceDetailDataSource_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: testAccTdmqProInstanceDetailDataSource,
20+
Check: resource.ComposeTestCheckFunc(
21+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_tdmq_pro_instance_detail.pro_instance_detail"),
22+
),
23+
},
24+
},
25+
})
26+
}
27+
28+
const testAccTdmqProInstanceDetailDataSource = `
29+
data "tencentcloud_tdmq_pro_instance_detail" "pro_instance_detail" {
30+
cluster_id = "pulsar-5z3g4227qnwr"
31+
}
32+
`

0 commit comments

Comments
 (0)