@@ -3,12 +3,46 @@ package tencentcloud
33import (
44 "context"
55 "fmt"
6+ "strings"
67 "testing"
78
89 "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
910 "github.com/hashicorp/terraform-plugin-sdk/terraform"
1011)
1112
13+ func init () {
14+ // go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_elasticsearch_instance
15+ resource .AddTestSweepers ("tencentcloud_elasticsearch_instance" , & resource.Sweeper {
16+ Name : "tencentcloud_elasticsearch_instance" ,
17+ F : func (r string ) error {
18+ logId := getLogId (contextNil )
19+ ctx := context .WithValue (context .TODO (), logIdKey , logId )
20+ cli , _ := sharedClientForRegion (r )
21+ client := cli .(* TencentCloudClient ).apiV3Conn
22+
23+ service := ElasticsearchService {client : client }
24+
25+ es , err := service .DescribeInstancesByFilter (ctx , "" , "tf-ci-test" , nil )
26+ if err != nil {
27+ return err
28+ }
29+
30+ for _ , v := range es {
31+ id := * v .InstanceId
32+ name := * v .InstanceName
33+ if ! strings .Contains (name , "tf-ci-test" ) {
34+ continue
35+ }
36+ if err := service .DeleteInstance (ctx , id ); err != nil {
37+ continue
38+ }
39+ }
40+
41+ return nil
42+ },
43+ })
44+ }
45+
1246func TestAccTencentCloudElasticsearchInstance_basic (t * testing.T ) {
1347 t .Parallel ()
1448
@@ -31,7 +65,7 @@ func TestAccTencentCloudElasticsearchInstance_basic(t *testing.T) {
3165 resource .TestCheckResourceAttr ("tencentcloud_elasticsearch_instance.foo" , "web_node_type_info.0.node_num" , "1" ),
3266 resource .TestCheckResourceAttr ("tencentcloud_elasticsearch_instance.foo" , "web_node_type_info.0.node_type" , "ES.S1.MEDIUM4" ),
3367 resource .TestCheckResourceAttr ("tencentcloud_elasticsearch_instance.foo" , "node_info_list.0.node_num" , "2" ),
34- resource .TestCheckResourceAttr ("tencentcloud_elasticsearch_instance.foo" , "node_info_list.0.node_type" , "ES.S1.SMALL2 " ),
68+ resource .TestCheckResourceAttr ("tencentcloud_elasticsearch_instance.foo" , "node_info_list.0.node_type" , "ES.S1.MEDIUM4 " ),
3569 resource .TestCheckResourceAttr ("tencentcloud_elasticsearch_instance.foo" , "node_info_list.0.type" , "hotData" ),
3670 resource .TestCheckResourceAttr ("tencentcloud_elasticsearch_instance.foo" , "node_info_list.0.encrypt" , "false" ),
3771 resource .TestCheckResourceAttr ("tencentcloud_elasticsearch_instance.foo" , "tags.test" , "terraform" ),
@@ -144,7 +178,7 @@ resource "tencentcloud_elasticsearch_instance" "foo" {
144178
145179 node_info_list {
146180 node_num = 2
147- node_type = "ES.S1.SMALL2 "
181+ node_type = "ES.S1.MEDIUM4 "
148182 }
149183
150184 tags = {
0 commit comments