Skip to content

Commit aaccc2a

Browse files
tongyimingmikatong
and
mikatong
authored
fix(dnspod): [121993505]support sub_domains (#3165)
* support sub_domains * add changelog * update doc --------- Co-authored-by: mikatong <[email protected]>
1 parent 49f5bec commit aaccc2a

File tree

4 files changed

+63
-14
lines changed

4 files changed

+63
-14
lines changed

.changelog/3165.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
data-source/tencentcloud_dnspod_record_list: add `sub_domains` param
3+
```

tencentcloud/services/dnspod/data_source_tc_dnspod_record_list.go

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ func DataSourceTencentCloudDnspodRecordList() *schema.Resource {
2929
},
3030

3131
"sub_domain": {
32-
Optional: true,
33-
Type: schema.TypeString,
34-
Description: "Retrieve resolution records based on the host header of the resolution record. Fuzzy matching is used by default. You can set the IsExactSubdomain parameter to true for precise searching.",
32+
Optional: true,
33+
Type: schema.TypeString,
34+
ConflictsWith: []string{"sub_domains"},
35+
Description: "Retrieve resolution records based on the host header of the resolution record. Fuzzy matching is used by default. You can set the IsExactSubdomain parameter to true for precise searching.",
36+
},
37+
"sub_domains": {
38+
Optional: true,
39+
Type: schema.TypeSet,
40+
Elem: &schema.Schema{Type: schema.TypeString},
41+
ConflictsWith: []string{"sub_domain"},
42+
Description: "Sub domains.",
3543
},
3644

3745
"record_type": {
@@ -381,8 +389,16 @@ func dataSourceTencentCloudDnspodRecordListRead(d *schema.ResourceData, meta int
381389
paramMap["DomainId"] = helper.IntUint64(v.(int))
382390
}
383391

392+
subDomains := make([]string, 0)
384393
if v, ok := d.GetOk("sub_domain"); ok {
385-
paramMap["SubDomain"] = helper.String(v.(string))
394+
subDomains = append(subDomains, v.(string))
395+
}
396+
397+
if v, ok := d.GetOk("sub_domains"); ok {
398+
subDomainList := v.(*schema.Set).List()
399+
for _, subDomain := range subDomainList {
400+
subDomains = append(subDomains, subDomain.(string))
401+
}
386402
}
387403

388404
if v, ok := d.GetOk("record_type"); ok {
@@ -472,16 +488,19 @@ func dataSourceTencentCloudDnspodRecordListRead(d *schema.ResourceData, meta int
472488

473489
var recordList []*dnspod.RecordListItem
474490

475-
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
476-
result, e := service.DescribeDnspodRecordListByFilter(ctx, paramMap)
477-
if e != nil {
478-
return tccommon.RetryError(e)
491+
for _, subDomain := range subDomains {
492+
paramMap["SubDomain"] = helper.String(subDomain)
493+
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
494+
result, e := service.DescribeDnspodRecordListByFilter(ctx, paramMap)
495+
if e != nil {
496+
return tccommon.RetryError(e)
497+
}
498+
recordList = append(recordList, result...)
499+
return nil
500+
})
501+
if err != nil {
502+
return err
479503
}
480-
recordList = result
481-
return nil
482-
})
483-
if err != nil {
484-
return err
485504
}
486505

487506
ids := make([]string, 0, len(recordList))

tencentcloud/services/dnspod/data_source_tc_dnspod_record_list_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func TestAccTencentCloudDnspodRecordListDataSource_basic(t *testing.T) {
1212
t.Parallel()
1313
resource.Test(t, resource.TestCase{
14-
PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_PREPAY) },
14+
PreCheck: func() { tcacctest.AccPreCheck(t) },
1515
Providers: tcacctest.AccProviders,
1616
Steps: []resource.TestStep{
1717
{
@@ -22,6 +22,24 @@ func TestAccTencentCloudDnspodRecordListDataSource_basic(t *testing.T) {
2222
})
2323
}
2424

25+
func TestAccTencentCloudDnspodRecordListDataSource_subDomains(t *testing.T) {
26+
t.Parallel()
27+
resource.Test(t, resource.TestCase{
28+
PreCheck: func() { tcacctest.AccPreCheck(t) },
29+
Providers: tcacctest.AccProviders,
30+
Steps: []resource.TestStep{
31+
{
32+
Config: testAccDnspodRecordListDataSource_subDomains,
33+
Check: resource.ComposeTestCheckFunc(
34+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_dnspod_record_list.subdomains"),
35+
resource.TestCheckResourceAttr("data.tencentcloud_dnspod_record_list.subdomains", "record_list.#", "2"),
36+
resource.TestCheckResourceAttr("data.tencentcloud_dnspod_record_list.subdomains", "instance_list.#", "2"),
37+
),
38+
},
39+
},
40+
})
41+
}
42+
2543
const testAccDnspodRecordListDataSource = `
2644
2745
data "tencentcloud_dnspod_record_list" "record_list" {
@@ -50,3 +68,11 @@ data "tencentcloud_dnspod_record_list" "record_list" {
5068
}
5169
5270
`
71+
72+
const testAccDnspodRecordListDataSource_subDomains = `
73+
data "tencentcloud_dnspod_record_list" "subdomains" {
74+
domain = "mikatong.xyz"
75+
is_exact_sub_domain = true
76+
sub_domains = ["tes1029","tes103"]
77+
}
78+
`

website/docs/d/dnspod_record_list.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ The following arguments are supported:
6161
* `sort_field` - (Optional, String) Sorting field, supporting NAME, LINE, TYPE, VALUE, WEIGHT, MX, TTL, UPDATED_ON fields. NAME: The host header of the resolution record LINE: The resolution record line TYPE: The resolution record type VALUE: The resolution record value WEIGHT: The weight MX: MX priority TTL: The resolution record cache time UPDATED_ON: The resolution record update time.
6262
* `sort_type` - (Optional, String) Sorting method, ascending: ASC, descending: DESC. The default value is ASC.
6363
* `sub_domain` - (Optional, String) Retrieve resolution records based on the host header of the resolution record. Fuzzy matching is used by default. You can set the IsExactSubdomain parameter to true for precise searching.
64+
* `sub_domains` - (Optional, Set: [`String`]) Sub domains.
6465
* `ttl_begin` - (Optional, Int) The starting point of the resolution record TTL query interval.
6566
* `ttl_end` - (Optional, Int) The endpoint of the resolution record TTL query interval.
6667
* `updated_at_begin` - (Optional, String) The starting point of the resolution record update time query interval.

0 commit comments

Comments
 (0)