Skip to content

Commit 619bf5a

Browse files
gitmknanonymous
andauthored
feat: support tsf group (#1889)
* feat: support tsf group' * feat: add changelog * feat: add doc --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent eed5a06 commit 619bf5a

13 files changed

+1471
-0
lines changed

.changelog/1889.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_tsf_container_group
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_tsf_groups
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_tsf_ms_api_list
11+
```
Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
/*
2+
Use this data source to query detailed information of tsf container_group
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_tsf_container_group" "container_group" {
8+
application_id = "application-a24x29xv"
9+
search_word = "keep"
10+
order_by = "createTime"
11+
order_type = 0
12+
cluster_id = "cluster-vwgj5e6y"
13+
namespace_id = "namespace-aemrg36v"
14+
}
15+
```
16+
*/
17+
package tencentcloud
18+
19+
import (
20+
"context"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
23+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
24+
tsf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf/v20180326"
25+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
26+
)
27+
28+
func dataSourceTencentCloudTsfContainerGroup() *schema.Resource {
29+
return &schema.Resource{
30+
Read: dataSourceTencentCloudTsfContainerGroupRead,
31+
Schema: map[string]*schema.Schema{
32+
"search_word": {
33+
Optional: true,
34+
Type: schema.TypeString,
35+
Description: "search word, support group name.",
36+
},
37+
38+
"application_id": {
39+
Optional: true,
40+
Type: schema.TypeString,
41+
Description: "ApplicationId, required.",
42+
},
43+
44+
"order_by": {
45+
Optional: true,
46+
Type: schema.TypeString,
47+
Description: "The sorting field. By default, it is the createTime field. Supports id, name, createTime.",
48+
},
49+
50+
"order_type": {
51+
Optional: true,
52+
Type: schema.TypeInt,
53+
Description: "The sorting order. By default, it is 1, indicating descending order. 0 indicates ascending order, and 1 indicates descending order.",
54+
},
55+
56+
"cluster_id": {
57+
Optional: true,
58+
Type: schema.TypeString,
59+
Description: "Cluster Id.",
60+
},
61+
62+
"namespace_id": {
63+
Optional: true,
64+
Type: schema.TypeString,
65+
Description: "Namespace Id.",
66+
},
67+
68+
"result": {
69+
Computed: true,
70+
Type: schema.TypeList,
71+
Description: "result list.",
72+
Elem: &schema.Resource{
73+
Schema: map[string]*schema.Schema{
74+
"content": {
75+
Type: schema.TypeList,
76+
Computed: true,
77+
Description: "List of deployment groups.Note: This field may return null, indicating that no valid value was found.",
78+
Elem: &schema.Resource{
79+
Schema: map[string]*schema.Schema{
80+
"group_id": {
81+
Type: schema.TypeString,
82+
Computed: true,
83+
Description: "Group Id.Note: This field may return null, indicating that no valid value was found.",
84+
},
85+
"group_name": {
86+
Type: schema.TypeString,
87+
Computed: true,
88+
Description: "Group name.Note: This field may return null, indicating that no valid value was found.",
89+
},
90+
"create_time": {
91+
Type: schema.TypeString,
92+
Computed: true,
93+
Description: "Create time.Note: This field may return null, indicating that no valid value was found.",
94+
},
95+
"server": {
96+
Type: schema.TypeString,
97+
Computed: true,
98+
Description: "Image server.Note: This field may return null, indicating that no valid value was found.",
99+
},
100+
"repo_name": {
101+
Type: schema.TypeString,
102+
Computed: true,
103+
Description: "Image name.Note: This field may return null, indicating that no valid value was found.",
104+
},
105+
"tag_name": {
106+
Type: schema.TypeString,
107+
Computed: true,
108+
Description: "Image version Name.Note: This field may return null, indicating that no valid value was found.",
109+
},
110+
"cluster_id": {
111+
Type: schema.TypeString,
112+
Computed: true,
113+
Description: "Cluster Id.Note: This field may return null, indicating that no valid value was found.",
114+
},
115+
"cluster_name": {
116+
Type: schema.TypeString,
117+
Computed: true,
118+
Description: "Cluster name.Note: This field may return null, indicating that no valid value was found.",
119+
},
120+
"namespace_id": {
121+
Type: schema.TypeString,
122+
Computed: true,
123+
Description: "Namespace Id.Note: This field may return null, indicating that no valid value was found.",
124+
},
125+
"namespace_name": {
126+
Type: schema.TypeString,
127+
Computed: true,
128+
Description: "Namespace name.Note: This field may return null, indicating that no valid value was found.",
129+
},
130+
"cpu_request": {
131+
Type: schema.TypeString,
132+
Computed: true,
133+
Description: "The initial amount of CPU, corresponding to K8S request.Note: This field may return null, indicating that no valid value was found.",
134+
},
135+
"cpu_limit": {
136+
Type: schema.TypeString,
137+
Computed: true,
138+
Description: "The maximum amount of CPU, corresponding to K8S limit.Note: This field may return null, indicating that no valid value was found.",
139+
},
140+
"mem_request": {
141+
Type: schema.TypeString,
142+
Computed: true,
143+
Description: "The initial amount of memory allocated in MiB, corresponding to K8S request.Note: This field may return null, indicating that no valid value was found.",
144+
},
145+
"mem_limit": {
146+
Type: schema.TypeString,
147+
Computed: true,
148+
Description: "The maximum amount of memory allocated in MiB, corresponding to K8S limit.Note: This field may return null, indicating that no valid value was found.",
149+
},
150+
"alias": {
151+
Type: schema.TypeString,
152+
Computed: true,
153+
Description: "The Group description.Note: This field may return null, indicating that no valid value was found.",
154+
},
155+
"kube_inject_enable": {
156+
Type: schema.TypeBool,
157+
Computed: true,
158+
Description: "The value of KubeInjectEnable.Note: This field may return null, indicating that no valid value was found.",
159+
},
160+
"updated_time": {
161+
Type: schema.TypeString,
162+
Computed: true,
163+
Description: "Update type.Note: This field may return null, indicating that no valid value was found.",
164+
},
165+
},
166+
},
167+
},
168+
"total_count": {
169+
Type: schema.TypeInt,
170+
Computed: true,
171+
Description: "Total count.",
172+
},
173+
},
174+
},
175+
},
176+
177+
"result_output_file": {
178+
Type: schema.TypeString,
179+
Optional: true,
180+
Description: "Used to save results.",
181+
},
182+
},
183+
}
184+
}
185+
186+
func dataSourceTencentCloudTsfContainerGroupRead(d *schema.ResourceData, meta interface{}) error {
187+
defer logElapsed("data_source.tencentcloud_tsf__container_group.read")()
188+
defer inconsistentCheck(d, meta)()
189+
190+
logId := getLogId(contextNil)
191+
192+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
193+
194+
paramMap := make(map[string]interface{})
195+
if v, ok := d.GetOk("search_word"); ok {
196+
paramMap["SearchWord"] = helper.String(v.(string))
197+
}
198+
199+
if v, ok := d.GetOk("application_id"); ok {
200+
paramMap["ApplicationId"] = helper.String(v.(string))
201+
}
202+
203+
if v, ok := d.GetOk("order_by"); ok {
204+
paramMap["OrderBy"] = helper.String(v.(string))
205+
}
206+
207+
if v, _ := d.GetOk("order_type"); v != nil {
208+
paramMap["OrderType"] = helper.IntInt64(v.(int))
209+
}
210+
211+
if v, ok := d.GetOk("cluster_id"); ok {
212+
paramMap["ClusterId"] = helper.String(v.(string))
213+
}
214+
215+
if v, ok := d.GetOk("namespace_id"); ok {
216+
paramMap["NamespaceId"] = helper.String(v.(string))
217+
}
218+
219+
service := TsfService{client: meta.(*TencentCloudClient).apiV3Conn}
220+
221+
var result *tsf.ContainGroupResult
222+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
223+
response, e := service.DescribeTsfDescriptionContainerGroupByFilter(ctx, paramMap)
224+
if e != nil {
225+
return retryError(e)
226+
}
227+
result = response
228+
return nil
229+
})
230+
if err != nil {
231+
return err
232+
}
233+
234+
ids := make([]string, 0, len(result.Content))
235+
containGroupResultMap := map[string]interface{}{}
236+
if result != nil {
237+
238+
if result.Content != nil {
239+
contentList := []interface{}{}
240+
for _, content := range result.Content {
241+
contentMap := map[string]interface{}{}
242+
243+
if content.GroupId != nil {
244+
contentMap["group_id"] = content.GroupId
245+
}
246+
247+
if content.GroupName != nil {
248+
contentMap["group_name"] = content.GroupName
249+
}
250+
251+
if content.CreateTime != nil {
252+
contentMap["create_time"] = content.CreateTime
253+
}
254+
255+
if content.Server != nil {
256+
contentMap["server"] = content.Server
257+
}
258+
259+
if content.RepoName != nil {
260+
contentMap["repo_name"] = content.RepoName
261+
}
262+
263+
if content.TagName != nil {
264+
contentMap["tag_name"] = content.TagName
265+
}
266+
267+
if content.ClusterId != nil {
268+
contentMap["cluster_id"] = content.ClusterId
269+
}
270+
271+
if content.ClusterName != nil {
272+
contentMap["cluster_name"] = content.ClusterName
273+
}
274+
275+
if content.NamespaceId != nil {
276+
contentMap["namespace_id"] = content.NamespaceId
277+
}
278+
279+
if content.NamespaceName != nil {
280+
contentMap["namespace_name"] = content.NamespaceName
281+
}
282+
283+
if content.CpuRequest != nil {
284+
contentMap["cpu_request"] = content.CpuRequest
285+
}
286+
287+
if content.CpuLimit != nil {
288+
contentMap["cpu_limit"] = content.CpuLimit
289+
}
290+
291+
if content.MemRequest != nil {
292+
contentMap["mem_request"] = content.MemRequest
293+
}
294+
295+
if content.MemLimit != nil {
296+
contentMap["mem_limit"] = content.MemLimit
297+
}
298+
299+
if content.Alias != nil {
300+
contentMap["alias"] = content.Alias
301+
}
302+
303+
if content.KubeInjectEnable != nil {
304+
contentMap["kube_inject_enable"] = content.KubeInjectEnable
305+
}
306+
307+
if content.UpdatedTime != nil {
308+
contentMap["updated_time"] = content.UpdatedTime
309+
}
310+
311+
contentList = append(contentList, contentMap)
312+
ids = append(ids, *content.GroupId)
313+
}
314+
315+
containGroupResultMap["content"] = contentList
316+
}
317+
318+
if result.TotalCount != nil {
319+
containGroupResultMap["total_count"] = result.TotalCount
320+
}
321+
322+
_ = d.Set("result", []interface{}{containGroupResultMap})
323+
}
324+
325+
d.SetId(helper.DataResourceIdsHash(ids))
326+
output, ok := d.GetOk("result_output_file")
327+
if ok && output.(string) != "" {
328+
if e := writeToFile(output.(string), containGroupResultMap); e != nil {
329+
return e
330+
}
331+
}
332+
return nil
333+
}

0 commit comments

Comments
 (0)