diff --git a/.changelog/3165.txt b/.changelog/3165.txt new file mode 100644 index 0000000000..230997bf9f --- /dev/null +++ b/.changelog/3165.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +data-source/tencentcloud_dnspod_record_list: add `sub_domains` param +``` diff --git a/tencentcloud/services/dnspod/data_source_tc_dnspod_record_list.go b/tencentcloud/services/dnspod/data_source_tc_dnspod_record_list.go index d54deb78cc..521120fd18 100644 --- a/tencentcloud/services/dnspod/data_source_tc_dnspod_record_list.go +++ b/tencentcloud/services/dnspod/data_source_tc_dnspod_record_list.go @@ -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": { @@ -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 { @@ -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)) diff --git a/tencentcloud/services/dnspod/data_source_tc_dnspod_record_list_test.go b/tencentcloud/services/dnspod/data_source_tc_dnspod_record_list_test.go index 8bee0331c7..8b39759f49 100644 --- a/tencentcloud/services/dnspod/data_source_tc_dnspod_record_list_test.go +++ b/tencentcloud/services/dnspod/data_source_tc_dnspod_record_list_test.go @@ -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{ { @@ -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" { @@ -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"] +} +` diff --git a/website/docs/d/dnspod_record_list.html.markdown b/website/docs/d/dnspod_record_list.html.markdown index 45340b4ae2..82e53f6bc9 100644 --- a/website/docs/d/dnspod_record_list.html.markdown +++ b/website/docs/d/dnspod_record_list.html.markdown @@ -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.