Skip to content

Commit ef4fc79

Browse files
author
mikatong
committed
support filter_at_ns
1 parent 8451aa1 commit ef4fc79

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

tencentcloud/services/dnspod/data_source_tc_dnspod_record_list.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ func DataSourceTencentCloudDnspodRecordList() *schema.Resource {
169169
Description: "Project ID.",
170170
},
171171

172+
"filter_at_ns": {
173+
Optional: true,
174+
Type: schema.TypeBool,
175+
Description: "Filter @ type NS records. Default is false.",
176+
Default: false,
177+
},
178+
172179
"record_count_info": {
173180
Computed: true,
174181
Type: schema.TypeList,
@@ -484,7 +491,10 @@ func dataSourceTencentCloudDnspodRecordListRead(d *schema.ResourceData, meta int
484491
if v, ok := d.GetOkExists("project_id"); ok {
485492
paramMap["ProjectId"] = helper.IntInt64(v.(int))
486493
}
487-
494+
var filterAtNS bool
495+
if v, ok := d.GetOkExists("filter_at_ns"); ok {
496+
filterAtNS = v.(bool)
497+
}
488498
service := DnspodService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
489499

490500
var recordList []*dnspod.RecordListItem
@@ -536,6 +546,9 @@ func dataSourceTencentCloudDnspodRecordListRead(d *schema.ResourceData, meta int
536546
instanceList := make([]map[string]interface{}, 0, len(recordList))
537547
if recordList != nil {
538548
for _, recordListItem := range recordList {
549+
if filterAtNS && recordListItem.Name != nil && *recordListItem.Name == DNSPOD_RECORD_NAME_AT && recordListItem.Type != nil && *recordListItem.Type == DNSPOD_RECORD_TYPE_NS {
550+
continue
551+
}
539552
recordListItemMap := map[string]interface{}{}
540553
instanceListItemMap := map[string]interface{}{}
541554
instanceListItemMap["domain"] = domain

tencentcloud/services/dnspod/data_source_tc_dnspod_record_list_test.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,36 @@ func TestAccTencentCloudDnspodRecordListDataSource_withoutSubDomain(t *testing.T
5858
})
5959
}
6060

61+
func TestAccTencentCloudDnspodRecordListDataSource_filterAtNS(t *testing.T) {
62+
t.Parallel()
63+
resource.Test(t, resource.TestCase{
64+
PreCheck: func() { tcacctest.AccPreCheck(t) },
65+
Providers: tcacctest.AccProviders,
66+
Steps: []resource.TestStep{
67+
{
68+
Config: testAccDnspodRecordListDataSource_filterAtNSTrue,
69+
Check: resource.ComposeTestCheckFunc(
70+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_dnspod_record_list.subdomains"),
71+
resource.TestCheckResourceAttr("data.tencentcloud_dnspod_record_list.subdomains", "record_list.#", "0"),
72+
resource.TestCheckResourceAttr("data.tencentcloud_dnspod_record_list.subdomains", "instance_list.#", "0"),
73+
),
74+
},
75+
{
76+
Config: testAccDnspodRecordListDataSource_filterAtNSFalse,
77+
Check: resource.ComposeTestCheckFunc(
78+
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_dnspod_record_list.subdomains"),
79+
resource.TestCheckResourceAttr("data.tencentcloud_dnspod_record_list.subdomains", "record_list.#", "2"),
80+
resource.TestCheckResourceAttr("data.tencentcloud_dnspod_record_list.subdomains", "instance_list.#", "2"),
81+
),
82+
},
83+
},
84+
})
85+
}
86+
6187
const testAccDnspodRecordListDataSource = `
6288
6389
data "tencentcloud_dnspod_record_list" "record_list" {
64-
domain = "iac-tf.cloud"
90+
domain = "tencentcloud-terraform-provider.cn"
6591
# domain_id = 123
6692
# sub_domain = "www"
6793
record_type = ["A", "NS", "CNAME", "NS", "AAAA"]
@@ -101,3 +127,20 @@ data "tencentcloud_dnspod_record_list" "subdomains" {
101127
is_exact_sub_domain = true
102128
}
103129
`
130+
131+
const testAccDnspodRecordListDataSource_filterAtNSTrue = `
132+
data "tencentcloud_dnspod_record_list" "subdomains" {
133+
domain = "tencentcloud-terraform-provider.cn"
134+
sub_domains = ["@"]
135+
record_type = ["NS"]
136+
filter_at_ns = true
137+
}
138+
`
139+
const testAccDnspodRecordListDataSource_filterAtNSFalse = `
140+
data "tencentcloud_dnspod_record_list" "subdomains" {
141+
domain = "tencentcloud-terraform-provider.cn"
142+
sub_domains = ["@"]
143+
record_type = ["NS"]
144+
filter_at_ns = false
145+
}
146+
`

tencentcloud/services/dnspod/extension_dnspod.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ var DNSPOD_DOMAIN_STATUS_TYPE = []string{
1919
DNSPOD_DOMAIN_STATUS_ENABLE,
2020
DNSPOD_DOMAIN_STATUS_DISABLE,
2121
}
22+
23+
const (
24+
DNSPOD_RECORD_NAME_AT = "@"
25+
DNSPOD_RECORD_TYPE_NS = "NS"
26+
)

website/docs/d/dnspod_record_list.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The following arguments are supported:
4646

4747
* `domain` - (Required, String) The domain to which the resolution record belongs.
4848
* `domain_id` - (Optional, Int) The domain ID to which the resolution record belongs. If DomainId is provided, the system will ignore the Domain parameter. You can find all Domain and DomainId through the DescribeDomainList interface.
49+
* `filter_at_ns` - (Optional, Bool) Filter @ type NS records. Default is false.
4950
* `group_id` - (Optional, Set: [`Int`]) When retrieving resolution records under certain groups, pass this group ID. You can obtain the GroupId field through the DescribeRecordGroupList interface.
5051
* `is_exact_sub_domain` - (Optional, Bool) Whether to perform an exact search based on the SubDomain parameter.
5152
* `keyword` - (Optional, String) Search for resolution records by keyword, currently supporting searching host headers and record values.

0 commit comments

Comments
 (0)