Skip to content

Commit b7b9a3d

Browse files
gitmknanonymous
andauthored
Feat/crs support (#1652)
* feat: add redis account * feat: support param * feat: support read only * feat: support ssl, maintenance_window * feat: support backup, connection_config, datasource * feat: add crs changelog * fix: modify provider * fix: modify crs * fix: modify test * fix: modify crs test * fix: modify ssl --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent a2a0694 commit b7b9a3d

37 files changed

+4928
-350
lines changed

.changelog/1652.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```release-note:new-resource
2+
tencentcloud_redis_account
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_redis_read_only
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_redis_ssl
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_redis_maintenance_window
15+
```
16+
17+
```release-note:new-data-source
18+
tencentcloud_redis_backup
19+
```
20+
21+
```release-note:new-data-source
22+
tencentcloud_redis_backup_download_info
23+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.599
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412
41-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.630
41+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.633
4242
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.572
@@ -63,7 +63,7 @@ require (
6363
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.625
6464
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.290
6565
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.533
66-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.490
66+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.633
6767
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.542
6868
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.275
6969
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.529

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.625/go.mod
531531
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.627/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
532532
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.630 h1:wjTmUzAigRKOYb+avYZCllzosnGqWM+U6u915znVRvs=
533533
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.630/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
534+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.633 h1:Yj8s35IjbgaHp4Ic9BZLVGWdN2gXBMtwYi1JJ+qYbrc=
535+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.633/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
534536
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
535537
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
536538
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589 h1:LZihgirMH0vsaGScYexxwY0fTss9vHaSZs/YOQUVESg=
@@ -582,6 +584,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.533 h1:BJDJlHk
582584
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.533/go.mod h1:SHeExU5ggWrG8hsc4BMmxdhhw6WpoiWSu1Jw8CXs/Dg=
583585
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.490 h1:JEW8+EjIGG5APXrPKLlMHo4fzLcCxVlg5QXwK1+YhA0=
584586
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.490/go.mod h1:1yBtZUeKla8GNnVnJ1JOgMVBi/YgjEuQgzO4uNmisdI=
587+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.633 h1:CvbXeonn1aSKXP6eJW7aT4EYnLY26QqtrquiUE3j27k=
588+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.633/go.mod h1:saByK7CXtqX3Q9+Vj+S4A3WceAmVifiQhVK8DKKY05I=
585589
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.542 h1:/U0rTVKXD7Y8Opw6OtnqSDPnWiP3zMMAlxOKayII/5Q=
586590
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.542/go.mod h1:QF1J13hmuMY5gMrBopRFmHWFs/KsLr5uCNBRJt5aA1M=
587591
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.275 h1:hn5RrN/qkcObnyKfJ+raey/riVeRqHJFvY34l2YgELs=

tencentcloud/basic_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,3 +957,10 @@ variable "cbs_backup_disk_id" {
957957
`
958958

959959
// End of CBS
960+
961+
// CRS
962+
const (
963+
defaultCrsInstanceId = "crs-jf4ico4v"
964+
)
965+
966+
// End of CRS
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
/*
2+
Use this data source to query detailed information of redis backup
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_redis_backup" "backup" {
8+
instance_id = "crs-c1nl9rpv"
9+
begin_time = "2023-04-07 03:57:30"
10+
end_time = "2023-04-07 03:57:56"
11+
status = [2]
12+
instance_name = "Keep-terraform"
13+
}
14+
```
15+
*/
16+
package tencentcloud
17+
18+
import (
19+
"context"
20+
21+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
22+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
23+
redis "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis/v20180412"
24+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
25+
)
26+
27+
func dataSourceTencentCloudRedisBackup() *schema.Resource {
28+
return &schema.Resource{
29+
Read: dataSourceTencentCloudRedisBackupRead,
30+
Schema: map[string]*schema.Schema{
31+
"instance_id": {
32+
Optional: true,
33+
Type: schema.TypeString,
34+
Description: "The ID of instance.",
35+
},
36+
37+
"begin_time": {
38+
Optional: true,
39+
Type: schema.TypeString,
40+
Description: "start time, such as 2017-02-08 19:09:26.Query the list of backups that the instance started backing up during the [beginTime, endTime] time period.",
41+
},
42+
43+
"end_time": {
44+
Optional: true,
45+
Type: schema.TypeString,
46+
Description: "End time, such as 2017-02-08 19:09:26.Query the list of backups that the instance started backing up during the [beginTime, endTime] time period.",
47+
},
48+
49+
"status": {
50+
Optional: true,
51+
Type: schema.TypeSet,
52+
Elem: &schema.Schema{
53+
Type: schema.TypeInt,
54+
},
55+
Description: "Status of the backup task:1: Backup is in the process.2: The backup is normal.3: Backup to RDB file processing.4: RDB conversion completed.-1: The backup has expired.-2: Backup deleted.",
56+
},
57+
58+
"instance_name": {
59+
Optional: true,
60+
Type: schema.TypeString,
61+
Description: "Instance name, which supports fuzzy search based on instance name.",
62+
},
63+
64+
"backup_set": {
65+
Computed: true,
66+
Type: schema.TypeList,
67+
Description: "An array of backups for the instance.",
68+
Elem: &schema.Resource{
69+
Schema: map[string]*schema.Schema{
70+
"start_time": {
71+
Type: schema.TypeString,
72+
Computed: true,
73+
Description: "Backup start time.",
74+
},
75+
"backup_id": {
76+
Type: schema.TypeString,
77+
Computed: true,
78+
Description: "Backup ID.",
79+
},
80+
"backup_type": {
81+
Type: schema.TypeString,
82+
Computed: true,
83+
Description: "Backup type.1: User-initiated manual backup.0: System-initiated backup in the early morning.",
84+
},
85+
"status": {
86+
Type: schema.TypeInt,
87+
Computed: true,
88+
Description: "Backup status.1: The backup is locked by another process.2: The backup is normal and not locked by any process.-1: The backup has expired.3: The backup is being exported.4: The backup export is successful.",
89+
},
90+
"remark": {
91+
Type: schema.TypeString,
92+
Computed: true,
93+
Description: "Notes information for the backup.",
94+
},
95+
"locked": {
96+
Type: schema.TypeInt,
97+
Computed: true,
98+
Description: "Whether the backup is locked.0: Not locked.1: Has been locked.",
99+
},
100+
"backup_size": {
101+
Type: schema.TypeInt,
102+
Computed: true,
103+
Description: "Internal fields, which can be ignored by the user.",
104+
},
105+
"full_backup": {
106+
Type: schema.TypeInt,
107+
Computed: true,
108+
Description: "Internal fields, which can be ignored by the user.",
109+
},
110+
"instance_type": {
111+
Type: schema.TypeInt,
112+
Computed: true,
113+
Description: "Internal fields, which can be ignored by the user.",
114+
},
115+
"instance_id": {
116+
Type: schema.TypeString,
117+
Computed: true,
118+
Description: "The ID of instance.",
119+
},
120+
"instance_name": {
121+
Type: schema.TypeString,
122+
Computed: true,
123+
Description: "The name of instance.",
124+
},
125+
"region": {
126+
Type: schema.TypeString,
127+
Computed: true,
128+
Description: "The region where the backup is located.",
129+
},
130+
"end_time": {
131+
Type: schema.TypeString,
132+
Computed: true,
133+
Description: "Backup end time.",
134+
},
135+
"file_type": {
136+
Type: schema.TypeString,
137+
Computed: true,
138+
Description: "Back up file types.",
139+
},
140+
"expire_time": {
141+
Type: schema.TypeString,
142+
Computed: true,
143+
Description: "Backup file expiration time.",
144+
},
145+
},
146+
},
147+
},
148+
149+
"result_output_file": {
150+
Type: schema.TypeString,
151+
Optional: true,
152+
Description: "Used to save results.",
153+
},
154+
},
155+
}
156+
}
157+
158+
func dataSourceTencentCloudRedisBackupRead(d *schema.ResourceData, meta interface{}) error {
159+
defer logElapsed("data_source.tencentcloud_redis_backup.read")()
160+
defer inconsistentCheck(d, meta)()
161+
162+
logId := getLogId(contextNil)
163+
164+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
165+
166+
paramMap := make(map[string]interface{})
167+
if v, ok := d.GetOk("instance_id"); ok {
168+
paramMap["instance_id"] = helper.String(v.(string))
169+
}
170+
171+
if v, ok := d.GetOk("begin_time"); ok {
172+
paramMap["begin_time"] = helper.String(v.(string))
173+
}
174+
175+
if v, ok := d.GetOk("end_time"); ok {
176+
paramMap["end_time"] = helper.String(v.(string))
177+
}
178+
179+
if v, ok := d.GetOk("status"); ok {
180+
statusSet := v.(*schema.Set).List()
181+
statusList := []*int64{}
182+
for i := range statusSet {
183+
status := statusSet[i].(int)
184+
statusList = append(statusList, helper.IntInt64(status))
185+
}
186+
paramMap["status"] = statusList
187+
}
188+
189+
if v, ok := d.GetOk("instance_name"); ok {
190+
paramMap["InstanceName"] = helper.String(v.(string))
191+
}
192+
193+
service := RedisService{client: meta.(*TencentCloudClient).apiV3Conn}
194+
195+
var backupSet []*redis.RedisBackupSet
196+
197+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
198+
result, e := service.DescribeRedisBackupByFilter(ctx, paramMap)
199+
if e != nil {
200+
return retryError(e)
201+
}
202+
backupSet = result
203+
return nil
204+
})
205+
if err != nil {
206+
return err
207+
}
208+
209+
ids := make([]string, 0, len(backupSet))
210+
tmpList := make([]map[string]interface{}, 0, len(backupSet))
211+
212+
if backupSet != nil {
213+
for _, redisBackupSet := range backupSet {
214+
redisBackupSetMap := map[string]interface{}{}
215+
216+
if redisBackupSet.StartTime != nil {
217+
redisBackupSetMap["start_time"] = redisBackupSet.StartTime
218+
}
219+
220+
if redisBackupSet.BackupId != nil {
221+
redisBackupSetMap["backup_id"] = redisBackupSet.BackupId
222+
}
223+
224+
if redisBackupSet.BackupType != nil {
225+
redisBackupSetMap["backup_type"] = redisBackupSet.BackupType
226+
}
227+
228+
if redisBackupSet.Status != nil {
229+
redisBackupSetMap["status"] = redisBackupSet.Status
230+
}
231+
232+
if redisBackupSet.Remark != nil {
233+
redisBackupSetMap["remark"] = redisBackupSet.Remark
234+
}
235+
236+
if redisBackupSet.Locked != nil {
237+
redisBackupSetMap["locked"] = redisBackupSet.Locked
238+
}
239+
240+
if redisBackupSet.BackupSize != nil {
241+
redisBackupSetMap["backup_size"] = redisBackupSet.BackupSize
242+
}
243+
244+
if redisBackupSet.FullBackup != nil {
245+
redisBackupSetMap["full_backup"] = redisBackupSet.FullBackup
246+
}
247+
248+
if redisBackupSet.InstanceType != nil {
249+
redisBackupSetMap["instance_type"] = redisBackupSet.InstanceType
250+
}
251+
252+
if redisBackupSet.InstanceId != nil {
253+
redisBackupSetMap["instance_id"] = redisBackupSet.InstanceId
254+
}
255+
256+
if redisBackupSet.InstanceName != nil {
257+
redisBackupSetMap["instance_name"] = redisBackupSet.InstanceName
258+
}
259+
260+
if redisBackupSet.Region != nil {
261+
redisBackupSetMap["region"] = redisBackupSet.Region
262+
}
263+
264+
if redisBackupSet.EndTime != nil {
265+
redisBackupSetMap["end_time"] = redisBackupSet.EndTime
266+
}
267+
268+
if redisBackupSet.FileType != nil {
269+
redisBackupSetMap["file_type"] = redisBackupSet.FileType
270+
}
271+
272+
if redisBackupSet.ExpireTime != nil {
273+
redisBackupSetMap["expire_time"] = redisBackupSet.ExpireTime
274+
}
275+
276+
ids = append(ids, *redisBackupSet.InstanceId)
277+
tmpList = append(tmpList, redisBackupSetMap)
278+
}
279+
280+
_ = d.Set("backup_set", tmpList)
281+
}
282+
283+
d.SetId(helper.DataResourceIdsHash(ids))
284+
output, ok := d.GetOk("result_output_file")
285+
if ok && output.(string) != "" {
286+
if e := writeToFile(output.(string), tmpList); e != nil {
287+
return e
288+
}
289+
}
290+
return nil
291+
}

0 commit comments

Comments
 (0)