Skip to content

Commit 3514755

Browse files
tongyimingmikatong
andauthored
add lighthouse sweeper (#1743)
Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 7bdc265 commit 3514755

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tencentcloud/resource_tc_lighthouse_instance_test.go

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

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

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

12+
func init() {
13+
// go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_lighthouse_instance
14+
resource.AddTestSweepers("tencentcloud_lighthouse_instance", &resource.Sweeper{
15+
Name: "tencentcloud_lighthouse_instance",
16+
F: func(r string) error {
17+
logId := getLogId(contextNil)
18+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
19+
cli, _ := sharedClientForRegion(r)
20+
21+
request := lighthouse.NewDescribeInstancesRequest()
22+
response, err := cli.(*TencentCloudClient).apiV3Conn.UseLighthouseClient().DescribeInstances(request)
23+
if err != nil {
24+
return err
25+
}
26+
instances := response.Response.InstanceSet
27+
service := LightHouseService{client: cli.(*TencentCloudClient).apiV3Conn}
28+
29+
for _, instance := range instances {
30+
name := *instance.InstanceName
31+
created, err := time.Parse("2006-01-02 15:04:05", *instance.CreatedTime)
32+
if err != nil {
33+
continue
34+
}
35+
if isResourcePersist(name, &created) {
36+
continue
37+
}
38+
if innerErr := service.DeleteLighthouseInstanceById(ctx, *instance.InstanceId); innerErr != nil {
39+
continue
40+
}
41+
}
42+
return nil
43+
},
44+
})
45+
}
46+
947
func TestAccTencentCloudLighthouseInstance_basic(t *testing.T) {
1048
t.Parallel()
1149

0 commit comments

Comments
 (0)