Skip to content

Commit c426540

Browse files
tongyimingmikatong
andauthored
add cbs backup sweep (#1602)
Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 7df2006 commit c426540

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tencentcloud/resource_tc_cbs_disk_backup_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
11
package tencentcloud
22

33
import (
4+
"context"
45
"testing"
6+
"time"
57

68
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
9+
cbs "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs/v20170312"
710
)
811

12+
func init() {
13+
// go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_cbs_disk_backup
14+
resource.AddTestSweepers("tencentcloud_cbs_disk_backup", &resource.Sweeper{
15+
Name: "tencentcloud_cbs_disk_backup",
16+
F: func(r string) error {
17+
logId := getLogId(contextNil)
18+
cli, _ := sharedClientForRegion(r)
19+
request := cbs.NewDescribeDiskBackupsRequest()
20+
resp, err := cli.(*TencentCloudClient).apiV3Conn.UseCbsClient().DescribeDiskBackups(request)
21+
if err != nil {
22+
return err
23+
}
24+
diskBuckups := resp.Response.DiskBackupSet
25+
for _, diskBuckup := range diskBuckups {
26+
created, err := time.Parse("2006-01-02 15:04:05", *diskBuckup.CreateTime)
27+
if err != nil {
28+
created = time.Now()
29+
}
30+
name := *diskBuckup.DiskBackupName
31+
if isResourcePersist(name, &created) {
32+
continue
33+
}
34+
buckupId := *diskBuckup.DiskBackupId
35+
client := cli.(*TencentCloudClient).apiV3Conn
36+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
37+
service := CbsService{client}
38+
err = service.DeleteCbsDiskBackupById(ctx, buckupId)
39+
if err != nil {
40+
continue
41+
}
42+
}
43+
44+
return nil
45+
},
46+
})
47+
}
48+
949
func TestAccTencentCloudCbsDiskBackupResource_basic(t *testing.T) {
1050
t.Parallel()
1151

0 commit comments

Comments
 (0)