Skip to content

Commit b4789b6

Browse files
authored
feat(dnspod): datasource of dnspod (#2235)
* feat(dnspod): datasource of dnspod * feat(dnspod): datasource of dnspod * docs(dnspod): datasource docs * feat(dnspod): e2e use pre uin * feat(dnspod): e2e use pre uin * feat(dnspod): e2e update * refact(dnspod): remove file * refact(dnspod): remove file * docs(dnspod): add changelog
1 parent 7f7d769 commit b4789b6

20 files changed

+2121
-3
lines changed

.changelog/2235.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```release-note:new-data-source
2+
tencentcloud_dnspod_domain_log_list
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_dnspod_record_analytics
7+
```
8+
9+
```release-note:new-data-source
10+
tencentcloud_dnspod_record_line_list
11+
```
12+
13+
```release-note:new-data-source
14+
tencentcloud_dnspod_record_list
15+
```
16+
17+
```release-note:new-data-source
18+
tencentcloud_dnspod_record_type
19+
```

tencentcloud/data_source_tc_dnspod_domain_analytics_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
func TestAccTencentCloudDnspodDomainAnalyticsDataSource_basic(t *testing.T) {
1010
t.Parallel()
1111
resource.Test(t, resource.TestCase{
12-
PreCheck: func() {
13-
testAccPreCheck(t)
14-
},
12+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
13+
// PreCheck: func() {
14+
// testAccPreCheck(t)
15+
// },
1516
Providers: testAccProviders,
1617
Steps: []resource.TestStep{
1718
{
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
Use this data source to query detailed information of dnspod domain_log_list
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_dnspod_domain_log_list" "domain_log_list" {
8+
domain = "iac-tf.cloud"
9+
domain_id = 123
10+
}
11+
```
12+
*/
13+
package tencentcloud
14+
15+
import (
16+
"context"
17+
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
20+
21+
// dnspod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod/v20210323"
22+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
23+
)
24+
25+
func dataSourceTencentCloudDnspodDomainLogList() *schema.Resource {
26+
return &schema.Resource{
27+
Read: dataSourceTencentCloudDnspodDomainLogListRead,
28+
Schema: map[string]*schema.Schema{
29+
"domain": {
30+
Required: true,
31+
Type: schema.TypeString,
32+
Description: "Domain.",
33+
},
34+
35+
"domain_id": {
36+
Optional: true,
37+
Type: schema.TypeInt,
38+
Description: "Domain ID. The parameter DomainId has a higher priority than the parameter Domain. If the parameter DomainId is passed, the parameter Domain will be ignored. You can find all Domains and DomainIds through the DescribeDomainList interface.",
39+
},
40+
41+
"log_list": {
42+
Computed: true,
43+
Type: schema.TypeSet,
44+
Elem: &schema.Schema{
45+
Type: schema.TypeString,
46+
},
47+
Description: "Domain Operation Log List. Note: This field may return null, indicating that no valid value can be obtained.",
48+
},
49+
50+
"result_output_file": {
51+
Type: schema.TypeString,
52+
Optional: true,
53+
Description: "Used to save results.",
54+
},
55+
},
56+
}
57+
}
58+
59+
func dataSourceTencentCloudDnspodDomainLogListRead(d *schema.ResourceData, meta interface{}) error {
60+
defer logElapsed("data_source.tencentcloud_dnspod_domain_log_list.read")()
61+
defer inconsistentCheck(d, meta)()
62+
63+
logId := getLogId(contextNil)
64+
65+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
66+
var domain string
67+
68+
paramMap := make(map[string]interface{})
69+
if v, ok := d.GetOk("domain"); ok {
70+
domain = v.(string)
71+
paramMap["Domain"] = helper.String(v.(string))
72+
}
73+
74+
if v, ok := d.GetOkExists("domain_id"); ok {
75+
paramMap["DomainId"] = helper.IntUint64(v.(int))
76+
}
77+
78+
service := DnspodService{client: meta.(*TencentCloudClient).apiV3Conn}
79+
80+
var logList []*string
81+
82+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
83+
result, e := service.DescribeDnspodDomainLogListByFilter(ctx, paramMap)
84+
if e != nil {
85+
return retryError(e)
86+
}
87+
logList = result
88+
return nil
89+
})
90+
if err != nil {
91+
return err
92+
}
93+
94+
// ids := make([]string, 0, len(logList))
95+
if logList != nil {
96+
_ = d.Set("log_list", logList)
97+
}
98+
99+
d.SetId(helper.DataResourceIdHash(domain))
100+
output, ok := d.GetOk("result_output_file")
101+
if ok && output.(string) != "" {
102+
if e := writeToFile(output.(string), logList); e != nil {
103+
return e
104+
}
105+
}
106+
return nil
107+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDnspodDomainLogListDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
13+
Providers: testAccProviders,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccDnspodDomainLogListDataSource,
17+
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_dnspod_domain_log_list.domain_log_list")),
18+
},
19+
},
20+
})
21+
}
22+
23+
const testAccDnspodDomainLogListDataSource = `
24+
25+
data "tencentcloud_dnspod_domain_log_list" "domain_log_list" {
26+
domain = "iac-tf.cloud"
27+
# domain_id = 123
28+
}
29+
30+
`

0 commit comments

Comments
 (0)