@@ -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
0 commit comments