Skip to content

Commit f06bcba

Browse files
authored
Feat/dayu l7 rules (#2062)
* add dayu l7 rules * fix l7 * add changelog
1 parent e219085 commit f06bcba

File tree

7 files changed

+81
-60
lines changed

7 files changed

+81
-60
lines changed

.changelog/2062.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_dayu_l7_rules_v2: fix query results.
3+
```

tencentcloud/data_source_tc_dayu_l7_rules.go

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ func dataSourceTencentCloudDayuL7RulesRead(d *schema.ResourceData, meta interfac
194194
list := make([]map[string]interface{}, 0, len(rules))
195195
ids := make([]string, 0, len(rules))
196196

197-
listItem := make(map[string]interface{})
198197
for k, rule := range rules {
199-
health := healths[k]
198+
listItem := make(map[string]interface{})
199+
200200
listItem["name"] = *rule.RuleName
201201
listItem["domain"] = *rule.Domain
202202
listItem["ssl_id"] = *rule.SSLId
@@ -217,26 +217,30 @@ func dataSourceTencentCloudDayuL7RulesRead(d *schema.ResourceData, meta interfac
217217
}
218218
listItem["source_list"] = helper.StringsInterfaces(sourceList)
219219

220-
if health.Enable != nil {
221-
listItem["health_check_switch"] = *health.Enable > 0
222-
}
223-
if health.Url != nil {
224-
listItem["health_check_path"] = *health.Url
225-
}
226-
if health.StatusCode != nil {
227-
listItem["health_check_code"] = int(*health.StatusCode)
228-
}
229-
if health.Interval != nil {
230-
listItem["health_check_interval"] = int(*health.Interval)
231-
}
232-
if health.KickNum != nil {
233-
listItem["health_check_unhealth_num"] = int(*health.KickNum)
234-
}
235-
if health.AliveNum != nil {
236-
listItem["health_check_health_num"] = int(*health.AliveNum)
237-
}
238-
if health.Method != nil {
239-
listItem["health_check_method"] = *health.Method
220+
if k < len(healths) {
221+
health := healths[k]
222+
223+
if health.Enable != nil {
224+
listItem["health_check_switch"] = *health.Enable > 0
225+
}
226+
if health.Url != nil {
227+
listItem["health_check_path"] = *health.Url
228+
}
229+
if health.StatusCode != nil {
230+
listItem["health_check_code"] = int(*health.StatusCode)
231+
}
232+
if health.Interval != nil {
233+
listItem["health_check_interval"] = int(*health.Interval)
234+
}
235+
if health.KickNum != nil {
236+
listItem["health_check_unhealth_num"] = int(*health.KickNum)
237+
}
238+
if health.AliveNum != nil {
239+
listItem["health_check_health_num"] = int(*health.AliveNum)
240+
}
241+
if health.Method != nil {
242+
listItem["health_check_method"] = *health.Method
243+
}
240244
}
241245
list = append(list, listItem)
242246
ids = append(ids, listItem["rule_id"].(string))

tencentcloud/data_source_tc_dayu_l7_rules_v2.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Example Usage
55
66
```hcl
77
data "tencentcloud_dayu_l7_rules_v2" "test" {
8-
business = "bgpip"
9-
offset = 0
10-
limit = 10
8+
business = "bgpip"
9+
domain = "qq.com"
10+
protocol = "https"
1111
}
1212
```
1313
*/
@@ -50,12 +50,14 @@ func dataSourceTencentCloudDayuL7RulesV2() *schema.Resource {
5050
Type: schema.TypeInt,
5151
Optional: true,
5252
Default: 0,
53+
Deprecated: "It has been deprecated from version 1.81.21.",
5354
Description: "The page start offset, default is `0`.",
5455
},
5556
"limit": {
5657
Type: schema.TypeInt,
5758
Optional: true,
5859
Default: 10,
60+
Deprecated: "It has been deprecated from version 1.81.21.",
5961
Description: "The number of pages, default is `10`.",
6062
},
6163
"result_output_file": {
@@ -205,16 +207,16 @@ func dataSourceTencentCloudDayuL7RulesReadV2(d *schema.ResourceData, meta interf
205207
}
206208

207209
business := d.Get("business").(string)
208-
offset := d.Get("offset").(int)
209-
limit := d.Get("limit").(int)
210210
domain := d.Get("domain").(string)
211211
protocol := d.Get("protocol").(string)
212+
ip := d.Get("ip").(string)
212213

213214
extendParams := make(map[string]interface{})
214215
extendParams["domain"] = domain
215216
extendParams["protocol"] = protocol
217+
extendParams["ip"] = ip
216218

217-
rules, _, err := service.DescribeL7RulesV2(ctx, business, offset, limit, extendParams)
219+
rules, _, err := service.DescribeL7RulesV2(ctx, business, extendParams)
218220
if err != nil {
219221
return err
220222
}

tencentcloud/resource_tc_dayu_l7_rule_v2.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func resourceTencentCloudDayuL7RuleUpdateV2(d *schema.ResourceData, meta interfa
192192
extendParams := make(map[string]interface{})
193193
extendParams["domain"] = domain
194194
extendParams["protocol"] = protocol
195-
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, 0, 10, extendParams)
195+
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, extendParams)
196196
if err != nil {
197197
return err
198198
}
@@ -278,11 +278,9 @@ func resourceTencentCloudDayuL7RuleReadV2(d *schema.ResourceData, meta interface
278278
extendParams := make(map[string]interface{})
279279
extendParams["domain"] = domain
280280
extendParams["protocol"] = protocol
281-
offset := 0
282-
limit := 10
283281
dayuService := DayuService{client: meta.(*TencentCloudClient).apiV3Conn}
284282
for {
285-
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, offset, limit, extendParams)
283+
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, extendParams)
286284
if err != nil {
287285
return err
288286
}
@@ -318,7 +316,7 @@ func resourceTencentCloudDayuL7RuleDeleteV2(d *schema.ResourceData, meta interfa
318316
extendParams := make(map[string]interface{})
319317
extendParams["domain"] = domain
320318
extendParams["protocol"] = protocol
321-
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, 0, 10, extendParams)
319+
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, extendParams)
322320
if err != nil {
323321
return err
324322
}

tencentcloud/resource_tc_dayu_l7_rule_v2_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func testAccCheckDayuL7RuleV2Destroy(s *terraform.State) error {
5353
extendParams["domain"] = domain
5454
extendParams["protocol"] = protocol
5555
dayuService := DayuService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
56-
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, 0, 10, extendParams)
56+
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, extendParams)
5757
if err != nil {
5858
return err
5959
}
@@ -101,7 +101,7 @@ func testAccCheckDayuL7RuleV2Exists(n string) resource.TestCheckFunc {
101101
extendParams["domain"] = domain
102102
extendParams["protocol"] = protocol
103103
dayuService := DayuService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn}
104-
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, 0, 10, extendParams)
104+
rules, _, err := dayuService.DescribeL7RulesV2(ctx, business, extendParams)
105105

106106
if err != nil {
107107
return err

tencentcloud/service_tencentcloud_dayu.go

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ func (me *DayuService) SetSession(ctx context.Context, resourceType string, reso
18271827
return
18281828
}
18291829

1830-
func (me *DayuService) DescribeL7RulesV2(ctx context.Context, business string, offset int, limit int, extendParams map[string]interface{}) (rules []*dayu.NewL7RuleEntry, healths []*dayu.L7RuleHealth, errRet error) {
1830+
func (me *DayuService) DescribeL7RulesV2(ctx context.Context, business string, extendParams map[string]interface{}) (rules []*dayu.NewL7RuleEntry, healths []*dayu.L7RuleHealth, errRet error) {
18311831
logId := getLogId(ctx)
18321832
request := dayu.NewDescribleNewL7RulesRequest()
18331833

@@ -1850,32 +1850,46 @@ func (me *DayuService) DescribeL7RulesV2(ctx context.Context, business string, o
18501850
request.Domain = &domain
18511851
}
18521852
}
1853-
offsetUint64 := uint64(offset)
1854-
request.Offset = &offsetUint64
1855-
limitUint64 := uint64(limit)
1856-
request.Limit = &limitUint64
1857-
var response *dayu.DescribleNewL7RulesResponse
1858-
errRet = resource.Retry(readRetryTimeout, func() *resource.RetryError {
1853+
if v, ok := extendParams["ip"]; ok {
1854+
ip := v.(string)
1855+
if ip != "" {
1856+
request.Ip = &ip
1857+
}
1858+
}
1859+
1860+
var (
1861+
offset uint64 = 0
1862+
limit uint64 = 20
1863+
)
1864+
1865+
for {
1866+
request.Offset = &offset
1867+
request.Limit = &limit
18591868
ratelimit.Check(request.GetAction())
1860-
response, errRet = me.client.UseDayuClient().DescribleNewL7Rules(request)
1869+
response, err := me.client.UseDayuClient().DescribleNewL7Rules(request)
18611870

1862-
if e, ok := errRet.(*sdkError.TencentCloudSDKError); ok {
1863-
if e.GetCode() == "InternalError.ClusterNotFound" {
1864-
return nil
1865-
}
1871+
if err != nil {
1872+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
1873+
logId, request.GetAction(), request.ToJsonString(), err.Error())
1874+
errRet = err
1875+
return
18661876
}
1867-
if errRet != nil {
1868-
return resource.RetryableError(errRet)
1877+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
1878+
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1879+
1880+
if response == nil || len(response.Response.Rules) < 1 {
1881+
break
18691882
}
1870-
return nil
1871-
})
1872-
if errRet != nil {
1873-
return
1883+
1884+
rules = append(rules, response.Response.Rules...)
1885+
healths = append(healths, response.Response.Healths...)
1886+
if len(response.Response.Rules) < int(limit) {
1887+
break
1888+
}
1889+
1890+
offset += limit
18741891
}
1875-
rules = response.Response.Rules
1876-
healths = response.Response.Healths
18771892
return
1878-
18791893
}
18801894

18811895
func (me *DayuService) CreateL7RuleV2(ctx context.Context, business string, resourceId string, resourceIp string, ruleList []interface{}) (errRet error) {

website/docs/d/dayu_l7_rules_v2.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Use this data source to query new dayu layer 7 rules
1616
```hcl
1717
data "tencentcloud_dayu_l7_rules_v2" "test" {
1818
business = "bgpip"
19-
offset = 0
20-
limit = 10
19+
domain = "qq.com"
20+
protocol = "https"
2121
}
2222
```
2323

@@ -28,8 +28,8 @@ The following arguments are supported:
2828
* `business` - (Required, String) Type of the resource that the layer 4 rule works for, valid values are `bgpip`, `bgp`, `bgp-multip` and `net`.
2929
* `domain` - (Optional, String) Domain of resource.
3030
* `ip` - (Optional, String) Ip of the resource.
31-
* `limit` - (Optional, Int) The number of pages, default is `10`.
32-
* `offset` - (Optional, Int) The page start offset, default is `0`.
31+
* `limit` - (Optional, Int, **Deprecated**) It has been deprecated from version 1.81.21. The number of pages, default is `10`.
32+
* `offset` - (Optional, Int, **Deprecated**) It has been deprecated from version 1.81.21. The page start offset, default is `0`.
3333
* `protocol` - (Optional, String) Protocol of resource, value range [`http`, `https`].
3434
* `result_output_file` - (Optional, String) Used to save results.
3535

0 commit comments

Comments
 (0)