Skip to content

Commit fc63cbf

Browse files
authored
feat(dnspod): dnspod snapshot config (#2306)
* feat(dnspod): dnspod snapshot config * docs: add changelog * docs: add changelog * docs: add changelog * docs: add changelog
1 parent 890892c commit fc63cbf

File tree

7 files changed

+279
-0
lines changed

7 files changed

+279
-0
lines changed

.changelog/2306.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
tencentcloud_dnspod_snapshot_config
3+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ DNSPOD
12481248
tencentcloud_dnspod_modify_domain_owner_operation
12491249
tencentcloud_dnspod_download_snapshot_operation
12501250
tencentcloud_dnspod_custom_line
1251+
tencentcloud_dnspod_snapshot_config
12511252
12521253
Data Source
12531254
tencentcloud_dnspod_records
@@ -3391,6 +3392,7 @@ func Provider() *schema.Provider {
33913392
"tencentcloud_dnspod_modify_record_group_operation": resourceTencentCloudDnspodModifyRecordGroupOperation(),
33923393
"tencentcloud_dnspod_download_snapshot_operation": resourceTencentCloudDnspodDownloadSnapshotOperation(),
33933394
"tencentcloud_dnspod_custom_line": resourceTencentCloudDnspodCustomLine(),
3395+
"tencentcloud_dnspod_snapshot_config": resourceTencentCloudDnspodSnapshotConfig(),
33943396
"tencentcloud_private_dns_zone": resourceTencentCloudPrivateDnsZone(),
33953397
"tencentcloud_private_dns_record": resourceTencentCloudPrivateDnsRecord(),
33963398
"tencentcloud_private_dns_zone_vpc_attachment": resourceTencentCloudPrivateDnsZoneVpcAttachment(),
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
Provides a resource to create a dnspod snapshot_config
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_dnspod_snapshot_config" "snapshot_config" {
8+
domain = "dnspod.cn"
9+
period = "hourly"
10+
}
11+
```
12+
13+
Import
14+
15+
dnspod snapshot_config can be imported using the id, e.g.
16+
17+
```
18+
terraform import tencentcloud_dnspod_snapshot_config.snapshot_config domain
19+
```
20+
*/
21+
package tencentcloud
22+
23+
import (
24+
"context"
25+
"log"
26+
27+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
28+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
29+
dnspod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod/v20210323"
30+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
31+
)
32+
33+
func resourceTencentCloudDnspodSnapshotConfig() *schema.Resource {
34+
return &schema.Resource{
35+
Create: resourceTencentCloudDnspodSnapshotConfigCreate,
36+
Read: resourceTencentCloudDnspodSnapshotConfigRead,
37+
Update: resourceTencentCloudDnspodSnapshotConfigUpdate,
38+
Delete: resourceTencentCloudDnspodSnapshotConfigDelete,
39+
Importer: &schema.ResourceImporter{
40+
State: schema.ImportStatePassthrough,
41+
},
42+
Schema: map[string]*schema.Schema{
43+
"domain": {
44+
Required: true,
45+
ForceNew: true,
46+
Type: schema.TypeString,
47+
Description: "Domain name.",
48+
},
49+
50+
"period": {
51+
Required: true,
52+
Type: schema.TypeString,
53+
Description: "Backup interval: empty string - no backup, half_hour - every half hour, hourly - every hour, daily - every day, monthly - every month.",
54+
},
55+
},
56+
}
57+
}
58+
59+
func resourceTencentCloudDnspodSnapshotConfigCreate(d *schema.ResourceData, meta interface{}) error {
60+
defer logElapsed("resource.tencentcloud_dnspod_snapshot_config.create")()
61+
defer inconsistentCheck(d, meta)()
62+
63+
var domain string
64+
65+
if v, ok := d.GetOk("domain"); ok {
66+
domain = v.(string)
67+
}
68+
69+
d.SetId(domain)
70+
71+
return resourceTencentCloudDnspodSnapshotConfigUpdate(d, meta)
72+
}
73+
74+
func resourceTencentCloudDnspodSnapshotConfigRead(d *schema.ResourceData, meta interface{}) error {
75+
defer logElapsed("resource.tencentcloud_dnspod_snapshot_config.read")()
76+
defer inconsistentCheck(d, meta)()
77+
78+
logId := getLogId(contextNil)
79+
80+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
81+
82+
service := DnspodService{client: meta.(*TencentCloudClient).apiV3Conn}
83+
84+
domain := d.Id()
85+
86+
snapshotConfig, err := service.DescribeDnspodSnapshotConfigById(ctx, domain)
87+
if err != nil {
88+
return err
89+
}
90+
91+
if snapshotConfig == nil {
92+
d.SetId("")
93+
log.Printf("[WARN]%s resource `DnspodSnapshot_config` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
94+
return nil
95+
}
96+
97+
_ = d.Set("domain", domain)
98+
99+
if snapshotConfig.Config != nil {
100+
_ = d.Set("period", snapshotConfig.Config)
101+
}
102+
103+
return nil
104+
}
105+
106+
func resourceTencentCloudDnspodSnapshotConfigUpdate(d *schema.ResourceData, meta interface{}) error {
107+
defer logElapsed("resource.tencentcloud_dnspod_snapshot_config.update")()
108+
defer inconsistentCheck(d, meta)()
109+
110+
logId := getLogId(contextNil)
111+
112+
request := dnspod.NewModifySnapshotConfigRequest()
113+
114+
domain := d.Id()
115+
request.Domain = &domain
116+
117+
if v, ok := d.GetOk("period"); ok {
118+
request.Period = helper.String(v.(string))
119+
}
120+
121+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
122+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseDnsPodClient().ModifySnapshotConfig(request)
123+
if e != nil {
124+
return retryError(e)
125+
} else {
126+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
127+
}
128+
return nil
129+
})
130+
if err != nil {
131+
log.Printf("[CRITAL]%s update dnspod snapshot_config failed, reason:%+v", logId, err)
132+
return err
133+
}
134+
135+
return resourceTencentCloudDnspodSnapshotConfigRead(d, meta)
136+
}
137+
138+
func resourceTencentCloudDnspodSnapshotConfigDelete(d *schema.ResourceData, meta interface{}) error {
139+
defer logElapsed("resource.tencentcloud_dnspod_snapshot_config.delete")()
140+
defer inconsistentCheck(d, meta)()
141+
142+
return nil
143+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDnspodSnapshotConfigResource_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: testAccDnspodSnapshotConfig,
17+
Check: resource.ComposeTestCheckFunc(
18+
resource.TestCheckResourceAttr("tencentcloud_dnspod_snapshot_config.snapshot_config", "domain", "iac-tf.cloud"),
19+
resource.TestCheckResourceAttr("tencentcloud_dnspod_snapshot_config.snapshot_config", "period", "hourly"),
20+
),
21+
},
22+
{
23+
ResourceName: "tencentcloud_dnspod_snapshot_config.snapshot_config",
24+
ImportState: true,
25+
ImportStateVerify: true,
26+
},
27+
{
28+
Config: testAccDnspodSnapshotConfigUp,
29+
Check: resource.ComposeTestCheckFunc(
30+
resource.TestCheckResourceAttr("tencentcloud_dnspod_snapshot_config.snapshot_config", "domain", "iac-tf.cloud"),
31+
resource.TestCheckResourceAttr("tencentcloud_dnspod_snapshot_config.snapshot_config", "period", "daily"),
32+
),
33+
},
34+
},
35+
})
36+
}
37+
38+
const testAccDnspodSnapshotConfig = `
39+
40+
resource "tencentcloud_dnspod_snapshot_config" "snapshot_config" {
41+
domain = "iac-tf.cloud"
42+
period = "hourly"
43+
}
44+
45+
`
46+
47+
const testAccDnspodSnapshotConfigUp = `
48+
49+
resource "tencentcloud_dnspod_snapshot_config" "snapshot_config" {
50+
domain = "iac-tf.cloud"
51+
period = "daily"
52+
}
53+
54+
`

tencentcloud/service_tencentcloud_dnspod.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,3 +759,32 @@ func (me *DnspodService) DeleteDnspodCustomLineById(ctx context.Context, domain
759759

760760
return
761761
}
762+
763+
func (me *DnspodService) DescribeDnspodSnapshotConfigById(ctx context.Context, domain string) (snapshotConfig *dnspod.SnapshotConfig, errRet error) {
764+
logId := getLogId(ctx)
765+
766+
request := dnspod.NewDescribeSnapshotConfigRequest()
767+
request.Domain = &domain
768+
769+
defer func() {
770+
if errRet != nil {
771+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
772+
}
773+
}()
774+
775+
ratelimit.Check(request.GetAction())
776+
777+
response, err := me.client.UseDnsPodClient().DescribeSnapshotConfig(request)
778+
if err != nil {
779+
errRet = err
780+
return
781+
}
782+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
783+
784+
if response.Response == nil || response.Response.SnapshotConfig == nil {
785+
return
786+
}
787+
788+
snapshotConfig = response.Response.SnapshotConfig
789+
return
790+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
subcategory: "DNSPOD"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_dnspod_snapshot_config"
5+
sidebar_current: "docs-tencentcloud-resource-dnspod_snapshot_config"
6+
description: |-
7+
Provides a resource to create a dnspod snapshot_config
8+
---
9+
10+
# tencentcloud_dnspod_snapshot_config
11+
12+
Provides a resource to create a dnspod snapshot_config
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_dnspod_snapshot_config" "snapshot_config" {
18+
domain = "dnspod.cn"
19+
period = "hourly"
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `domain` - (Required, String, ForceNew) Domain name.
28+
* `period` - (Required, String) Backup interval: empty string - no backup, half_hour - every half hour, hourly - every hour, daily - every day, monthly - every month.
29+
30+
## Attributes Reference
31+
32+
In addition to all arguments above, the following attributes are exported:
33+
34+
* `id` - ID of the resource.
35+
36+
37+
38+
## Import
39+
40+
dnspod snapshot_config can be imported using the id, e.g.
41+
42+
```
43+
terraform import tencentcloud_dnspod_snapshot_config.snapshot_config domain
44+
```
45+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,9 @@
19111911
<li>
19121912
<a href="/docs/providers/tencentcloud/r/dnspod_record_group.html">tencentcloud_dnspod_record_group</a>
19131913
</li>
1914+
<li>
1915+
<a href="/docs/providers/tencentcloud/r/dnspod_snapshot_config.html">tencentcloud_dnspod_snapshot_config</a>
1916+
</li>
19141917
</ul>
19151918
</li>
19161919
</ul>

0 commit comments

Comments
 (0)