Skip to content

Commit df4347c

Browse files
gitmknanonymous
andauthored
feat: support tsf descirbe (#1764)
* feat: support tsf descirbe * feat: add changelog --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent 170cf11 commit df4347c

16 files changed

+1770
-0
lines changed

.changelog/1764.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```release-note:new-data-source
2+
tencentcloud_tsf_config_summary
3+
```
4+
5+
6+
```release-note:new-data-source
7+
tencentcloud_tsf_delivery_config_by_group_id
8+
```
9+
10+
11+
```release-note:new-data-source
12+
tencentcloud_tsf_delivery_configs
13+
```
14+
15+
16+
```release-note:new-data-source
17+
tencentcloud_tsf_public_config_summary
18+
```
19+
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
/*
2+
Use this data source to query detailed information of tsf config_summary
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_tsf_config_summary" "config_summary" {
8+
application_id = "application-a24x29xv"
9+
search_word = "terraform"
10+
order_by = "last_update_time"
11+
order_type = 0
12+
disable_program_auth_check = true
13+
config_id_list = ["dcfg-y54wzk3a"]
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 dataSourceTencentCloudTsfConfigSummary() *schema.Resource {
29+
return &schema.Resource{
30+
Read: dataSourceTencentCloudTsfConfigSummaryRead,
31+
Schema: map[string]*schema.Schema{
32+
"application_id": {
33+
Optional: true,
34+
Type: schema.TypeString,
35+
Description: "Application ID. If not passed, the query will be for all.",
36+
},
37+
38+
"search_word": {
39+
Optional: true,
40+
Type: schema.TypeString,
41+
Description: "Query keyword, fuzzy query: application name, configuration item name. If not passed, the query will be for all.",
42+
},
43+
44+
"order_by": {
45+
Optional: true,
46+
Type: schema.TypeString,
47+
Description: "Order term. support Sort by time: creation_time; or Sort by name: config_name.",
48+
},
49+
50+
"order_type": {
51+
Optional: true,
52+
Type: schema.TypeInt,
53+
Description: "Pass 0 for ascending order and 1 for descending order.",
54+
},
55+
56+
"config_tag_list": {
57+
Optional: true,
58+
Type: schema.TypeSet,
59+
Elem: &schema.Schema{
60+
Type: schema.TypeString,
61+
},
62+
Description: "config tag list.",
63+
},
64+
65+
"disable_program_auth_check": {
66+
Optional: true,
67+
Type: schema.TypeBool,
68+
Description: "Whether to disable dataset authentication.",
69+
},
70+
71+
"config_id_list": {
72+
Optional: true,
73+
Type: schema.TypeSet,
74+
Elem: &schema.Schema{
75+
Type: schema.TypeString,
76+
},
77+
Description: "Config Id List.",
78+
},
79+
80+
"result": {
81+
Computed: true,
82+
Type: schema.TypeList,
83+
Description: "config Page Item.",
84+
Elem: &schema.Resource{
85+
Schema: map[string]*schema.Schema{
86+
"total_count": {
87+
Type: schema.TypeInt,
88+
Computed: true,
89+
Description: "total count.",
90+
},
91+
"content": {
92+
Type: schema.TypeList,
93+
Computed: true,
94+
Description: "config list.",
95+
Elem: &schema.Resource{
96+
Schema: map[string]*schema.Schema{
97+
"config_id": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
Description: "Configuration item ID.Note: This field may return null, indicating that no valid value was found.",
101+
},
102+
"config_name": {
103+
Type: schema.TypeString,
104+
Computed: true,
105+
Description: "Configuration name.Note: This field may return null, indicating that no valid value was found.",
106+
},
107+
"config_version": {
108+
Type: schema.TypeString,
109+
Computed: true,
110+
Description: "Configuration version. Note: This field may return null, indicating that no valid value was found.",
111+
},
112+
"config_version_desc": {
113+
Type: schema.TypeString,
114+
Computed: true,
115+
Description: "Configuration version description.Note: This field may return null, indicating that no valid value was found.",
116+
},
117+
"config_value": {
118+
Type: schema.TypeString,
119+
Computed: true,
120+
Description: "Configuration value.Note: This field may return null, indicating that no valid value was found.",
121+
},
122+
"config_type": {
123+
Type: schema.TypeString,
124+
Computed: true,
125+
Description: "Config type. Note: This field may return null, indicating that no valid value was found.",
126+
},
127+
"creation_time": {
128+
Type: schema.TypeString,
129+
Computed: true,
130+
Description: "Create time.Note: This field may return null, indicating that no valid value was found.",
131+
},
132+
"application_id": {
133+
Type: schema.TypeString,
134+
Computed: true,
135+
Description: "Application ID.Note: This field may return null, indicating that no valid value was found.",
136+
},
137+
"application_name": {
138+
Type: schema.TypeString,
139+
Computed: true,
140+
Description: "Application Name. Note: This field may return null, indicating that no valid value was found.",
141+
},
142+
"delete_flag": {
143+
Type: schema.TypeBool,
144+
Computed: true,
145+
Description: "Deletion flag, true: deletable; false: not deletable.Note: This field may return null, indicating that no valid value was found.",
146+
},
147+
"last_update_time": {
148+
Type: schema.TypeString,
149+
Computed: true,
150+
Description: "Last update time.Note: This field may return null, indicating that no valid value was found.",
151+
},
152+
"config_version_count": {
153+
Type: schema.TypeInt,
154+
Computed: true,
155+
Description: "Configure version count.Note: This field may return null, indicating that no valid value was found.",
156+
},
157+
},
158+
},
159+
},
160+
},
161+
},
162+
},
163+
164+
"result_output_file": {
165+
Type: schema.TypeString,
166+
Optional: true,
167+
Description: "Used to save results.",
168+
},
169+
},
170+
}
171+
}
172+
173+
func dataSourceTencentCloudTsfConfigSummaryRead(d *schema.ResourceData, meta interface{}) error {
174+
defer logElapsed("data_source.tencentcloud_tsf_config_summary.read")()
175+
defer inconsistentCheck(d, meta)()
176+
177+
logId := getLogId(contextNil)
178+
179+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
180+
181+
paramMap := make(map[string]interface{})
182+
if v, ok := d.GetOk("application_id"); ok {
183+
paramMap["ApplicationId"] = helper.String(v.(string))
184+
}
185+
186+
if v, ok := d.GetOk("search_word"); ok {
187+
paramMap["SearchWord"] = helper.String(v.(string))
188+
}
189+
190+
if v, ok := d.GetOk("order_by"); ok {
191+
paramMap["OrderBy"] = helper.String(v.(string))
192+
}
193+
194+
if v, _ := d.GetOk("order_type"); v != nil {
195+
paramMap["OrderType"] = helper.IntInt64(v.(int))
196+
}
197+
198+
if v, ok := d.GetOk("config_tag_list"); ok {
199+
configTagListSet := v.(*schema.Set).List()
200+
paramMap["ConfigTagList"] = helper.InterfacesStringsPoint(configTagListSet)
201+
}
202+
203+
if v, _ := d.GetOk("disable_program_auth_check"); v != nil {
204+
paramMap["DisableProgramAuthCheck"] = helper.Bool(v.(bool))
205+
}
206+
207+
if v, ok := d.GetOk("config_id_list"); ok {
208+
configIdListSet := v.(*schema.Set).List()
209+
paramMap["ConfigIdList"] = helper.InterfacesStringsPoint(configIdListSet)
210+
}
211+
212+
service := TsfService{client: meta.(*TencentCloudClient).apiV3Conn}
213+
214+
var config *tsf.TsfPageConfig
215+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
216+
result, e := service.DescribeTsfConfigSummaryByFilter(ctx, paramMap)
217+
if e != nil {
218+
return retryError(e)
219+
}
220+
config = result
221+
return nil
222+
})
223+
if err != nil {
224+
return err
225+
}
226+
227+
ids := make([]string, 0, len(config.Content))
228+
tsfPageConfigMap := map[string]interface{}{}
229+
if config != nil {
230+
if config.TotalCount != nil {
231+
tsfPageConfigMap["total_count"] = config.TotalCount
232+
}
233+
234+
if config.Content != nil {
235+
contentList := []interface{}{}
236+
for _, content := range config.Content {
237+
contentMap := map[string]interface{}{}
238+
239+
if content.ConfigId != nil {
240+
contentMap["config_id"] = content.ConfigId
241+
}
242+
243+
if content.ConfigName != nil {
244+
contentMap["config_name"] = content.ConfigName
245+
}
246+
247+
if content.ConfigVersion != nil {
248+
contentMap["config_version"] = content.ConfigVersion
249+
}
250+
251+
if content.ConfigVersionDesc != nil {
252+
contentMap["config_version_desc"] = content.ConfigVersionDesc
253+
}
254+
255+
if content.ConfigValue != nil {
256+
contentMap["config_value"] = content.ConfigValue
257+
}
258+
259+
if content.ConfigType != nil {
260+
contentMap["config_type"] = content.ConfigType
261+
}
262+
263+
if content.CreationTime != nil {
264+
contentMap["creation_time"] = content.CreationTime
265+
}
266+
267+
if content.ApplicationId != nil {
268+
contentMap["application_id"] = content.ApplicationId
269+
}
270+
271+
if content.ApplicationName != nil {
272+
contentMap["application_name"] = content.ApplicationName
273+
}
274+
275+
if content.DeleteFlag != nil {
276+
contentMap["delete_flag"] = content.DeleteFlag
277+
}
278+
279+
if content.LastUpdateTime != nil {
280+
contentMap["last_update_time"] = content.LastUpdateTime
281+
}
282+
283+
if content.ConfigVersionCount != nil {
284+
contentMap["config_version_count"] = content.ConfigVersionCount
285+
}
286+
287+
contentList = append(contentList, contentMap)
288+
ids = append(ids, *content.ConfigId)
289+
}
290+
291+
tsfPageConfigMap["content"] = contentList
292+
}
293+
294+
_ = d.Set("result", []interface{}{tsfPageConfigMap})
295+
}
296+
297+
d.SetId(helper.DataResourceIdsHash(ids))
298+
output, ok := d.GetOk("result_output_file")
299+
if ok && output.(string) != "" {
300+
if e := writeToFile(output.(string), tsfPageConfigMap); e != nil {
301+
return e
302+
}
303+
}
304+
return nil
305+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 TestAccTencentCloudTsfConfigSummaryDataSource_basic -v
10+
func TestAccTencentCloudTsfConfigSummaryDataSource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_TSF) },
14+
Providers: testAccProviders,
15+
Steps: []resource.TestStep{
16+
{
17+
Config: testAccTsfConfigSummaryDataSource,
18+
Check: resource.ComposeTestCheckFunc(
19+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_tsf_config_summary.config_summary"),
20+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.#"),
21+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.total_count"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.content.#"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.content.0.application_id"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.content.0.application_name"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.content.0.config_id"),
26+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.content.0.config_name"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.content.0.config_version_count"),
28+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.content.0.delete_flag"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_tsf_config_summary.config_summary", "result.0.content.0.last_update_time"),
30+
),
31+
},
32+
},
33+
})
34+
}
35+
36+
const testAccTsfConfigSummaryDataSource = `
37+
38+
data "tencentcloud_tsf_config_summary" "config_summary" {
39+
application_id = "application-a24x29xv"
40+
search_word = "terraform"
41+
order_by = "last_update_time"
42+
order_type = 0
43+
disable_program_auth_check = true
44+
config_id_list = ["dcfg-y54wzk3a"]
45+
}
46+
47+
`

0 commit comments

Comments
 (0)