Skip to content

Commit 211ec7f

Browse files
authored
add cls resource (#1817)
* add cls resource * add changelog
1 parent fa2365b commit 211ec7f

23 files changed

+2239
-1312
lines changed

.changelog/1817.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-resource
2+
tencentcloud_cls_ckafka_consumer
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_cls_cos_recharge
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_cls_export
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_cls_shipper_tasks
15+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ require (
3737
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.634
3838
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.599
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
40-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.658
41-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.662
40+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.663
41+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.663
4242
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.572

go.sum

Lines changed: 6 additions & 1304 deletions
Large diffs are not rendered by default.
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/*
2+
Use this data source to query detailed information of cls shipper_tasks
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_cls_shipper_tasks" "shipper_tasks" {
8+
shipper_id = "dbde3c9b-ea16-4032-bc2a-d8fa65567a8e"
9+
start_time = 160749910700
10+
end_time = 160749910800
11+
}
12+
```
13+
*/
14+
package tencentcloud
15+
16+
import (
17+
"context"
18+
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
21+
cls "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016"
22+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
23+
)
24+
25+
func dataSourceTencentCloudClsShipperTasks() *schema.Resource {
26+
return &schema.Resource{
27+
Read: dataSourceTencentCloudClsShipperTasksRead,
28+
Schema: map[string]*schema.Schema{
29+
"shipper_id": {
30+
Required: true,
31+
Type: schema.TypeString,
32+
Description: "shipper id.",
33+
},
34+
35+
"start_time": {
36+
Required: true,
37+
Type: schema.TypeInt,
38+
Description: "start time(ms).",
39+
},
40+
41+
"end_time": {
42+
Required: true,
43+
Type: schema.TypeInt,
44+
Description: "end time(ms).",
45+
},
46+
47+
"tasks": {
48+
Computed: true,
49+
Type: schema.TypeList,
50+
Description: ".",
51+
Elem: &schema.Resource{
52+
Schema: map[string]*schema.Schema{
53+
"task_id": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
Description: "task id.",
57+
},
58+
"shipper_id": {
59+
Type: schema.TypeString,
60+
Computed: true,
61+
Description: "shipper id.",
62+
},
63+
"topic_id": {
64+
Type: schema.TypeString,
65+
Computed: true,
66+
Description: "topic id.",
67+
},
68+
"range_start": {
69+
Type: schema.TypeInt,
70+
Computed: true,
71+
Description: "start time of current task (ms).",
72+
},
73+
"range_end": {
74+
Type: schema.TypeInt,
75+
Computed: true,
76+
Description: "end time of current task (ms).",
77+
},
78+
"start_time": {
79+
Type: schema.TypeInt,
80+
Computed: true,
81+
Description: "start time(ms).",
82+
},
83+
"end_time": {
84+
Type: schema.TypeInt,
85+
Computed: true,
86+
Description: "end time(ms).",
87+
},
88+
"status": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
Description: "status of current shipper task.",
92+
},
93+
"message": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
Description: "detail info.",
97+
},
98+
},
99+
},
100+
},
101+
102+
"result_output_file": {
103+
Type: schema.TypeString,
104+
Optional: true,
105+
Description: "Used to save results.",
106+
},
107+
},
108+
}
109+
}
110+
111+
func dataSourceTencentCloudClsShipperTasksRead(d *schema.ResourceData, meta interface{}) error {
112+
defer logElapsed("data_source.tencentcloud_cls_shipper_tasks.read")()
113+
defer inconsistentCheck(d, meta)()
114+
115+
logId := getLogId(contextNil)
116+
117+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
118+
119+
paramMap := make(map[string]interface{})
120+
if v, ok := d.GetOk("shipper_id"); ok {
121+
paramMap["ShipperId"] = helper.String(v.(string))
122+
}
123+
124+
if v, _ := d.GetOk("start_time"); v != nil {
125+
paramMap["StartTime"] = helper.IntInt64(v.(int))
126+
}
127+
128+
if v, _ := d.GetOk("end_time"); v != nil {
129+
paramMap["EndTime"] = helper.IntInt64(v.(int))
130+
}
131+
132+
service := ClsService{client: meta.(*TencentCloudClient).apiV3Conn}
133+
134+
var tasks []*cls.ShipperTaskInfo
135+
136+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
137+
result, e := service.DescribeClsShipperTasksByFilter(ctx, paramMap)
138+
if e != nil {
139+
return retryError(e)
140+
}
141+
tasks = result
142+
return nil
143+
})
144+
if err != nil {
145+
return err
146+
}
147+
148+
ids := make([]string, 0, len(tasks))
149+
tmpList := make([]map[string]interface{}, 0, len(tasks))
150+
151+
if tasks != nil {
152+
for _, shipperTaskInfo := range tasks {
153+
shipperTaskInfoMap := map[string]interface{}{}
154+
155+
if shipperTaskInfo.TaskId != nil {
156+
shipperTaskInfoMap["task_id"] = shipperTaskInfo.TaskId
157+
}
158+
159+
if shipperTaskInfo.ShipperId != nil {
160+
shipperTaskInfoMap["shipper_id"] = shipperTaskInfo.ShipperId
161+
}
162+
163+
if shipperTaskInfo.TopicId != nil {
164+
shipperTaskInfoMap["topic_id"] = shipperTaskInfo.TopicId
165+
}
166+
167+
if shipperTaskInfo.RangeStart != nil {
168+
shipperTaskInfoMap["range_start"] = shipperTaskInfo.RangeStart
169+
}
170+
171+
if shipperTaskInfo.RangeEnd != nil {
172+
shipperTaskInfoMap["range_end"] = shipperTaskInfo.RangeEnd
173+
}
174+
175+
if shipperTaskInfo.StartTime != nil {
176+
shipperTaskInfoMap["start_time"] = shipperTaskInfo.StartTime
177+
}
178+
179+
if shipperTaskInfo.EndTime != nil {
180+
shipperTaskInfoMap["end_time"] = shipperTaskInfo.EndTime
181+
}
182+
183+
if shipperTaskInfo.Status != nil {
184+
shipperTaskInfoMap["status"] = shipperTaskInfo.Status
185+
}
186+
187+
if shipperTaskInfo.Message != nil {
188+
shipperTaskInfoMap["message"] = shipperTaskInfo.Message
189+
}
190+
191+
ids = append(ids, *shipperTaskInfo.ShipperId)
192+
tmpList = append(tmpList, shipperTaskInfoMap)
193+
}
194+
195+
_ = d.Set("tasks", tmpList)
196+
}
197+
198+
d.SetId(helper.DataResourceIdsHash(ids))
199+
output, ok := d.GetOk("result_output_file")
200+
if ok && output.(string) != "" {
201+
if e := writeToFile(output.(string), tmpList); e != nil {
202+
return e
203+
}
204+
}
205+
return nil
206+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudNeedFixClsShipperTasksDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccClsShipperTasksDataSource,
19+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_cls_shipper_tasks.shipper_tasks")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccClsShipperTasksDataSource = `
26+
27+
data "tencentcloud_cls_shipper_tasks" "shipper_tasks" {
28+
shipper_id = "dbde3c9b-ea16-4032-bc2a-d8fa65567a8e"
29+
start_time = 160749910700
30+
end_time = 160749910800
31+
}
32+
33+
`

tencentcloud/provider.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,12 @@ Cloud Log Service(CLS)
862862
tencentcloud_cls_index
863863
tencentcloud_cls_alarm
864864
tencentcloud_cls_alarm_notice
865+
tencentcloud_cls_ckafka_consumer
866+
tencentcloud_cls_cos_recharge
867+
tencentcloud_cls_export
868+
869+
Data Source
870+
tencentcloud_cls_shipper_tasks
865871
866872
TencentCloud Lighthouse(Lighthouse)
867873
Resource
@@ -1724,6 +1730,7 @@ func Provider() *schema.Provider {
17241730
"tencentcloud_lighthouse_instance_disk_num": dataSourceTencentCloudLighthouseInstanceDiskNum(),
17251731
"tencentcloud_lighthouse_instance_blueprint": dataSourceTencentCloudLighthouseInstanceBlueprint(),
17261732
"tencentcloud_lighthouse_disk_config": dataSourceTencentCloudLighthouseDiskConfig(),
1733+
"tencentcloud_cls_shipper_tasks": dataSourceTencentCloudClsShipperTasks(),
17271734
},
17281735

17291736
ResourcesMap: map[string]*schema.Resource{
@@ -2064,6 +2071,9 @@ func Provider() *schema.Provider {
20642071
"tencentcloud_cls_index": resourceTencentCloudClsIndex(),
20652072
"tencentcloud_cls_alarm": resourceTencentCloudClsAlarm(),
20662073
"tencentcloud_cls_alarm_notice": resourceTencentCloudClsAlarmNotice(),
2074+
"tencentcloud_cls_ckafka_consumer": resourceTencentCloudClsCkafkaConsumer(),
2075+
"tencentcloud_cls_cos_recharge": resourceTencentCloudClsCosRecharge(),
2076+
"tencentcloud_cls_export": resourceTencentCloudClsExport(),
20672077
"tencentcloud_lighthouse_instance": resourceTencentCloudLighthouseInstance(),
20682078
"tencentcloud_tem_environment": resourceTencentCloudTemEnvironment(),
20692079
"tencentcloud_tem_application": resourceTencentCloudTemApplication(),

0 commit comments

Comments
 (0)