Skip to content

Commit ad2fd90

Browse files
author
hellertang
authored
fix cvm sweeper (#989)
1 parent c1f7e71 commit ad2fd90

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tencentcloud/resource_tc_instance_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"strings"
88
"testing"
9+
"time"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1112
"github.com/hashicorp/terraform-plugin-sdk/terraform"
@@ -40,7 +41,15 @@ func testSweepCvmInstance(region string) error {
4041
for _, v := range instances {
4142
instanceId := *v.InstanceId
4243
instanceName := *v.InstanceName
43-
if !strings.HasPrefix(instanceName, defaultInsName) {
44+
now := time.Now()
45+
createTime := stringTotime(*v.CreatedTime)
46+
interval := now.Sub(createTime).Minutes()
47+
48+
if strings.HasPrefix(instanceName, keepResource) || strings.HasPrefix(instanceName, defaultResource) {
49+
continue
50+
}
51+
52+
if needProtect == 1 && int64(interval) < 30 {
4453
continue
4554
}
4655

0 commit comments

Comments
 (0)