Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tencentcloud/resource_tc_teo_rule_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func init() {
// go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_teo_rule_engine
resource.AddTestSweepers("tencentcloud_teo_rule_engine", &resource.Sweeper{
Name: "tencentcloud_teo_rule_engine",
F: testSweepRuleEngine,
})
}

func testSweepRuleEngine(region string) error {
logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)
cli, _ := sharedClientForRegion(region)
client := cli.(*TencentCloudClient).apiV3Conn
service := TeoService{client}

zoneId := defaultZoneId

records, err := service.DescribeTeoRuleEngines(ctx, zoneId)
if err != nil {
return err
}

if len(records) < 1 {
return nil
}

for _, v := range records {
if *v.RuleName == "rule-1" {
err = service.DeleteTeoRuleEngineById(ctx, zoneId, *v.RuleId)
if err != nil {
return err
}
}
}
return nil
}

// go test -i; go test -test.run TestAccTencentCloudTeoRuleEngine_basic -v
func TestAccTencentCloudTeoRuleEngine_basic(t *testing.T) {
t.Parallel()
Expand Down
6 changes: 3 additions & 3 deletions tencentcloud/resource_tc_teo_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func testSweepZone(region string) error {
client := cli.(*TencentCloudClient).apiV3Conn
service := TeoService{client}

zoneId := clusterPrometheusId
zoneId := defaultZoneId

zone, err := service.DescribeTeoZone(ctx, zoneId)
if err != nil {
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestAccTencentCloudTeoZone_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckZoneExists("tencentcloud_teo_zone.basic"),
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "zone_name", "tf-teo.xyz"),
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "plan_type", "ent_with_bot"),
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "plan_type", "sta"),
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "type", "full"),
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "paused", "false"),
resource.TestCheckResourceAttr("tencentcloud_teo_zone.basic", "cname_speed_up", "enabled"),
Expand Down Expand Up @@ -120,7 +120,7 @@ const testAccTeoZone = `

resource "tencentcloud_teo_zone" "basic" {
cname_speed_up = "enabled"
plan_type = "ent_with_bot"
plan_type = "sta"
paused = false
type = "full"
zone_name = "tf-teo.xyz"
Expand Down
34 changes: 34 additions & 0 deletions tencentcloud/service_tencentcloud_teo.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,40 @@ func (me *TeoService) DescribeTeoRuleEngine(ctx context.Context, zoneId, ruleId

}

func (me *TeoService) DescribeTeoRuleEngines(ctx context.Context, zoneId string) (ruleEngines []*teo.RuleItem,
errRet error) {
var (
logId = getLogId(ctx)
request = teo.NewDescribeRulesRequest()
)

defer func() {
if errRet != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
logId, "query object", request.ToJsonString(), errRet.Error())
}
}()

request.ZoneId = &zoneId
ratelimit.Check(request.GetAction())
response, err := me.client.UseTeoClient().DescribeRules(request)
if err != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
logId, request.GetAction(), request.ToJsonString(), err.Error())
errRet = err
return
}
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())

if response != nil && response.Response != nil && response.Response.RuleItems != nil {
ruleEngines = response.Response.RuleItems
}

return

}

func (me *TeoService) DeleteTeoRuleEngineById(ctx context.Context, zoneId, ruleId string) (errRet error) {
logId := getLogId(ctx)

Expand Down