Skip to content

Commit 685e024

Browse files
authored
fix(clb): [123123123]tencentcloud_clb_listener_rule support multi_cert_info (#3082)
* add * add * add
1 parent 9c647ab commit 685e024

File tree

5 files changed

+118
-16
lines changed

5 files changed

+118
-16
lines changed

.changelog/3082.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_clb_listener_rule: support `multi_cert_info`
3+
```

tencentcloud/services/clb/resource_tc_clb_listener.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ func resourceTencentCloudClbListenerCreate(d *schema.ResourceData, meta interfac
383383
if vv {
384384
vvv = 1
385385
} else {
386-
if !certificateSetFlag {
386+
if !certificateSetFlag && !multiCertificateSetFlag {
387387
return fmt.Errorf("[CHECK][CLB listener][Create] check: certificated need to be set when protocol is HTTPS")
388388
}
389389
}

tencentcloud/services/clb/resource_tc_clb_listener_rule.go

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,48 @@ func ResourceTencentCloudClbListenerRule() *schema.Resource {
134134
Description: "Methods of health check. NOTES: Only supports listeners of `HTTP` and `HTTPS` protocol. The default is `HEAD`, the available value are `HEAD` and `GET`.",
135135
},
136136
"certificate_ssl_mode": {
137-
Type: schema.TypeString,
138-
Optional: true,
139-
ForceNew: true,
140-
ValidateFunc: tccommon.ValidateAllowedStringValue(CERT_SSL_MODE),
141-
Description: "Type of certificate. Valid values: `UNIDIRECTIONAL`, `MUTUAL`. NOTES: Only supports listeners of HTTPS protocol.",
137+
Type: schema.TypeString,
138+
Optional: true,
139+
ForceNew: true,
140+
ConflictsWith: []string{"multi_cert_info"},
141+
ValidateFunc: tccommon.ValidateAllowedStringValue(CERT_SSL_MODE),
142+
Description: "Type of certificate. Valid values: `UNIDIRECTIONAL`, `MUTUAL`. NOTES: Only supports listeners of HTTPS protocol.",
142143
},
143144
"certificate_id": {
144-
Type: schema.TypeString,
145-
Optional: true,
146-
Description: "ID of the server certificate. NOTES: Only supports listeners of HTTPS protocol.",
145+
Type: schema.TypeString,
146+
Optional: true,
147+
ConflictsWith: []string{"multi_cert_info"},
148+
Description: "ID of the server certificate. NOTES: Only supports listeners of HTTPS protocol.",
147149
},
148150
"certificate_ca_id": {
149-
Type: schema.TypeString,
150-
Optional: true,
151-
Description: "ID of the client certificate. NOTES: Only supports listeners of HTTPS protocol.",
151+
Type: schema.TypeString,
152+
Optional: true,
153+
ConflictsWith: []string{"multi_cert_info"},
154+
Description: "ID of the client certificate. NOTES: Only supports listeners of HTTPS protocol.",
155+
},
156+
"multi_cert_info": {
157+
Type: schema.TypeList,
158+
Optional: true,
159+
MaxItems: 1,
160+
ConflictsWith: []string{"certificate_ssl_mode", "certificate_id", "certificate_ca_id"},
161+
Description: "Certificate information. You can specify multiple server-side certificates with different algorithm types. This parameter is only applicable to HTTPS listeners with the SNI feature not enabled. Certificate and MultiCertInfo cannot be specified at the same time.",
162+
Elem: &schema.Resource{
163+
Schema: map[string]*schema.Schema{
164+
"ssl_mode": {
165+
Type: schema.TypeString,
166+
Required: true,
167+
ForceNew: true,
168+
ValidateFunc: tccommon.ValidateAllowedStringValue(CERT_SSL_MODE),
169+
Description: "Authentication type. Values: UNIDIRECTIONAL (one-way authentication), MUTUAL (two-way authentication).",
170+
},
171+
"cert_id_list": {
172+
Type: schema.TypeSet,
173+
Required: true,
174+
Description: "List of server certificate ID.",
175+
Elem: &schema.Schema{Type: schema.TypeString},
176+
},
177+
},
178+
},
152179
},
153180
"session_expire_time": {
154181
Type: schema.TypeInt,
@@ -332,6 +359,19 @@ func resourceTencentCloudClbListenerRuleCreate(d *schema.ResourceData, meta inte
332359
rule.Certificate = certificateInput
333360
}
334361

362+
multiCertificateSetFlag, multiCertInput, certErr := checkMultiCertificateInputPara(ctx, d, meta)
363+
if certErr != nil {
364+
return certErr
365+
}
366+
367+
if multiCertificateSetFlag {
368+
rule.MultiCertInfo = multiCertInput
369+
} else {
370+
if protocol == CLB_LISTENER_PROTOCOL_TCPSSL {
371+
return fmt.Errorf("[CHECK][CLB listener][Create] check: certificated need to be set when protocol is HTTPS")
372+
}
373+
}
374+
335375
if v, ok := d.GetOkExists("quic"); ok {
336376
rule.Quic = helper.Bool(v.(bool))
337377
}
@@ -576,12 +616,35 @@ func resourceTencentCloudClbListenerRuleRead(d *schema.ResourceData, meta interf
576616
}
577617

578618
if instance.Certificate != nil {
579-
_ = d.Set("certificate_ssl_mode", instance.Certificate.SSLMode)
580-
_ = d.Set("certificate_id", instance.Certificate.CertId)
581-
if instance.Certificate.CertCaId != nil {
582-
_ = d.Set("certificate_ca_id", instance.Certificate.CertCaId)
619+
// check single cert or multi cert
620+
if instance.Certificate.ExtCertIds != nil && len(instance.Certificate.ExtCertIds) > 0 {
621+
multiCertInfo := make([]map[string]interface{}, 0, 1)
622+
multiCert := make(map[string]interface{}, 0)
623+
certIds := make([]string, 0)
624+
if instance.Certificate.SSLMode != nil {
625+
multiCert["ssl_mode"] = *instance.Certificate.SSLMode
626+
}
627+
628+
if instance.Certificate.CertId != nil {
629+
certIds = append(certIds, *instance.Certificate.CertId)
630+
}
631+
632+
for _, item := range instance.Certificate.ExtCertIds {
633+
certIds = append(certIds, *item)
634+
}
635+
636+
multiCert["cert_id_list"] = certIds
637+
multiCertInfo = append(multiCertInfo, multiCert)
638+
_ = d.Set("multi_cert_info", multiCertInfo)
639+
} else {
640+
_ = d.Set("certificate_ssl_mode", instance.Certificate.SSLMode)
641+
_ = d.Set("certificate_id", instance.Certificate.CertId)
642+
if instance.Certificate.CertCaId != nil {
643+
_ = d.Set("certificate_ca_id", instance.Certificate.CertCaId)
644+
}
583645
}
584646
}
647+
585648
if instance.OAuth != nil {
586649
oath := make(map[string]interface{})
587650
if instance.OAuth.OAuthEnable != nil {
@@ -767,6 +830,22 @@ func resourceTencentCloudClbListenerRuleUpdate(d *schema.ResourceData, meta inte
767830
}
768831
}
769832

833+
if d.HasChange("multi_cert_info") {
834+
domainChanged = true
835+
multiCertificateSetFlag, multiCertInput, certErr := checkMultiCertificateInputPara(ctx, d, meta)
836+
if certErr != nil {
837+
return certErr
838+
}
839+
840+
if multiCertificateSetFlag {
841+
domainRequest.MultiCertInfo = multiCertInput
842+
} else {
843+
if protocol == CLB_LISTENER_PROTOCOL_TCPSSL {
844+
return fmt.Errorf("[CHECK][CLB listener][Create] check: certificated need to be set when protocol is HTTPS")
845+
}
846+
}
847+
}
848+
770849
if d.HasChange("http2_switch") {
771850
if v, ok := d.GetOkExists("http2_switch"); ok {
772851
if !(protocol == CLB_LISTENER_PROTOCOL_HTTPS) {

tencentcloud/services/clb/resource_tc_clb_listener_rule.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ resource "tencentcloud_clb_listener_rule" "example" {
4848
health_check_http_domain = "check.com"
4949
health_check_http_method = "GET"
5050
scheduler = "WRR"
51+
multi_cert_info {
52+
ssl_mode = "UNIDIRECTIONAL"
53+
cert_id_list = [
54+
"LCYouprI",
55+
"JVO1alRN",
56+
]
57+
}
5158
}
5259
```
5360

website/docs/r/clb_listener_rule.html.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ resource "tencentcloud_clb_listener_rule" "example" {
5959
health_check_http_domain = "check.com"
6060
health_check_http_method = "GET"
6161
scheduler = "WRR"
62+
multi_cert_info {
63+
ssl_mode = "UNIDIRECTIONAL"
64+
cert_id_list = [
65+
"LCYouprI",
66+
"JVO1alRN",
67+
]
68+
}
6269
}
6370
```
6471

@@ -87,12 +94,18 @@ The following arguments are supported:
8794
* `health_check_type` - (Optional, String) Type of health check. Valid value is `CUSTOM`, `PING`, `TCP`, `HTTP`, `HTTPS`, `GRPC`, `GRPCS`.
8895
* `health_check_unhealth_num` - (Optional, Int) Unhealthy threshold of health check, and the default is `3`. If the unhealthy result is returned 3 consecutive times, indicates that the forwarding is abnormal. 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`.
8996
* `http2_switch` - (Optional, Bool) Indicate to apply HTTP2.0 protocol or not.
97+
* `multi_cert_info` - (Optional, List) Certificate information. You can specify multiple server-side certificates with different algorithm types. This parameter is only applicable to HTTPS listeners with the SNI feature not enabled. Certificate and MultiCertInfo cannot be specified at the same time.
9098
* `oauth` - (Optional, List) OAuth configuration information.
9199
* `quic` - (Optional, Bool) Whether to enable QUIC. Note: QUIC can be enabled only for HTTPS domain names.
92100
* `scheduler` - (Optional, String) Scheduling method of the CLB listener rules. Valid values: `WRR`, `IP HASH`, `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`.
93101
* `session_expire_time` - (Optional, Int) Time of session persistence within the CLB listener. NOTES: Available when scheduler is specified as `WRR`, and not available when listener protocol is `TCP_SSL`. NOTES: TCP/UDP/TCP_SSL listener allows direct configuration, HTTP/HTTPS listener needs to be configured in `tencentcloud_clb_listener_rule`.
94102
* `target_type` - (Optional, String, ForceNew) Backend target type. Valid values: `NODE`, `TARGETGROUP`. `NODE` means to bind ordinary nodes, `TARGETGROUP` means to bind target group.
95103

104+
The `multi_cert_info` object supports the following:
105+
106+
* `cert_id_list` - (Required, Set) List of server certificate ID.
107+
* `ssl_mode` - (Required, String, ForceNew) Authentication type. Values: UNIDIRECTIONAL (one-way authentication), MUTUAL (two-way authentication).
108+
96109
The `oauth` object supports the following:
97110

98111
* `oauth_enable` - (Optional, Bool) Enable or disable authentication. True: Enabled; False: Disabled.

0 commit comments

Comments
 (0)