Skip to content

Commit 520041a

Browse files
authored
Merge pull request #523 from ttomzhou/fix-clb
add backend protocols
2 parents d6b21d5 + b4291c1 commit 520041a

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
ENHANCEMENTS:
44

5+
* Resource: `tencentcloud_clb_listener_rule` add new argument `forward_type` to support backend protocol([#522](https://github.com/tencentcloudstack/terraform-provider-tencentcloud/issues/522))
56
* Resource: `tencentcloud_instance` add new argument `keep_image_login` to support keeping image login.
67

78
## 1.44.0 (September 25, 2020)

tencentcloud/resource_tc_clb_listener_rule.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ func resourceTencentCloudClbListenerRule() *schema.Resource {
158158
ValidateFunc: validateAllowedStringValue(CLB_LISTENER_SCHEDULER),
159159
Description: "Scheduling method of the CLB listener rules, and available values are 'WRR', 'IP HASH' and 'LEAST_CONN'. The default is 'WRR'. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in tencentcloud_clb_listener_rule.",
160160
},
161+
"forward_type": {
162+
Type: schema.TypeString,
163+
Optional: true,
164+
Computed: true,
165+
ValidateFunc: validateAllowedStringValue([]string{"HTTP", "HTTPS", "TRPC"}),
166+
Description: "Forwarding protocol between the CLB instance and real server. Currently, HTTP/HTTPS/TRPC are supported.",
167+
},
161168
},
162169
}
163170
}
@@ -204,6 +211,9 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte
204211
rule.Domain = helper.String(domain)
205212
url := d.Get("url").(string)
206213
rule.Url = helper.String(url)
214+
if v, ok := d.GetOk("forward_type"); ok {
215+
rule.ForwardType = helper.String(v.(string))
216+
}
207217
scheduler := ""
208218
if v, ok := d.GetOk("scheduler"); ok {
209219
if !(protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS) {
@@ -326,6 +336,7 @@ func resourceTencentCloudClbListenerRuleRead(d *schema.ResourceData, meta interf
326336
_ = d.Set("url", instance.Url)
327337
_ = d.Set("scheduler", instance.Scheduler)
328338
_ = d.Set("session_expire_time", instance.SessionExpireTime)
339+
_ = d.Set("forward_type", instance.ForwardType)
329340

330341
//health check
331342
if instance.HealthCheck != nil {
@@ -397,6 +408,11 @@ func resourceTencentCloudClbListenerRuleUpdate(d *schema.ResourceData, meta inte
397408
request.Url = helper.String(url)
398409
}
399410

411+
if d.HasChange("forward_type") {
412+
changed = true
413+
request.ForwardType = helper.String(d.Get("forward_type").(string))
414+
}
415+
400416
if d.HasChange("scheduler") {
401417
changed = true
402418
scheduler = d.Get("scheduler").(string)
@@ -417,7 +433,6 @@ func resourceTencentCloudClbListenerRuleUpdate(d *schema.ResourceData, meta inte
417433
}
418434
sessionExpireTime64 := int64(sessionExpireTime)
419435
request.SessionExpireTime = &sessionExpireTime64
420-
421436
}
422437

423438
healthSetFlag, healthCheck, healthErr := checkHealthCheckPara(ctx, d, protocol, HEALTH_APPLY_TYPE_RULE)

tencentcloud/resource_tc_clb_listener_rule_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ func TestAccTencentCloudClbListenerRule_basic(t *testing.T) {
2727
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "session_expire_time", "30"),
2828
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "url", "/"),
2929
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "scheduler", "WRR"),
30+
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "forward_type", "HTTPS"),
31+
),
32+
},
33+
{
34+
Config: testAccClbListenerRule__basic_update,
35+
Check: resource.ComposeTestCheckFunc(
36+
testAccCheckClbListenerRuleExists("tencentcloud_clb_listener_rule.rule_basic"),
37+
resource.TestCheckResourceAttrSet("tencentcloud_clb_listener_rule.rule_basic", "clb_id"),
38+
resource.TestCheckResourceAttrSet("tencentcloud_clb_listener_rule.rule_basic", "listener_id"),
39+
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "domain", "abc.com"),
40+
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "session_expire_time", "30"),
41+
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "url", "/"),
42+
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "scheduler", "WRR"),
43+
resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "forward_type", "HTTP"),
3044
),
3145
},
3246
},
@@ -162,6 +176,31 @@ resource "tencentcloud_clb_listener_rule" "rule_basic" {
162176
url = "/"
163177
session_expire_time = 30
164178
scheduler = "WRR"
179+
forward_type = "HTTPS"
180+
}
181+
`
182+
183+
const testAccClbListenerRule__basic_update = `
184+
resource "tencentcloud_clb_instance" "clb_basic" {
185+
network_type = "OPEN"
186+
clb_name = "tf-clb-rule-basic"
187+
}
188+
189+
resource "tencentcloud_clb_listener" "listener_basic" {
190+
clb_id = tencentcloud_clb_instance.clb_basic.id
191+
port = 1
192+
protocol = "HTTP"
193+
listener_name = "listener_basic"
194+
}
195+
196+
resource "tencentcloud_clb_listener_rule" "rule_basic" {
197+
clb_id = tencentcloud_clb_instance.clb_basic.id
198+
listener_id = tencentcloud_clb_listener.listener_basic.id
199+
domain = "abc.com"
200+
url = "/"
201+
session_expire_time = 30
202+
scheduler = "WRR"
203+
forward_type = "HTTP"
165204
}
166205
`
167206

website/docs/r/clb_listener_rule.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The following arguments are supported:
4848
* `certificate_ca_id` - (Optional, ForceNew) Id of the client certificate. NOTES: Only supports listeners of 'HTTPS' protocol.
4949
* `certificate_id` - (Optional, ForceNew) Id of the server certificate. NOTES: Only supports listeners of 'HTTPS' protocol.
5050
* `certificate_ssl_mode` - (Optional, ForceNew) Type of certificate, and available values inclue 'UNIDIRECTIONAL', 'MUTUAL'. NOTES: Only supports listeners of 'HTTPS' protocol.
51+
* `forward_type` - (Optional) Forwarding protocol between the CLB instance and real server. Currently, HTTP/HTTPS/TRPC are supported.
5152
* `health_check_health_num` - (Optional) Health threshold of health check, and the default is 3. If a success result is returned for the health check 3 consecutive times, indicates that the forwarding is normal. The value range is 2-10. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in tencentcloud_clb_listener_rule.
5253
* `health_check_http_code` - (Optional) HTTP Status Code. The default is 31 and value range is 1-31. 1 means the return value '1xx' is health. 2 means the return value '2xx' is health. 4 means the return value '3xx' is health. 8 means the return value '4xx' is health. 16 means the return value '5xx' is health. If you want multiple return codes to indicate health, need to add the corresponding values. NOTES: The 'HTTP' health check of the 'TCP' listener only supports specifying one health check status code. NOTES: Only supports listeners of 'HTTP' and 'HTTPS' protocol.
5354
* `health_check_http_domain` - (Optional) Domain name of health check. NOTES: Only supports listeners of 'HTTP' and 'HTTPS' protocol.

0 commit comments

Comments
 (0)