Skip to content

Commit a8f53c9

Browse files
authored
feat(dnspod): domain lock and unlock (#2312)
* feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock * feat(dnspod): domain lock and unlock
1 parent 94652a2 commit a8f53c9

File tree

6 files changed

+218
-0
lines changed

6 files changed

+218
-0
lines changed

.changelog/2312.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_domain_lock
3+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,7 @@ DNSPOD
12501250
tencentcloud_dnspod_download_snapshot_operation
12511251
tencentcloud_dnspod_custom_line
12521252
tencentcloud_dnspod_snapshot_config
1253+
tencentcloud_dnspod_domain_lock
12531254
12541255
Data Source
12551256
tencentcloud_dnspod_records
@@ -3398,6 +3399,7 @@ func Provider() *schema.Provider {
33983399
"tencentcloud_dnspod_download_snapshot_operation": resourceTencentCloudDnspodDownloadSnapshotOperation(),
33993400
"tencentcloud_dnspod_custom_line": resourceTencentCloudDnspodCustomLine(),
34003401
"tencentcloud_dnspod_snapshot_config": resourceTencentCloudDnspodSnapshotConfig(),
3402+
"tencentcloud_dnspod_domain_lock": resourceTencentCloudDnspodDomainLock(),
34013403
"tencentcloud_private_dns_zone": resourceTencentCloudPrivateDnsZone(),
34023404
"tencentcloud_private_dns_record": resourceTencentCloudPrivateDnsRecord(),
34033405
"tencentcloud_private_dns_zone_vpc_attachment": resourceTencentCloudPrivateDnsZoneVpcAttachment(),
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
Provides a resource to create a dnspod domain_lock
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_dnspod_domain_lock" "domain_lock" {
8+
domain = "dnspod.cn"
9+
lock_days = 30
10+
}
11+
```
12+
13+
*/
14+
package tencentcloud
15+
16+
import (
17+
"fmt"
18+
"log"
19+
"strings"
20+
21+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
23+
dnspod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod/v20210323"
24+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
25+
)
26+
27+
func resourceTencentCloudDnspodDomainLock() *schema.Resource {
28+
return &schema.Resource{
29+
Create: resourceTencentCloudDnspodDomainLockCreate,
30+
Read: resourceTencentCloudDnspodDomainLockRead,
31+
Delete: resourceTencentCloudDnspodDomainLockDelete,
32+
Schema: map[string]*schema.Schema{
33+
"domain": {
34+
Required: true,
35+
ForceNew: true,
36+
Type: schema.TypeString,
37+
Description: "Domain name.",
38+
},
39+
40+
"lock_days": {
41+
Required: true,
42+
ForceNew: true,
43+
Type: schema.TypeInt,
44+
Description: "The number of max days to lock the domain+ Old packages: D_FREE 30 days, D_PLUS 90 days, D_EXTRA 30 days, D_EXPERT 60 days, D_ULTRA 365 days+ New packages: DP_FREE 365 days, DP_PLUS 365 days, DP_EXTRA 365 days, DP_EXPERT 365 days, DP_ULTRA 365 days.",
45+
},
46+
47+
"lock_code": {
48+
Computed: true,
49+
Type: schema.TypeString,
50+
Description: "Domain unlock code, can be obtained through the ModifyDomainLock interface.",
51+
},
52+
},
53+
}
54+
}
55+
56+
func resourceTencentCloudDnspodDomainLockCreate(d *schema.ResourceData, meta interface{}) error {
57+
defer logElapsed("resource.tencentcloud_dnspod_domain_lock.create")()
58+
defer inconsistentCheck(d, meta)()
59+
60+
logId := getLogId(contextNil)
61+
62+
var (
63+
request = dnspod.NewModifyDomainLockRequest()
64+
response = dnspod.NewModifyDomainLockResponse()
65+
domain string
66+
lockCode string
67+
)
68+
if v, ok := d.GetOk("domain"); ok {
69+
domain = v.(string)
70+
request.Domain = helper.String(v.(string))
71+
}
72+
73+
if v, ok := d.GetOkExists("lock_days"); ok {
74+
request.LockDays = helper.IntUint64(v.(int))
75+
}
76+
77+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
78+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseDnsPodClient().ModifyDomainLock(request)
79+
if e != nil {
80+
return retryError(e)
81+
} else {
82+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
83+
}
84+
response = result
85+
return nil
86+
})
87+
if err != nil {
88+
log.Printf("[CRITAL]%s operate dnspod domain_lock failed, reason:%+v", logId, err)
89+
return err
90+
}
91+
92+
if response.Response.LockInfo != nil && response.Response.LockInfo.LockCode != nil {
93+
lockCode = *response.Response.LockInfo.LockCode
94+
}
95+
96+
d.SetId(strings.Join([]string{domain, lockCode}, FILED_SP))
97+
_ = d.Set("lock_code", lockCode)
98+
99+
return resourceTencentCloudDnspodDomainLockRead(d, meta)
100+
}
101+
102+
func resourceTencentCloudDnspodDomainLockRead(d *schema.ResourceData, meta interface{}) error {
103+
defer logElapsed("resource.tencentcloud_dnspod_domain_lock.read")()
104+
defer inconsistentCheck(d, meta)()
105+
106+
return nil
107+
}
108+
109+
func resourceTencentCloudDnspodDomainLockDelete(d *schema.ResourceData, meta interface{}) error {
110+
defer logElapsed("resource.tencentcloud_dnspod_domain_lock.delete")()
111+
defer inconsistentCheck(d, meta)()
112+
113+
logId := getLogId(contextNil)
114+
115+
var (
116+
request = dnspod.NewModifyDomainUnlockRequest()
117+
)
118+
119+
idSplit := strings.Split(d.Id(), FILED_SP)
120+
if len(idSplit) != 2 {
121+
return fmt.Errorf("tencentcloud_dnspod_domain_lock id is broken, id is %s", d.Id())
122+
}
123+
request.Domain = helper.String(idSplit[0])
124+
request.LockCode = helper.String(idSplit[1])
125+
126+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
127+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseDnsPodClient().ModifyDomainUnlock(request)
128+
if e != nil {
129+
return retryError(e)
130+
} else {
131+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
132+
}
133+
return nil
134+
})
135+
if err != nil {
136+
log.Printf("[CRITAL]%s operate dnspod domain_unlock failed, reason:%+v", logId, err)
137+
return err
138+
}
139+
140+
return nil
141+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDnspodDomainLockResource_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: testAccDnspodDomainLock,
17+
Check: resource.ComposeTestCheckFunc(
18+
resource.TestCheckResourceAttrSet("tencentcloud_dnspod_domain_lock.domain_lock", "id"),
19+
),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccDnspodDomainLock = `
26+
27+
resource "tencentcloud_dnspod_domain_lock" "domain_lock" {
28+
domain = "iac-tf.cloud"
29+
lock_days = 30
30+
}
31+
32+
`
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
subcategory: "DNSPOD"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_dnspod_domain_lock"
5+
sidebar_current: "docs-tencentcloud-resource-dnspod_domain_lock"
6+
description: |-
7+
Provides a resource to create a dnspod domain_lock
8+
---
9+
10+
# tencentcloud_dnspod_domain_lock
11+
12+
Provides a resource to create a dnspod domain_lock
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_dnspod_domain_lock" "domain_lock" {
18+
domain = "dnspod.cn"
19+
lock_days = 30
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `domain` - (Required, String, ForceNew) Domain name.
28+
* `lock_days` - (Required, Int, ForceNew) The number of max days to lock the domain+ Old packages: D_FREE 30 days, D_PLUS 90 days, D_EXTRA 30 days, D_EXPERT 60 days, D_ULTRA 365 days+ New packages: DP_FREE 365 days, DP_PLUS 365 days, DP_EXTRA 365 days, DP_EXPERT 365 days, DP_ULTRA 365 days.
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+
* `lock_code` - Domain unlock code, can be obtained through the ModifyDomainLock interface.
36+
37+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,9 @@
18961896
<li>
18971897
<a href="/docs/providers/tencentcloud/r/dnspod_domain_instance.html">tencentcloud_dnspod_domain_instance</a>
18981898
</li>
1899+
<li>
1900+
<a href="/docs/providers/tencentcloud/r/dnspod_domain_lock.html">tencentcloud_dnspod_domain_lock</a>
1901+
</li>
18991902
<li>
19001903
<a href="/docs/providers/tencentcloud/r/dnspod_download_snapshot_operation.html">tencentcloud_dnspod_download_snapshot_operation</a>
19011904
</li>

0 commit comments

Comments
 (0)