File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed
Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change 44 "context"
55 "fmt"
66 "log"
7+ "strings"
78 "testing"
9+ "time"
810
911 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1012 "github.com/hashicorp/terraform-plugin-sdk/terraform"
@@ -34,14 +36,6 @@ func testSweepClbInstance(region string) error {
3436 }
3537 client := cli .(* TencentCloudClient ).apiV3Conn
3638 service := ClbService {client : client }
37- testCaseNames := []string {
38- BasicClbName ,
39- InternalClbName ,
40- InternalClbNameUpdate ,
41- MyOpenClbName ,
42- OpenClbName ,
43- OpenClbNameUpdate ,
44- }
4539
4640 res , err := service .DescribeLoadBalancerByFilter (ctx , map [string ]interface {}{})
4741 if err != nil {
@@ -51,9 +45,17 @@ func testSweepClbInstance(region string) error {
5145 if len (res ) > 0 {
5246 for _ , v := range res {
5347 id := * v .LoadBalancerId
48+ instanceName := * v .LoadBalancerName
49+ createTime := stringTotime (* v .CreateTime )
5450
55- name := * v .LoadBalancerName
56- if ! IsContains (testCaseNames , name ) {
51+ now := time .Now ()
52+ interval := now .Sub (createTime ).Minutes ()
53+ // keep not delete
54+ if strings .HasPrefix (instanceName , keepResource ) || strings .HasPrefix (instanceName , defaultResource ) {
55+ continue
56+ }
57+ // less than 30 minute, not delete
58+ if int64 (interval ) < 30 {
5759 continue
5860 }
5961 if err := service .DeleteLoadBalancerById (ctx , id ); err != nil {
@@ -62,7 +64,6 @@ func testSweepClbInstance(region string) error {
6264 }
6365 }
6466 }
65-
6667 return nil
6768}
6869
You can’t perform that action at this time.
0 commit comments