Skip to content

fix(dnspod): [121993505]support sub_domains #3165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3165.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
data-source/tencentcloud_dnspod_record_list: add `sub_domains` param
```
45 changes: 32 additions & 13 deletions tencentcloud/services/dnspod/data_source_tc_dnspod_record_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ func DataSourceTencentCloudDnspodRecordList() *schema.Resource {
},

"sub_domain": {
Optional: true,
Type: schema.TypeString,
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.",
Optional: true,
Type: schema.TypeString,
ConflictsWith: []string{"sub_domains"},
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.",
},
"sub_domains": {
Optional: true,
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
ConflictsWith: []string{"sub_domain"},
Description: "Sub domains.",
},

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

subDomains := make([]string, 0)
if v, ok := d.GetOk("sub_domain"); ok {
paramMap["SubDomain"] = helper.String(v.(string))
subDomains = append(subDomains, v.(string))
}

if v, ok := d.GetOk("sub_domains"); ok {
subDomainList := v.(*schema.Set).List()
for _, subDomain := range subDomainList {
subDomains = append(subDomains, subDomain.(string))
}
}

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

var recordList []*dnspod.RecordListItem

err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeDnspodRecordListByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
for _, subDomain := range subDomains {
paramMap["SubDomain"] = helper.String(subDomain)
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeDnspodRecordListByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}
recordList = append(recordList, result...)
return nil
})
if err != nil {
return err
}
recordList = result
return nil
})
if err != nil {
return err
}

ids := make([]string, 0, len(recordList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestAccTencentCloudDnspodRecordListDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_PREPAY) },
PreCheck: func() { tcacctest.AccPreCheck(t) },
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Expand All @@ -22,6 +22,24 @@ func TestAccTencentCloudDnspodRecordListDataSource_basic(t *testing.T) {
})
}

func TestAccTencentCloudDnspodRecordListDataSource_subDomains(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { tcacctest.AccPreCheck(t) },
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccDnspodRecordListDataSource_subDomains,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_dnspod_record_list.subdomains"),
resource.TestCheckResourceAttr("data.tencentcloud_dnspod_record_list.subdomains", "record_list.#", "2"),
resource.TestCheckResourceAttr("data.tencentcloud_dnspod_record_list.subdomains", "instance_list.#", "2"),
),
},
},
})
}

const testAccDnspodRecordListDataSource = `

data "tencentcloud_dnspod_record_list" "record_list" {
Expand Down Expand Up @@ -50,3 +68,11 @@ data "tencentcloud_dnspod_record_list" "record_list" {
}

`

const testAccDnspodRecordListDataSource_subDomains = `
data "tencentcloud_dnspod_record_list" "subdomains" {
domain = "mikatong.xyz"
is_exact_sub_domain = true
sub_domains = ["tes1029","tes103"]
}
`
1 change: 1 addition & 0 deletions website/docs/d/dnspod_record_list.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The following arguments are supported:
* `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.
* `sort_type` - (Optional, String) Sorting method, ascending: ASC, descending: DESC. The default value is ASC.
* `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.
* `sub_domains` - (Optional, Set: [`String`]) Sub domains.
* `ttl_begin` - (Optional, Int) The starting point of the resolution record TTL query interval.
* `ttl_end` - (Optional, Int) The endpoint of the resolution record TTL query interval.
* `updated_at_begin` - (Optional, String) The starting point of the resolution record update time query interval.
Expand Down
Loading