@@ -3,12 +3,58 @@ package tencentcloud
33import (
44 "context"
55 "fmt"
6+ "strings"
67 "testing"
8+ "time"
79
810 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
911 "github.com/hashicorp/terraform-plugin-sdk/terraform"
1012)
1113
14+ func init () {
15+ // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_as_scaling_config
16+ resource .AddTestSweepers ("tencentcloud_as_scaling_config" , & resource.Sweeper {
17+ Name : "tencentcloud_as_scaling_config" ,
18+ F : func (r string ) error {
19+ logId := getLogId (contextNil )
20+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
21+ sharedClient , err := sharedClientForRegion (r )
22+ if err != nil {
23+ return fmt .Errorf ("getting tencentcloud client error: %s" , err .Error ())
24+ }
25+ client := sharedClient .(* TencentCloudClient )
26+ asService := AsService {
27+ client : client .apiV3Conn ,
28+ }
29+ configs , err := asService .DescribeLaunchConfigurationByFilter (ctx , "" , "" )
30+ if err != nil {
31+ return err
32+ }
33+ for _ , config := range configs {
34+ instanceName := * config .LaunchConfigurationName
35+ now := time .Now ()
36+ createTime := stringTotime (* config .CreatedTime )
37+ interval := now .Sub (createTime ).Minutes ()
38+
39+ if strings .HasPrefix (instanceName , keepResource ) || strings .HasPrefix (instanceName , defaultResource ) {
40+ continue
41+ }
42+
43+ if needProtect == 1 && int64 (interval ) < 30 {
44+ continue
45+ }
46+
47+ ee := asService .DeleteLaunchConfiguration (ctx , * config .LaunchConfigurationId )
48+ if ee != nil {
49+ continue
50+ }
51+ }
52+
53+ return nil
54+ },
55+ })
56+ }
57+
1258func TestAccTencentCloudAsScalingConfig_basic (t * testing.T ) {
1359 resource .Test (t , resource.TestCase {
1460 PreCheck : func () { testAccPreCheck (t ) },
0 commit comments