From 93a03f2b628dc29a1ec991cf72d3711f1b8911b5 Mon Sep 17 00:00:00 2001 From: ttomzhou Date: Mon, 28 Sep 2020 16:18:31 +0800 Subject: [PATCH] add backend protocols --- CHANGELOG.md | 5 +++ tencentcloud/resource_tc_clb_listener_rule.go | 17 +++++++- .../resource_tc_clb_listener_rule_test.go | 39 +++++++++++++++++++ .../docs/r/clb_listener_rule.html.markdown | 1 + 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 860bc85312..fa91e3195f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ ## 1.44.1 (Unreleased) + +ENHANCEMENTS: + +* Resource: `tencentcloud_clb_listener_rule` add new argument `forward_type` to support backend protocol([#522](https://github.com/tencentcloudstack/terraform-provider-tencentcloud/issues/522)) + ## 1.44.0 (September 25, 2020) FEATURES: diff --git a/tencentcloud/resource_tc_clb_listener_rule.go b/tencentcloud/resource_tc_clb_listener_rule.go index 84ad5240a4..16bfbc38b7 100644 --- a/tencentcloud/resource_tc_clb_listener_rule.go +++ b/tencentcloud/resource_tc_clb_listener_rule.go @@ -158,6 +158,13 @@ func resourceTencentCloudClbListenerRule() *schema.Resource { ValidateFunc: validateAllowedStringValue(CLB_LISTENER_SCHEDULER), 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.", }, + "forward_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validateAllowedStringValue([]string{"HTTP", "HTTPS", "TRPC"}), + Description: "Forwarding protocol between the CLB instance and real server. Currently, HTTP/HTTPS/TRPC are supported.", + }, }, } } @@ -204,6 +211,9 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte rule.Domain = helper.String(domain) url := d.Get("url").(string) rule.Url = helper.String(url) + if v, ok := d.GetOk("forward_type"); ok { + rule.ForwardType = helper.String(v.(string)) + } scheduler := "" if v, ok := d.GetOk("scheduler"); ok { if !(protocol == CLB_LISTENER_PROTOCOL_HTTP || protocol == CLB_LISTENER_PROTOCOL_HTTPS) { @@ -326,6 +336,7 @@ func resourceTencentCloudClbListenerRuleRead(d *schema.ResourceData, meta interf _ = d.Set("url", instance.Url) _ = d.Set("scheduler", instance.Scheduler) _ = d.Set("session_expire_time", instance.SessionExpireTime) + _ = d.Set("forward_type", instance.ForwardType) //health check if instance.HealthCheck != nil { @@ -397,6 +408,11 @@ func resourceTencentCloudClbListenerRuleUpdate(d *schema.ResourceData, meta inte request.Url = helper.String(url) } + if d.HasChange("forward_type") { + changed = true + request.ForwardType = helper.String(d.Get("forward_type").(string)) + } + if d.HasChange("scheduler") { changed = true scheduler = d.Get("scheduler").(string) @@ -417,7 +433,6 @@ func resourceTencentCloudClbListenerRuleUpdate(d *schema.ResourceData, meta inte } sessionExpireTime64 := int64(sessionExpireTime) request.SessionExpireTime = &sessionExpireTime64 - } healthSetFlag, healthCheck, healthErr := checkHealthCheckPara(ctx, d, protocol, HEALTH_APPLY_TYPE_RULE) diff --git a/tencentcloud/resource_tc_clb_listener_rule_test.go b/tencentcloud/resource_tc_clb_listener_rule_test.go index bcd451d887..3eba43ea10 100644 --- a/tencentcloud/resource_tc_clb_listener_rule_test.go +++ b/tencentcloud/resource_tc_clb_listener_rule_test.go @@ -27,6 +27,20 @@ func TestAccTencentCloudClbListenerRule_basic(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "session_expire_time", "30"), resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "url", "/"), resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "scheduler", "WRR"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "forward_type", "HTTPS"), + ), + }, + { + Config: testAccClbListenerRule__basic_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckClbListenerRuleExists("tencentcloud_clb_listener_rule.rule_basic"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_listener_rule.rule_basic", "clb_id"), + resource.TestCheckResourceAttrSet("tencentcloud_clb_listener_rule.rule_basic", "listener_id"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "domain", "abc.com"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "session_expire_time", "30"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "url", "/"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "scheduler", "WRR"), + resource.TestCheckResourceAttr("tencentcloud_clb_listener_rule.rule_basic", "forward_type", "HTTP"), ), }, }, @@ -162,6 +176,31 @@ resource "tencentcloud_clb_listener_rule" "rule_basic" { url = "/" session_expire_time = 30 scheduler = "WRR" + forward_type = "HTTPS" +} +` + +const testAccClbListenerRule__basic_update = ` +resource "tencentcloud_clb_instance" "clb_basic" { + network_type = "OPEN" + clb_name = "tf-clb-rule-basic" +} + +resource "tencentcloud_clb_listener" "listener_basic" { + clb_id = tencentcloud_clb_instance.clb_basic.id + port = 1 + protocol = "HTTP" + listener_name = "listener_basic" +} + +resource "tencentcloud_clb_listener_rule" "rule_basic" { + clb_id = tencentcloud_clb_instance.clb_basic.id + listener_id = tencentcloud_clb_listener.listener_basic.id + domain = "abc.com" + url = "/" + session_expire_time = 30 + scheduler = "WRR" + forward_type = "HTTP" } ` diff --git a/website/docs/r/clb_listener_rule.html.markdown b/website/docs/r/clb_listener_rule.html.markdown index 49dbd0ecb3..57c594d5d8 100644 --- a/website/docs/r/clb_listener_rule.html.markdown +++ b/website/docs/r/clb_listener_rule.html.markdown @@ -48,6 +48,7 @@ The following arguments are supported: * `certificate_ca_id` - (Optional, ForceNew) Id of the client certificate. NOTES: Only supports listeners of 'HTTPS' protocol. * `certificate_id` - (Optional, ForceNew) Id of the server certificate. NOTES: Only supports listeners of 'HTTPS' protocol. * `certificate_ssl_mode` - (Optional, ForceNew) Type of certificate, and available values inclue 'UNIDIRECTIONAL', 'MUTUAL'. NOTES: Only supports listeners of 'HTTPS' protocol. +* `forward_type` - (Optional) Forwarding protocol between the CLB instance and real server. Currently, HTTP/HTTPS/TRPC are supported. * `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. * `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. * `health_check_http_domain` - (Optional) Domain name of health check. NOTES: Only supports listeners of 'HTTP' and 'HTTPS' protocol.