Skip to content

Commit 6f70708

Browse files
tongyimingmikatong
andauthored
fix: gaap http rule support sni (#1041)
* fix: gaap http rule support sni * fix: unit test * fix Co-authored-by: mikatong <[email protected]>
1 parent c961110 commit 6f70708

File tree

14 files changed

+3862
-109
lines changed

14 files changed

+3862
-109
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ require (
3131
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.283
3232
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.199
3333
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.377
34-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.392
34+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.397
3535
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.385
3636
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359
3737
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
3838
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.294
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.287
4141
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.383
42-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.199
42+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.397
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.199
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.199
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.329

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.389/go.mod
485485
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.391/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
486486
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.392 h1:UqcmPErxEm77NwqaRq6J1i2rcbhXcZHzq7WOuc9clAQ=
487487
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.392/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
488+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.397 h1:oYU+ghWYDEXSpU8aogzPYHiuZAI1291BMroSG0WKdAc=
489+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.397/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
488490
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.385 h1:8bwloRxRwSADSK48KxaUeO9JHmmgniNGJbA7Or/HUEk=
489491
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.385/go.mod h1:PMxA0L4o8Fbx/6+ju1cAMAU7x2bV4C6e/LTqVe745yM=
490492
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.359 h1:cNKqelPgUxrJkLY0Azd2QHr/UMYOPPnmqs88clt2akk=
@@ -501,6 +503,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.383 h1:OhKvreaR
501503
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/es v1.0.383/go.mod h1:WLskTV0GsorWBboZsLUWrgj+f1xGOKGzPGCK9275tdU=
502504
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.199 h1:tmjUPp0VBKuzjTqt0IQ5PT6iYt0yLmvM2DUzMFF7SGk=
503505
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.199/go.mod h1:tuPVv7O2B2fIpoDsrV/kvC62FO4CE4FihUxZY0JX2ek=
506+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.397 h1:i0GyUqV/dAJkvEO1foUBB4GG/KrwbseORspjLNdTcfo=
507+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap v1.0.397/go.mod h1:5XosT/WYkH2v6Q6L34hjJIeQXOymyoBWYcvlmxupjFo=
504508
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.194/go.mod h1:yrBKWhChnDqNz1xuXdSbWXG56XawEq0G5j1lg4VwBD4=
505509
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.199 h1:rSDQeqvV4khOJUyg6xmMYF26CRd+WtSYvfwP6N72NP0=
506510
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.199/go.mod h1:yrBKWhChnDqNz1xuXdSbWXG56XawEq0G5j1lg4VwBD4=

tencentcloud/data_source_tc_gaap_http_rules.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ func dataSourceTencentCloudGaapHttpRules() *schema.Resource {
161161
Computed: true,
162162
Description: "Requested host which is forwarded to the realserver by the listener.",
163163
},
164+
"sni_switch": {
165+
Type: schema.TypeString,
166+
Computed: true,
167+
Description: "ServerNameIndication (SNI) switch.",
168+
},
169+
"sni": {
170+
Type: schema.TypeString,
171+
Computed: true,
172+
Description: "ServerNameIndication (SNI).",
173+
},
164174
"realservers": {
165175
Type: schema.TypeList,
166176
Computed: true,
@@ -294,6 +304,8 @@ func dataSourceTencentCloudGaapHttpRulesRead(d *schema.ResourceData, m interface
294304
"health_check_path": *checkParams.Path,
295305
"health_check_method": *checkParams.Method,
296306
"forward_host": *rule.ForwardHost,
307+
"sni_switch": *rule.ServerNameIndicationSwitch,
308+
"sni": *rule.ServerNameIndication,
297309
}
298310
statusCodes := make([]int, 0, len(checkParams.StatusCode))
299311
for _, code := range checkParams.StatusCode {

tencentcloud/extension_gaap.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const (
3232

3333
GAAPInternalError = "InternalError"
3434
GAAPResourceNotFound = "ResourceNotFound"
35+
36+
GAAP_SERVER_NAME_INDICATION_SWITCH_ON = "ON"
37+
GAAP_SERVER_NAME_INDICATION_SWITCH_OFF = "OFF"
3538
)
3639

3740
var (

tencentcloud/resource_tc_gaap_http_rule.go

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ func resourceTencentCloudGaapHttpRule() *schema.Resource {
220220
Default: "default",
221221
Description: "The default value of requested host which is forwarded to the realserver by the listener is `default`.",
222222
},
223+
"sni_switch": {
224+
Type: schema.TypeString,
225+
Optional: true,
226+
Computed: true,
227+
ValidateFunc: validateAllowedStringValue([]string{GAAP_SERVER_NAME_INDICATION_SWITCH_ON, GAAP_SERVER_NAME_INDICATION_SWITCH_OFF}),
228+
Description: "ServerNameIndication (SNI) switch. ON means on and OFF means off.",
229+
},
230+
"sni": {
231+
Type: schema.TypeString,
232+
Optional: true,
233+
Computed: true,
234+
Description: "ServerNameIndication (SNI) is required when the SNI switch is turned on.",
235+
},
223236
},
224237
}
225238
}
@@ -235,17 +248,19 @@ func resourceTencentCloudGaapHttpRuleCreate(d *schema.ResourceData, m interface{
235248
listenerId := d.Get("listener_id").(string)
236249

237250
rule := gaapHttpRule{
238-
listenerId: listenerId,
239-
domain: d.Get("domain").(string),
240-
path: d.Get("path").(string),
241-
realserverType: d.Get("realserver_type").(string),
242-
scheduler: d.Get("scheduler").(string),
243-
healthCheck: d.Get("health_check").(bool),
244-
interval: d.Get("interval").(int),
245-
connectTimeout: d.Get("connect_timeout").(int),
246-
healthCheckPath: d.Get("health_check_path").(string),
247-
healthCheckMethod: d.Get("health_check_method").(string),
248-
forwardHost: d.Get("forward_host").(string),
251+
listenerId: listenerId,
252+
domain: d.Get("domain").(string),
253+
path: d.Get("path").(string),
254+
realserverType: d.Get("realserver_type").(string),
255+
scheduler: d.Get("scheduler").(string),
256+
healthCheck: d.Get("health_check").(bool),
257+
interval: d.Get("interval").(int),
258+
connectTimeout: d.Get("connect_timeout").(int),
259+
healthCheckPath: d.Get("health_check_path").(string),
260+
healthCheckMethod: d.Get("health_check_method").(string),
261+
forwardHost: d.Get("forward_host").(string),
262+
serverNameIndicationSwitch: d.Get("sni_switch").(string),
263+
serverNameIndication: d.Get("sni").(string),
249264
}
250265

251266
if raw, ok := d.GetOk("health_check_status_codes"); ok {
@@ -271,6 +286,9 @@ func resourceTencentCloudGaapHttpRuleCreate(d *schema.ResourceData, m interface{
271286
return errors.New("health_check_status_codes can't be empty")
272287
}
273288

289+
if rule.serverNameIndicationSwitch == GAAP_SERVER_NAME_INDICATION_SWITCH_ON && rule.serverNameIndication == "" {
290+
return fmt.Errorf("ServerNameIndication (SNI) is required when the SNI switch is turned on.")
291+
}
274292
service := GaapService{client: m.(*TencentCloudClient).apiV3Conn}
275293

276294
id, err := service.CreateHttpRule(ctx, rule)
@@ -342,6 +360,8 @@ func resourceTencentCloudGaapHttpRuleRead(d *schema.ResourceData, m interface{})
342360
_ = d.Set("health_check_method", rule.CheckParams.Method)
343361
_ = d.Set("forward_host", rule.ForwardHost)
344362
_ = d.Set("health_check_status_codes", rule.CheckParams.StatusCode)
363+
_ = d.Set("sni_switch", rule.ServerNameIndicationSwitch)
364+
_ = d.Set("sni", rule.ServerNameIndication)
345365

346366
realserverSet := make([]map[string]interface{}, 0, len(rule.RealServerSet))
347367
for _, rs := range rule.RealServerSet {
@@ -373,7 +393,17 @@ func resourceTencentCloudGaapHttpRuleUpdate(d *schema.ResourceData, m interface{
373393
scheduler *string
374394
updateAttr []string
375395
)
376-
396+
if d.HasChange("sni_switch") {
397+
updateAttr = append(updateAttr, "sni_switch")
398+
}
399+
sniSwitch := d.Get("sni_switch").(string)
400+
if d.HasChange("sni") {
401+
updateAttr = append(updateAttr, "sni")
402+
}
403+
sni := d.Get("sni").(string)
404+
if sniSwitch == GAAP_SERVER_NAME_INDICATION_SWITCH_ON && sni == "" {
405+
return fmt.Errorf("ServerNameIndication (SNI) is required when the SNI switch is turned on.")
406+
}
377407
if d.HasChange("path") {
378408
updateAttr = append(updateAttr, "path")
379409
path = helper.String(d.Get("path").(string))
@@ -454,7 +484,7 @@ func resourceTencentCloudGaapHttpRuleUpdate(d *schema.ResourceData, m interface{
454484

455485
if err := service.ModifyHTTPRuleAttribute(
456486
ctx,
457-
listenerId, id, healthCheckPath, healthCheckMethod,
487+
listenerId, id, healthCheckPath, healthCheckMethod, sniSwitch, sni,
458488
path, scheduler, healthCheck, interval, connectTimeout, healthCheckStatusCodes,
459489
); err != nil {
460490
return err

tencentcloud/resource_tc_gaap_realserver_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"strconv"
88
"testing"
9+
"time"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1112
"github.com/hashicorp/terraform-plugin-sdk/terraform"
@@ -116,7 +117,8 @@ func TestAccTencentCloudGaapRealserver_updateTags(t *testing.T) {
116117
),
117118
},
118119
{
119-
Config: testAccGaapRealserverUpdateTags,
120+
PreConfig: func() { time.Sleep(time.Duration(time.Second * 5)) },
121+
Config: testAccGaapRealserverUpdateTags,
120122
Check: resource.ComposeTestCheckFunc(
121123
testAccCheckGaapRealserverExists("tencentcloud_gaap_realserver.foo", id),
122124
resource.TestCheckResourceAttr("tencentcloud_gaap_realserver.foo", "tags.test", "test"),

tencentcloud/service_tencentcloud_gaap.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@ type gaapRealserverBind struct {
2525
}
2626

2727
type gaapHttpRule struct {
28-
listenerId string
29-
domain string
30-
path string
31-
realserverType string
32-
scheduler string
33-
healthCheck bool
34-
interval int
35-
connectTimeout int
36-
healthCheckPath string
37-
healthCheckMethod string
38-
healthCheckStatusCodes []int
39-
forwardHost string
28+
listenerId string
29+
domain string
30+
path string
31+
realserverType string
32+
scheduler string
33+
healthCheck bool
34+
interval int
35+
connectTimeout int
36+
healthCheckPath string
37+
healthCheckMethod string
38+
healthCheckStatusCodes []int
39+
forwardHost string
40+
serverNameIndicationSwitch string
41+
serverNameIndication string
4042
}
4143

4244
type GaapService struct {
@@ -2669,6 +2671,12 @@ func (me *GaapService) CreateHttpRule(ctx context.Context, httpRule gaapHttpRule
26692671
}
26702672

26712673
request.ForwardHost = &httpRule.forwardHost
2674+
if httpRule.serverNameIndicationSwitch != "" {
2675+
request.ServerNameIndicationSwitch = &httpRule.serverNameIndicationSwitch
2676+
}
2677+
if httpRule.serverNameIndication != "" {
2678+
request.ServerNameIndication = &httpRule.serverNameIndication
2679+
}
26722680

26732681
if err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
26742682
ratelimit.Check(request.GetAction())
@@ -2778,7 +2786,7 @@ func (me *GaapService) DescribeHttpRule(ctx context.Context, id string) (rule *g
27782786

27792787
func (me *GaapService) ModifyHTTPRuleAttribute(
27802788
ctx context.Context,
2781-
listenerId, ruleId, healthCheckPath, healthCheckMethod string,
2789+
listenerId, ruleId, healthCheckPath, healthCheckMethod, sniSwitch, sni string,
27822790
path, scheduler *string,
27832791
healthCheck bool,
27842792
interval, connectTimeout int,
@@ -2792,6 +2800,8 @@ func (me *GaapService) ModifyHTTPRuleAttribute(
27922800
request.RuleId = &ruleId
27932801
request.Path = path
27942802
request.Scheduler = scheduler
2803+
request.ServerNameIndicationSwitch = &sniSwitch
2804+
request.ServerNameIndication = &sni
27952805

27962806
if healthCheck {
27972807
request.HealthCheck = helper.IntUint64(1)

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)