Skip to content

Commit 21d93ef

Browse files
gitmknanonymous
andauthored
feat: support crs (#1680)
* feat: support crs * feat: add crs changelog * fix: modify test * fix: modify test * fix: update redis * fix: update redis * fix: update redis * fix: update redis --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent 9099516 commit 21d93ef

27 files changed

+1749
-2
lines changed

.changelog/1680.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
```release-note:new-resource
2+
tencentcloud_redis_backup_download_restriction
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_redis_clear_instance_operation
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_redis_renew_instance_operation
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_redis_startup_instance_operation
15+
```
16+
17+
```release-note:new-resource
18+
tencentcloud_redis_upgrade_cache_version_operation
19+
```
20+
21+
```release-note:new-resource
22+
tencentcloud_redis_upgrade_multi_zone_operation
23+
```
24+
25+
```release-note:new-resource
26+
tencentcloud_redis_upgrade_proxy_version_operation
27+
```
28+
29+
```release-note:enhancement
30+
resource/tencentcloud_redis_instance: Support `typeid` immediate switching
31+
```

tencentcloud/provider.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,13 @@ TencentDB for Redis(crs)
562562
tencentcloud_redis_account
563563
tencentcloud_redis_read_only
564564
tencentcloud_redis_ssl
565+
tencentcloud_redis_backup_download_restriction
566+
tencentcloud_redis_clear_instance_operation
567+
tencentcloud_redis_renew_instance_operation
568+
tencentcloud_redis_startup_instance_operation
569+
tencentcloud_redis_upgrade_cache_version_operation
570+
tencentcloud_redis_upgrade_multi_zone_operation
571+
tencentcloud_redis_upgrade_proxy_version_operation
565572
tencentcloud_redis_maintenance_window
566573
tencentcloud_redis_replica_readonly
567574
@@ -1701,6 +1708,13 @@ func Provider() *schema.Provider {
17011708
"tencentcloud_redis_param": resourceTencentCloudRedisParam(),
17021709
"tencentcloud_redis_read_only": resourceTencentCloudRedisReadOnly(),
17031710
"tencentcloud_redis_ssl": resourceTencentCloudRedisSsl(),
1711+
"tencentcloud_redis_backup_download_restriction": resourceTencentCloudRedisBackupDownloadRestriction(),
1712+
"tencentcloud_redis_clear_instance_operation": resourceTencentCloudRedisClearInstanceOperation(),
1713+
"tencentcloud_redis_renew_instance_operation": resourceTencentCloudRedisRenewInstanceOperation(),
1714+
"tencentcloud_redis_startup_instance_operation": resourceTencentCloudRedisStartupInstanceOperation(),
1715+
"tencentcloud_redis_upgrade_cache_version_operation": resourceTencentCloudRedisUpgradeCacheVersionOperation(),
1716+
"tencentcloud_redis_upgrade_multi_zone_operation": resourceTencentCloudRedisUpgradeMultiZoneOperation(),
1717+
"tencentcloud_redis_upgrade_proxy_version_operation": resourceTencentCloudRedisUpgradeProxyVersionOperation(),
17041718
"tencentcloud_redis_maintenance_window": resourceTencentCloudRedisMaintenanceWindow(),
17051719
"tencentcloud_redis_replica_readonly": resourceTencentCloudRedisReplicaReadonly(),
17061720
"tencentcloud_as_scaling_config": resourceTencentCloudAsScalingConfig(),
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
/*
2+
Provides a resource to create a redis backup_download_restriction
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_redis_backup_download_restriction" "backup_download_restriction" {
8+
limit_type = "Customize"
9+
vpc_comparison_symbol = "In"
10+
ip_comparison_symbol = "In"
11+
limit_vpc {
12+
region = "ap-guangzhou"
13+
vpc_list = [var.vpc_id]
14+
}
15+
limit_ip = ["10.1.1.12", "10.1.1.13"]
16+
}
17+
```
18+
19+
Import
20+
21+
redis backup_download_restriction can be imported using the id, e.g.
22+
23+
```
24+
terraform import tencentcloud_redis_backup_download_restriction.backup_download_restriction backup_download_restriction_id
25+
```
26+
*/
27+
package tencentcloud
28+
29+
import (
30+
"context"
31+
"log"
32+
33+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
34+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
35+
redis "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis/v20180412"
36+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
37+
)
38+
39+
func resourceTencentCloudRedisBackupDownloadRestriction() *schema.Resource {
40+
return &schema.Resource{
41+
Create: resourceTencentCloudRedisBackupDownloadRestrictionCreate,
42+
Read: resourceTencentCloudRedisBackupDownloadRestrictionRead,
43+
Update: resourceTencentCloudRedisBackupDownloadRestrictionUpdate,
44+
Delete: resourceTencentCloudRedisBackupDownloadRestrictionDelete,
45+
Importer: &schema.ResourceImporter{
46+
State: schema.ImportStatePassthrough,
47+
},
48+
Schema: map[string]*schema.Schema{
49+
"limit_type": {
50+
Required: true,
51+
Type: schema.TypeString,
52+
Description: "Types of network restrictions for downloading backup files:- NoLimit: There is no limit, and backup files can be downloaded from both Tencent Cloud and internal and external networks.- LimitOnlyIntranet: Only intranet addresses automatically assigned by Tencent Cloud can download backup files.- Customize: refers to a user-defined private network downloadable backup file.",
53+
},
54+
55+
"vpc_comparison_symbol": {
56+
Optional: true,
57+
Type: schema.TypeString,
58+
Description: "This parameter only supports entering In, which means that the custom LimitVpc can download the backup file.",
59+
},
60+
61+
"ip_comparison_symbol": {
62+
Optional: true,
63+
Type: schema.TypeString,
64+
Description: "Identifies whether the customized LimitIP address can download the backup file.- In: Custom IP addresses are available for download.- NotIn: Custom IPs are not available for download.",
65+
},
66+
67+
"limit_vpc": {
68+
Optional: true,
69+
Type: schema.TypeList,
70+
Description: "A custom VPC ID for a downloadable backup file.If the parameter LimitType is **Customize**, you need to configure this parameter.",
71+
Elem: &schema.Resource{
72+
Schema: map[string]*schema.Schema{
73+
"region": {
74+
Type: schema.TypeString,
75+
Required: true,
76+
Description: "Customize the region of the VPC to which the backup file is downloaded.",
77+
},
78+
"vpc_list": {
79+
Type: schema.TypeSet,
80+
Elem: &schema.Schema{
81+
Type: schema.TypeString,
82+
},
83+
Required: true,
84+
Description: "Customize the list of VPCs to download backup files.",
85+
},
86+
},
87+
},
88+
},
89+
90+
"limit_ip": {
91+
Optional: true,
92+
Type: schema.TypeSet,
93+
Elem: &schema.Schema{
94+
Type: schema.TypeString,
95+
},
96+
Description: "A custom VPC IP address for downloadable backup files.If the parameter LimitType is **Customize**, you need to configure this parameter.",
97+
},
98+
},
99+
}
100+
}
101+
102+
func resourceTencentCloudRedisBackupDownloadRestrictionCreate(d *schema.ResourceData, meta interface{}) error {
103+
defer logElapsed("resource.tencentcloud_redis_backup_download_restriction.create")()
104+
defer inconsistentCheck(d, meta)()
105+
106+
region := meta.(*TencentCloudClient).apiV3Conn.Region
107+
108+
d.SetId(region)
109+
110+
return resourceTencentCloudRedisBackupDownloadRestrictionUpdate(d, meta)
111+
}
112+
113+
func resourceTencentCloudRedisBackupDownloadRestrictionRead(d *schema.ResourceData, meta interface{}) error {
114+
defer logElapsed("resource.tencentcloud_redis_backup_download_restriction.read")()
115+
defer inconsistentCheck(d, meta)()
116+
117+
logId := getLogId(contextNil)
118+
119+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
120+
121+
service := RedisService{client: meta.(*TencentCloudClient).apiV3Conn}
122+
backupDownloadRestriction, err := service.DescribeRedisBackupDownloadRestrictionById(ctx)
123+
if err != nil {
124+
return err
125+
}
126+
127+
if backupDownloadRestriction == nil {
128+
d.SetId("")
129+
log.Printf("[WARN]%s resource `RedisBackupDownloadRestriction` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
130+
return nil
131+
}
132+
133+
if backupDownloadRestriction.LimitType != nil {
134+
_ = d.Set("limit_type", backupDownloadRestriction.LimitType)
135+
}
136+
137+
if backupDownloadRestriction.VpcComparisonSymbol != nil {
138+
_ = d.Set("vpc_comparison_symbol", backupDownloadRestriction.VpcComparisonSymbol)
139+
}
140+
141+
if backupDownloadRestriction.IpComparisonSymbol != nil {
142+
_ = d.Set("ip_comparison_symbol", backupDownloadRestriction.IpComparisonSymbol)
143+
}
144+
145+
if backupDownloadRestriction.LimitVpc != nil {
146+
limitVpcList := []interface{}{}
147+
for _, limitVpc := range backupDownloadRestriction.LimitVpc {
148+
limitVpcMap := map[string]interface{}{}
149+
150+
if limitVpc.Region != nil {
151+
limitVpcMap["region"] = limitVpc.Region
152+
}
153+
154+
if limitVpc.VpcList != nil {
155+
limitVpcMap["vpc_list"] = limitVpc.VpcList
156+
}
157+
158+
limitVpcList = append(limitVpcList, limitVpcMap)
159+
}
160+
161+
_ = d.Set("limit_vpc", limitVpcList)
162+
163+
}
164+
165+
if backupDownloadRestriction.LimitIp != nil {
166+
_ = d.Set("limit_ip", backupDownloadRestriction.LimitIp)
167+
}
168+
169+
return nil
170+
}
171+
172+
func resourceTencentCloudRedisBackupDownloadRestrictionUpdate(d *schema.ResourceData, meta interface{}) error {
173+
defer logElapsed("resource.tencentcloud_redis_backup_download_restriction.update")()
174+
defer inconsistentCheck(d, meta)()
175+
176+
logId := getLogId(contextNil)
177+
178+
request := redis.NewModifyBackupDownloadRestrictionRequest()
179+
180+
if v, ok := d.GetOk("limit_type"); ok {
181+
request.LimitType = helper.String(v.(string))
182+
}
183+
184+
if v, ok := d.GetOk("vpc_comparison_symbol"); ok {
185+
request.VpcComparisonSymbol = helper.String(v.(string))
186+
}
187+
188+
if v, ok := d.GetOk("ip_comparison_symbol"); ok {
189+
request.IpComparisonSymbol = helper.String(v.(string))
190+
}
191+
192+
if v, ok := d.GetOk("limit_vpc"); ok {
193+
for _, item := range v.([]interface{}) {
194+
dMap := item.(map[string]interface{})
195+
backupLimitVpcItem := redis.BackupLimitVpcItem{}
196+
if v, ok := dMap["region"]; ok {
197+
backupLimitVpcItem.Region = helper.String(v.(string))
198+
}
199+
if v, ok := dMap["vpc_list"]; ok {
200+
vpcListSet := v.(*schema.Set).List()
201+
for i := range vpcListSet {
202+
vpcList := vpcListSet[i].(string)
203+
backupLimitVpcItem.VpcList = append(backupLimitVpcItem.VpcList, &vpcList)
204+
}
205+
}
206+
request.LimitVpc = append(request.LimitVpc, &backupLimitVpcItem)
207+
}
208+
}
209+
210+
if d.HasChange("limit_ip") {
211+
if v, ok := d.GetOk("limit_ip"); ok {
212+
limitIpSet := v.(*schema.Set).List()
213+
for i := range limitIpSet {
214+
limitIp := limitIpSet[i].(string)
215+
request.LimitIp = append(request.LimitIp, &limitIp)
216+
}
217+
}
218+
}
219+
220+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
221+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseRedisClient().ModifyBackupDownloadRestriction(request)
222+
if e != nil {
223+
return retryError(e)
224+
} else {
225+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
226+
}
227+
return nil
228+
})
229+
if err != nil {
230+
log.Printf("[CRITAL]%s update redis backupDownloadRestriction failed, reason:%+v", logId, err)
231+
return err
232+
}
233+
234+
return resourceTencentCloudRedisBackupDownloadRestrictionRead(d, meta)
235+
}
236+
237+
func resourceTencentCloudRedisBackupDownloadRestrictionDelete(d *schema.ResourceData, meta interface{}) error {
238+
defer logElapsed("resource.tencentcloud_redis_backup_download_restriction.delete")()
239+
defer inconsistentCheck(d, meta)()
240+
241+
return nil
242+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
// go test -i; go test -test.run TestAccTencentCloudRedisBackupDownloadRestrictionResource_basic -v
10+
func TestAccTencentCloudRedisBackupDownloadRestrictionResource_basic(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() {
14+
testAccPreCheck(t)
15+
},
16+
Providers: testAccProviders,
17+
Steps: []resource.TestStep{
18+
{
19+
Config: testAccRedisBackupDownloadRestriction,
20+
Check: resource.ComposeTestCheckFunc(
21+
resource.TestCheckResourceAttrSet("tencentcloud_redis_backup_download_restriction.backup_download_restriction", "id"),
22+
resource.TestCheckResourceAttr("tencentcloud_redis_backup_download_restriction.backup_download_restriction", "limit_type", "Customize"),
23+
resource.TestCheckResourceAttr("tencentcloud_redis_backup_download_restriction.backup_download_restriction", "vpc_comparison_symbol", "In"),
24+
resource.TestCheckResourceAttr("tencentcloud_redis_backup_download_restriction.backup_download_restriction", "ip_comparison_symbol", "In"),
25+
resource.TestCheckResourceAttr("tencentcloud_redis_backup_download_restriction.backup_download_restriction", "limit_vpc.#", "1"),
26+
resource.TestCheckResourceAttr("tencentcloud_redis_backup_download_restriction.backup_download_restriction", "limit_vpc.0.region", "ap-guangzhou"),
27+
resource.TestCheckResourceAttr("tencentcloud_redis_backup_download_restriction.backup_download_restriction", "limit_vpc.0.vpc_list.#", "1"),
28+
resource.TestCheckResourceAttr("tencentcloud_redis_backup_download_restriction.backup_download_restriction", "limit_ip.#", "2"),
29+
),
30+
},
31+
{
32+
ResourceName: "tencentcloud_redis_backup_download_restriction.backup_download_restriction",
33+
ImportState: true,
34+
ImportStateVerify: true,
35+
},
36+
},
37+
})
38+
}
39+
40+
const testAccRedisBackupDownloadRestrictionVar = `
41+
variable "vpc_id" {
42+
default = "` + defaultCrsVpcId + `"
43+
}
44+
`
45+
46+
const testAccRedisBackupDownloadRestriction = testAccRedisBackupDownloadRestrictionVar + `
47+
48+
resource "tencentcloud_redis_backup_download_restriction" "backup_download_restriction" {
49+
limit_type = "Customize"
50+
vpc_comparison_symbol = "In"
51+
ip_comparison_symbol = "In"
52+
limit_vpc {
53+
region = "ap-guangzhou"
54+
vpc_list = ["vpc-4owdpnwr"]
55+
}
56+
limit_ip = ["10.1.1.12", "10.1.1.13"]
57+
}
58+
59+
`

0 commit comments

Comments
 (0)