From af2c9a4996180b341a38e69b2eb20efbc1759a54 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 19 Dec 2024 20:00:18 +0800 Subject: [PATCH 1/2] add --- tencentcloud/internal/helper/helper.go | 42 +++++++++++++++++++ .../clb/resource_tc_clb_listener_rule.go | 4 +- .../services/clb/service_tencentcloud_clb.go | 10 +---- .../docs/r/clb_listener_rule.html.markdown | 2 +- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/tencentcloud/internal/helper/helper.go b/tencentcloud/internal/helper/helper.go index 9d09a1e17a..b89a73a6e0 100644 --- a/tencentcloud/internal/helper/helper.go +++ b/tencentcloud/internal/helper/helper.go @@ -297,3 +297,45 @@ func CheckElementsExist(slice1 []string, slice2 []string) (bool, []string) { } return exist, diff } + +func StringSlicesEqual(slice1, slice2 []string) bool { + if len(slice1) != len(slice2) { + return false + } + + count := make(map[string]int) + + for _, value := range slice1 { + count[value]++ + } + + for _, value := range slice2 { + count[value]-- + if count[value] < 0 { + return false + } + } + + return true +} + +func StringPtrSlicesEqual(slice1, slice2 []*string) bool { + if len(slice1) != len(slice2) { + return false + } + + count := make(map[string]int) + + for _, value := range slice1 { + count[*value]++ + } + + for _, value := range slice2 { + count[*value]-- + if count[*value] < 0 { + return false + } + } + + return true +} diff --git a/tencentcloud/services/clb/resource_tc_clb_listener_rule.go b/tencentcloud/services/clb/resource_tc_clb_listener_rule.go index 38511a87f0..919159da63 100644 --- a/tencentcloud/services/clb/resource_tc_clb_listener_rule.go +++ b/tencentcloud/services/clb/resource_tc_clb_listener_rule.go @@ -47,7 +47,7 @@ func ResourceTencentCloudClbListenerRule() *schema.Resource { Description: "Domain name of the listener rule. Single domain rules are passed to `domain`, and multi domain rules are passed to `domains`.", }, "domains": { - Type: schema.TypeList, + Type: schema.TypeSet, Optional: true, Computed: true, ForceNew: true, @@ -272,7 +272,7 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte } if v, ok := d.GetOk("domains"); ok { - tmpDomains := v.([]interface{}) + tmpDomains := v.(*schema.Set).List() domains = make([]*string, 0, len(tmpDomains)) for _, value := range tmpDomains { tmpDomain := value.(string) diff --git a/tencentcloud/services/clb/service_tencentcloud_clb.go b/tencentcloud/services/clb/service_tencentcloud_clb.go index 01448533b1..65d3998f5a 100644 --- a/tencentcloud/services/clb/service_tencentcloud_clb.go +++ b/tencentcloud/services/clb/service_tencentcloud_clb.go @@ -375,15 +375,7 @@ func (me *ClbService) DescribeRuleByPara(ctx context.Context, clbId string, list findFlag = true break } else if len(domains) > 0 { - tmpRef := true - for i := range domains { - if *domains[i] != *rule.Domains[i] { - tmpRef = false - break - } - } - - if tmpRef { + if helper.StringPtrSlicesEqual(domains, rule.Domains) { ruleOutput = *rule findFlag = true break diff --git a/website/docs/r/clb_listener_rule.html.markdown b/website/docs/r/clb_listener_rule.html.markdown index c78e9d2592..cb0579cfbd 100644 --- a/website/docs/r/clb_listener_rule.html.markdown +++ b/website/docs/r/clb_listener_rule.html.markdown @@ -70,7 +70,7 @@ The following arguments are supported: * `certificate_id` - (Optional, String) ID of the server certificate. NOTES: Only supports listeners of HTTPS protocol. * `certificate_ssl_mode` - (Optional, String, ForceNew) Type of certificate. Valid values: `UNIDIRECTIONAL`, `MUTUAL`. NOTES: Only supports listeners of HTTPS protocol. * `domain` - (Optional, String) Domain name of the listener rule. Single domain rules are passed to `domain`, and multi domain rules are passed to `domains`. -* `domains` - (Optional, List: [`String`], ForceNew) Domain name list of the listener rule. Single domain rules are passed to `domain`, and multi domain rules are passed to `domains`. +* `domains` - (Optional, Set: [`String`], ForceNew) Domain name list of the listener rule. Single domain rules are passed to `domain`, and multi domain rules are passed to `domains`. * `forward_type` - (Optional, String) Forwarding protocol between the CLB instance and real server. Valid values: `HTTP`, `HTTPS`, `GRPC`, `GRPCS`, `TRPC`. The default is `HTTP`. * `health_check_health_num` - (Optional, Int) 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, Int) HTTP Status Code. The default is 31. Valid value ranges: [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. From 6d9f11cae913a24484f056fe920964573ac397cd Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 19 Dec 2024 20:02:25 +0800 Subject: [PATCH 2/2] add --- .changelog/3028.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/3028.txt diff --git a/.changelog/3028.txt b/.changelog/3028.txt new file mode 100644 index 0000000000..6ea9a690a2 --- /dev/null +++ b/.changelog/3028.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_clb_listener_rule: fix error with `domains` +``` \ No newline at end of file