Skip to content

Commit e5a4181

Browse files
authored
Fix/teo proxy engine unit (#1358)
* fix: update teo * fix: update teo * feat: add changelog Co-authored-by: arunma <arunma@tencent.com>
1 parent 1954b16 commit e5a4181

File tree

14 files changed

+1016
-528
lines changed

14 files changed

+1016
-528
lines changed

.changelog/1358.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_teo_application_proxy_rule: Add origin_port filed
3+
```

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require (
3434
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.445
3535
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199
3636
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.412
37-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.527
37+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.529
3838
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.488
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
@@ -53,6 +53,7 @@ require (
5353
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.290
5454
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.490
5555
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.275
56+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.486
5657
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver v1.0.406
5758
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.199
5859
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm v1.0.199
@@ -63,7 +64,7 @@ require (
6364
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.503
6465
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.268
6566
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.527
66-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.500
67+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529
6768
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.519
6869
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199
6970
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc v1.0.515

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.519/go.mod
503503
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.524/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
504504
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.527 h1:hpZMjoYnR+ma5HMWWNaNc5fshpFXXaUPrZMo4OXPxYQ=
505505
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.527/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
506+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.529 h1:B26Pn9N5O3Mmbh8icZSpZ8kkhcfnapUdU/TBxPDWggA=
507+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.529/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
506508
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445 h1:Bh7XD0ypNMHYyBOM8hhKsSu+y0VVKUnJVS+YKKhfpGg=
507509
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.445/go.mod h1:jMDD351efCFpT1+KVFbcpu6SbmP4TYmp4qkoCfr63nQ=
508510
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.488 h1:A1seXWtMf2atBjSNYvcwxyDoFzCMgqyVnsxnWzhqJEA=
@@ -564,6 +566,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.527 h1:nRFYv2e
564566
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.527/go.mod h1:mWXRd5WNzX7ypg1MNliZvz5mlfIJ9h0KvyOGnH86KFc=
565567
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.500 h1:8pOrQK3GLskFEHGYR3s6is0YLAgSe7vYs7wdC+brA30=
566568
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.500/go.mod h1:eQfp4Z6W1vg5vBVkR6i/ZdgKeXWoMECCvQKGTvU5dP0=
569+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529 h1:vWUgseUvHs1fW/Ok+x3ld9UIhrYRNO9Yr8ccX8wmkkY=
570+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.529/go.mod h1:vOd23iOVeQqm5LSEXUmE8773kiUCwGuoJnTO0po5D+Q=
567571
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.519 h1:o8NsQPLV6T8TD4sHxufCwtCsqYM4CUM1132zut6toww=
568572
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.519/go.mod h1:ydWSzYKc8AwtT9I8Cd0JdICqiyp9h+u2J5maDWxC9Mo=
569573
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod v1.0.199 h1:6Yt74l4pA5QtzhwMNIEUt0spXdSBKH744DDqTHJOCP0=

tencentcloud/basic_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,10 @@ locals {
742742
// TEO
743743

744744
const (
745-
defaultZoneName = "tf-teo-t.xyz"
746-
defaultZoneId = "zone-2a1u0y616jz6"
747-
defaultPolicyId = "11587"
745+
defaultZoneName = "tf-teo-t.xyz"
746+
defaultZoneId = "zone-2a1u0y616jz6"
747+
defaultPolicyId = "11587"
748+
applicationProxyId = "proxy-f2c15f4f-5b34-11ed-aa27-525400b35dd9"
748749
)
749750

750751
// End of TEO

tencentcloud/resource_tc_elasticsearch_instance.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ import (
5656
"fmt"
5757
"log"
5858

59+
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
60+
5961
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
6062
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
6163
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"

tencentcloud/resource_tc_teo_application_proxy_rule.go

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Example Usage
77
resource "tencentcloud_teo_application_proxy_rule" "application_proxy_rule" {
88
forward_client_ip = "TOA"
99
origin_type = "custom"
10+
origin_port = "8083"
1011
origin_value = [
11-
"127.0.0.1:8081",
12+
"127.0.0.1",
1213
]
1314
port = [
1415
"8083",
@@ -91,6 +92,12 @@ func resourceTencentCloudTeoApplicationProxyRule() *schema.Resource {
9192
Description: "Origin server type.- `custom`: Specified origins.- `origins`: An origin group.",
9293
},
9394

95+
"origin_port": {
96+
Type: schema.TypeString,
97+
Required: true,
98+
Description: "Origin port, supported formats: single port: 80; Port segment: 81-90, 81 to 90 ports.",
99+
},
100+
94101
"origin_value": {
95102
Type: schema.TypeSet,
96103
Elem: &schema.Schema{
@@ -164,6 +171,10 @@ func resourceTencentCloudTeoApplicationProxyRuleCreate(d *schema.ResourceData, m
164171
request.OriginType = helper.String(v.(string))
165172
}
166173

174+
if v, ok := d.GetOk("origin_port"); ok {
175+
request.OriginPort = helper.String(v.(string))
176+
}
177+
167178
if v, ok := d.GetOk("origin_value"); ok {
168179
originValueSet := v.(*schema.Set).List()
169180
for i := range originValueSet {
@@ -268,6 +279,10 @@ func resourceTencentCloudTeoApplicationProxyRuleRead(d *schema.ResourceData, met
268279
_ = d.Set("origin_type", proxyRule.OriginType)
269280
}
270281

282+
if proxyRule.OriginPort != nil {
283+
_ = d.Set("origin_port", proxyRule.OriginPort)
284+
}
285+
271286
if proxyRule.OriginValue != nil {
272287
_ = d.Set("origin_value", proxyRule.OriginValue)
273288
}
@@ -319,10 +334,8 @@ func resourceTencentCloudTeoApplicationProxyRuleUpdate(d *schema.ResourceData, m
319334

320335
}
321336

322-
if d.HasChange("proto") {
323-
if v, ok := d.GetOk("proto"); ok {
324-
request.Proto = helper.String(v.(string))
325-
}
337+
if v, ok := d.GetOk("proto"); ok {
338+
request.Proto = helper.String(v.(string))
326339
}
327340

328341
if v, ok := d.GetOk("port"); ok {
@@ -337,26 +350,24 @@ func resourceTencentCloudTeoApplicationProxyRuleUpdate(d *schema.ResourceData, m
337350
request.OriginType = helper.String(v.(string))
338351
}
339352

340-
if d.HasChange("origin_value") {
341-
if v, ok := d.GetOk("origin_value"); ok {
342-
originValueSet := v.(*schema.Set).List()
343-
for i := range originValueSet {
344-
originValue := originValueSet[i].(string)
345-
request.OriginValue = append(request.OriginValue, &originValue)
346-
}
347-
}
353+
if v, ok := d.GetOk("origin_port"); ok {
354+
request.OriginPort = helper.String(v.(string))
348355
}
349356

350-
if d.HasChange("forward_client_ip") {
351-
if v, ok := d.GetOk("forward_client_ip"); ok {
352-
request.ForwardClientIp = helper.String(v.(string))
357+
if v, ok := d.GetOk("origin_value"); ok {
358+
originValueSet := v.(*schema.Set).List()
359+
for i := range originValueSet {
360+
originValue := originValueSet[i].(string)
361+
request.OriginValue = append(request.OriginValue, &originValue)
353362
}
354363
}
355364

356-
if d.HasChange("session_persist") {
357-
if v, ok := d.GetOk("session_persist"); ok {
358-
request.SessionPersist = helper.Bool(v.(bool))
359-
}
365+
if v, ok := d.GetOk("forward_client_ip"); ok {
366+
request.ForwardClientIp = helper.String(v.(string))
367+
}
368+
369+
if v, ok := d.GetOk("session_persist"); ok {
370+
request.SessionPersist = helper.Bool(v.(bool))
360371
}
361372

362373
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
@@ -403,6 +414,25 @@ func resourceTencentCloudTeoApplicationProxyRuleUpdate(d *schema.ResourceData, m
403414
}
404415
}
405416

417+
service := TeoService{client: meta.(*TencentCloudClient).apiV3Conn}
418+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
419+
err = resource.Retry(60*readRetryTimeout, func() *resource.RetryError {
420+
instance, errRet := service.DescribeTeoApplicationProxyRule(ctx, zoneId, proxyId, ruleId)
421+
if errRet != nil {
422+
return retryError(errRet, InternalError)
423+
}
424+
if *instance.Status == "online" {
425+
return nil
426+
}
427+
if *instance.Status == "fail" {
428+
return resource.NonRetryableError(fmt.Errorf("applicationProxyRule status is %v, operate failed.", *instance.Status))
429+
}
430+
return resource.RetryableError(fmt.Errorf("applicationProxyRule status is %v, retry...", *instance.Status))
431+
})
432+
if err != nil {
433+
return err
434+
}
435+
406436
return resourceTencentCloudTeoApplicationProxyRuleRead(d, meta)
407437
}
408438

tencentcloud/resource_tc_teo_application_proxy_rule_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ func TestAccTencentCloudTeoApplicationProxyRule_basic(t *testing.T) {
2323
Config: testAccTeoApplicationProxyRule,
2424
Check: resource.ComposeTestCheckFunc(
2525
testAccCheckApplicationProxyRuleExists("tencentcloud_teo_application_proxy_rule.basic"),
26-
//resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "zone_name", "tf-teo.com"),
27-
//resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "plan_type", "ent_with_bot"),
26+
resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "forward_client_ip", "TOA"),
27+
resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "origin_type", "custom"),
28+
resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "origin_port", "8083"),
29+
resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "origin_value.#", "1"),
30+
resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "port.#", "1"),
31+
resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "proto", "TCP"),
32+
resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "session_persist", "false"),
33+
resource.TestCheckResourceAttr("tencentcloud_teo_application_proxy_rule.basic", "status", "online"),
2834
),
2935
},
3036
{
@@ -99,23 +105,24 @@ variable "default_zone_id" {
99105
default = "` + defaultZoneId + `"
100106
}
101107
variable "proxy_id" {
102-
default = "` + defaultPolicyId + `"
108+
default = "` + applicationProxyId + `"
103109
}
104110
`
105111

106-
const testAccTeoApplicationProxyRule = testAccTeoApplicationProxyRuleVar + testAccTeoApplicationProxy + `
112+
const testAccTeoApplicationProxyRule = testAccTeoApplicationProxyRuleVar + `
107113
108114
resource "tencentcloud_teo_application_proxy_rule" "basic" {
109115
forward_client_ip = "TOA"
110116
origin_type = "custom"
117+
origin_port = "8083"
111118
origin_value = [
112-
"127.0.0.1:8081",
119+
"127.0.0.1",
113120
]
114121
port = [
115122
"8083",
116123
]
117124
proto = "TCP"
118-
proxy_id = tencentcloud_teo_application_proxy.basic.proxy_id
125+
proxy_id = var.proxy_id
119126
session_persist = false
120127
status = "online"
121128
zone_id = var.default_zone_id

tencentcloud/service_tencentcloud_teo.go

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -679,84 +679,6 @@ func (me *TeoService) DescribeTeoSecurityPolicy(ctx context.Context,
679679
return
680680
}
681681

682-
func (me *TeoService) DescribeTeoHostCertificate(ctx context.Context,
683-
zoneId, host, certId string) (hostCertificate []*teo.HostsCertificate, errRet error) {
684-
var (
685-
logId = getLogId(ctx)
686-
request = teo.NewDescribeHostCertificatesRequest()
687-
)
688-
689-
defer func() {
690-
if errRet != nil {
691-
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
692-
logId, "query object", request.ToJsonString(), errRet.Error())
693-
}
694-
}()
695-
696-
request.Filters = append(
697-
request.Filters,
698-
&teo.AdvancedFilter{
699-
Name: helper.String("zone-id"),
700-
Values: []*string{&zoneId},
701-
Fuzzy: helper.Bool(false),
702-
},
703-
)
704-
request.Filters = append(
705-
request.Filters,
706-
&teo.AdvancedFilter{
707-
Name: helper.String("host"),
708-
Values: []*string{&host},
709-
Fuzzy: helper.Bool(false),
710-
},
711-
)
712-
713-
request.Filters = append(
714-
request.Filters,
715-
&teo.AdvancedFilter{
716-
Name: helper.String("cert-id"),
717-
Values: []*string{&certId},
718-
Fuzzy: helper.Bool(false),
719-
},
720-
)
721-
ratelimit.Check(request.GetAction())
722-
723-
var offset int64 = 0
724-
var pageSize int64 = 100
725-
instances := make([]*teo.HostsCertificate, 0)
726-
727-
for {
728-
request.Offset = &offset
729-
request.Limit = &pageSize
730-
ratelimit.Check(request.GetAction())
731-
response, err := me.client.UseTeoClient().DescribeHostCertificates(request)
732-
if err != nil {
733-
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
734-
logId, request.GetAction(), request.ToJsonString(), err.Error())
735-
errRet = err
736-
return
737-
}
738-
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
739-
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
740-
741-
if response == nil || len(response.Response.HostCertificates) < 1 {
742-
break
743-
}
744-
instances = append(instances, response.Response.HostCertificates...)
745-
if len(response.Response.HostCertificates) < int(pageSize) {
746-
break
747-
}
748-
offset += pageSize
749-
}
750-
751-
if len(instances) < 1 {
752-
return
753-
}
754-
hostCertificate = instances
755-
756-
return
757-
758-
}
759-
760682
func (me *TeoService) DescribeTeoDnsSec(ctx context.Context, zoneId string) (dnsSec *teo.DescribeDnssecResponseParams,
761683
errRet error) {
762684
var (
@@ -996,7 +918,7 @@ func (me *TeoService) DescribeTeoBotManagedRulesByFilter(ctx context.Context,
996918
ratelimit.Check(request.GetAction())
997919

998920
var offset int64 = 0
999-
var pageSize int64 = 9999999
921+
var pageSize int64 = 100
1000922

1001923
for {
1002924
request.Offset = &offset
@@ -1167,7 +1089,7 @@ func (me *TeoService) DescribeTeoWafRuleGroupsByFilter(ctx context.Context,
11671089
ratelimit.Check(request.GetAction())
11681090

11691091
var offset int64 = 0
1170-
var pageSize int64 = 9999999
1092+
var pageSize int64 = 100
11711093

11721094
for {
11731095
request.Offset = &offset

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)