Skip to content

Commit 4f7a2e8

Browse files
committed
feat(dnspod): support tags
1 parent 010261e commit 4f7a2e8

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

tencentcloud/data_source_tc_dnspod_domain_list.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ data "tencentcloud_dnspod_domain_list" "domain_list" {
1919
record_count_begin = 0
2020
record_count_end = 100
2121
project_id = -1
22+
tags {
23+
tag_key = "created_by"
24+
tag_value = ["terraform"]
25+
}
2226
}
2327
2428
```
@@ -126,6 +130,27 @@ func dataSourceTencentCloudDnspodDomainList() *schema.Resource {
126130
Description: "Project ID.",
127131
},
128132

133+
"tags": {
134+
Optional: true,
135+
Type: schema.TypeList,
136+
Description: "Tag description list.",
137+
Elem: &schema.Resource{
138+
Schema: map[string]*schema.Schema{
139+
"tag_key": {
140+
Type: schema.TypeString,
141+
Required: true,
142+
Description: "Field to be filtered.",
143+
},
144+
"tag_value": {
145+
Type: schema.TypeSet,
146+
Elem: &schema.Schema{Type: schema.TypeString},
147+
Required: true,
148+
Description: "Filter value of the field.",
149+
},
150+
},
151+
},
152+
},
153+
129154
"domain_list": {
130155
Computed: true,
131156
Type: schema.TypeList,
@@ -268,6 +293,12 @@ func dataSourceTencentCloudDnspodDomainList() *schema.Resource {
268293
},
269294
},
270295

296+
// "tags": {
297+
// Type: schema.TypeMap,
298+
// Optional: true,
299+
// Description: "Tag description list.",
300+
// },
301+
271302
"result_output_file": {
272303
Type: schema.TypeString,
273304
Optional: true,
@@ -344,6 +375,30 @@ func dataSourceTencentCloudDnspodDomainListRead(d *schema.ResourceData, meta int
344375
paramMap["ProjectId"] = helper.IntInt64(v.(int))
345376
}
346377

378+
// tags := helper.GetTagsFilter(d, "tags")
379+
if v, ok := d.GetOk("tags"); ok {
380+
tagsSet := v.([]interface{})
381+
tmpSet := make([]*dnspod.TagItemFilter, 0, len(tagsSet))
382+
383+
for _, item := range tagsSet {
384+
filter := dnspod.TagItemFilter{}
385+
filterMap := item.(map[string]interface{})
386+
387+
if v, ok := filterMap["tag_key"]; ok {
388+
filter.TagKey = helper.String(v.(string))
389+
}
390+
391+
if v, ok := filterMap["tag_value"]; ok {
392+
valuesSet := v.(*schema.Set).List()
393+
filter.TagValue = helper.InterfacesStringsPoint(valuesSet)
394+
}
395+
396+
tmpSet = append(tmpSet, &filter)
397+
}
398+
399+
paramMap["Tags"] = tmpSet
400+
}
401+
347402
service := DnspodService{client: meta.(*TencentCloudClient).apiV3Conn}
348403

349404
var domainList []*dnspod.DomainListItem
@@ -454,6 +509,25 @@ func dataSourceTencentCloudDnspodDomainListRead(d *schema.ResourceData, meta int
454509
domainListItemMap["owner"] = domainListItem.Owner
455510
}
456511

512+
if domainListItem.TagList != nil {
513+
tagListList := []interface{}{}
514+
for _, tagList := range domainListItem.TagList {
515+
tagListMap := map[string]interface{}{}
516+
517+
if tagList.TagKey != nil {
518+
tagListMap["tag_key"] = tagList.TagKey
519+
}
520+
521+
if tagList.TagValue != nil {
522+
tagListMap["tag_value"] = tagList.TagValue
523+
}
524+
525+
tagListList = append(tagListList, tagListMap)
526+
}
527+
528+
domainListItemMap["tag_list"] = []interface{}{tagListList}
529+
}
530+
457531
ids = append(ids, strconv.FormatUint(*domainListItem.DomainId, 10))
458532
tmpList = append(tmpList, domainListItemMap)
459533
}

tencentcloud/data_source_tc_dnspod_domain_list_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ data "tencentcloud_dnspod_domain_list" "domain_list" {
3838
record_count_begin = 0
3939
record_count_end = 100
4040
project_id = -1
41+
tags {
42+
tag_key = "created_by"
43+
tag_value = ["terraform"]
44+
}
4145
}
4246
4347
`

tencentcloud/service_tencentcloud_dnspod.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ func (me *DnspodService) DescribeDnspodDomainListByFilter(ctx context.Context, p
205205
if k == "ProjectId" {
206206
request.ProjectId = v.(*int64)
207207
}
208+
if k == "Tags" {
209+
request.Tags = v.([]*dnspod.TagItemFilter)
210+
}
208211
}
209212

210213
ratelimit.Check(request.GetAction())

website/docs/d/dnspod_domain_list.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ data "tencentcloud_dnspod_domain_list" "domain_list" {
2828
record_count_begin = 0
2929
record_count_end = 100
3030
project_id = -1
31+
tags {
32+
tag_key = "created_by"
33+
tag_value = ["terraform"]
34+
}
3135
}
3236
```
3337

@@ -47,9 +51,15 @@ The following arguments are supported:
4751
* `sort_field` - (Optional, String) Sorting field. Available values are NAME, STATUS, RECORDS, GRADE, UPDATED_ON. NAME: Domain name STATUS: Domain status RECORDS: Number of records GRADE: Package level UPDATED_ON: Update time.
4852
* `sort_type` - (Optional, String) Sorting type, ascending: ASC, descending: DESC.
4953
* `status` - (Optional, Set: [`String`]) Get domain names based on domain status. Available values are ENABLE, LOCK, PAUSE, SPAM. ENABLE: Normal LOCK: Locked PAUSE: Paused SPAM: Banned.
54+
* `tags` - (Optional, List) Tag description list.
5055
* `updated_at_begin` - (Optional, String) The start time of the domain name's update time to be obtained, such as '2021-05-01 03:00:00'.
5156
* `updated_at_end` - (Optional, String) The end time of the domain name's update time to be obtained, such as '2021-05-10 20:00:00'.
5257

58+
The `tags` object supports the following:
59+
60+
* `tag_key` - (Required, String) Field to be filtered.
61+
* `tag_value` - (Required, Set) Filter value of the field.
62+
5363
## Attributes Reference
5464

5565
In addition to all arguments above, the following attributes are exported:

0 commit comments

Comments
 (0)