@@ -32,6 +32,7 @@ import (
3232 "encoding/base64"
3333 "encoding/json"
3434 "fmt"
35+ scf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
3536 "io/ioutil"
3637 "log"
3738 "os"
@@ -190,7 +191,19 @@ func resourceTencentCloudScfFunction() *schema.Resource {
190191 Optional : true ,
191192 Description : "Tags of the SCF function." ,
192193 },
193-
194+ "enable_public_net" : {
195+ Type : schema .TypeBool ,
196+ Optional : true ,
197+ Default : false ,
198+ Description : "Indicates whether public net config enabled." ,
199+ },
200+ "enable_eip_config" : {
201+ Type : schema .TypeBool ,
202+ Optional : true ,
203+ Default : false ,
204+ AtLeastOneOf : []string {"enable_public_net" },
205+ Description : "Indicates whether EIP config set to `ENABLE` when `enable_public_net` was true." ,
206+ },
194207 // cos code
195208 "cos_bucket_name" : {
196209 Type : schema .TypeString ,
@@ -433,6 +446,37 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{}
433446 functionInfo .cosBucketRegion = helper .String (raw .(string ))
434447 }
435448
449+ enablePublicNet , enablePublicNetOk := d .GetOk ("enable_public_net" )
450+ enableEipConfig , enableEipConfigOk := d .GetOk ("enable_eip_config" )
451+
452+ if enablePublicNetOk {
453+ enable := enablePublicNet .(bool )
454+ publicNetStatus := helper .String ("ENABLE" )
455+ if ! enable {
456+ publicNetStatus = helper .String ("DISABLE" )
457+ }
458+ functionInfo .publicNetConfig = & scf.PublicNetConfigIn {
459+ PublicNetStatus : publicNetStatus ,
460+ EipConfig : & scf.EipConfigIn {
461+ EipStatus : helper .String ("DISABLE" ),
462+ },
463+ }
464+ }
465+
466+ if enableEipConfigOk {
467+ enableEip := enableEipConfig .(bool )
468+ eipStatus := "DISABLE"
469+ if enableEip {
470+ if ! enablePublicNet .(bool ) {
471+ return fmt .Errorf ("cannot set enable_eip_config to true if enable_public_net was disable" )
472+ }
473+ eipStatus = "ENABLE"
474+ }
475+ functionInfo .publicNetConfig .EipConfig = & scf.EipConfigIn {
476+ EipStatus : helper .String (eipStatus ),
477+ }
478+ }
479+
436480 if raw , ok := d .GetOk ("zip_file" ); ok {
437481 path , err := homedir .Expand (raw .(string ))
438482 if err != nil {
@@ -606,6 +650,10 @@ func resourceTencentCloudScfFunctionRead(d *schema.ResourceData, m interface{})
606650 _ = d .Set ("eips" , resp .EipConfig .Eips )
607651 _ = d .Set ("host" , resp .AccessInfo .Host )
608652 _ = d .Set ("vip" , resp .AccessInfo .Vip )
653+ if resp .PublicNetConfig != nil {
654+ _ = d .Set ("enable_public_net" , * resp .PublicNetConfig .PublicNetStatus == "ENABLE" )
655+ _ = d .Set ("enable_eip_config" , * resp .PublicNetConfig .EipConfig .EipStatus == "ENABLE" )
656+ }
609657
610658 triggers := make ([]map [string ]interface {}, 0 , len (resp .Triggers ))
611659 for _ , trigger := range resp .Triggers {
@@ -806,6 +854,42 @@ func resourceTencentCloudScfFunctionUpdate(d *schema.ResourceData, m interface{}
806854 functionInfo .l5Enable = helper .Bool (d .Get ("l5_enable" ).(bool ))
807855 }
808856
857+ if d .HasChange ("enable_public_net" ) {
858+ updateAttrs = append (updateAttrs , "enable_public_net" )
859+ }
860+
861+ if d .HasChange ("enable_eip_config" ) {
862+ updateAttrs = append (updateAttrs , "enable_eip_config" )
863+ }
864+
865+ if raw , ok := d .GetOk ("enable_public_net" ); ok {
866+ enablePublicNet := raw .(bool )
867+ publicNetStatus := helper .String ("ENABLE" )
868+ if ! enablePublicNet {
869+ publicNetStatus = helper .String ("DISABLE" )
870+ }
871+ functionInfo .publicNetConfig = & scf.PublicNetConfigIn {
872+ PublicNetStatus : publicNetStatus ,
873+ EipConfig : & scf.EipConfigIn {
874+ EipStatus : helper .String ("DISABLE" ),
875+ },
876+ }
877+ }
878+
879+ if raw , ok := d .GetOk ("enable_eip_config" ); ok {
880+ status := "DISABLE"
881+ enablePublicNet := d .Get ("enable_public_net" ).(bool )
882+ if raw .(bool ) {
883+ if ! enablePublicNet {
884+ return fmt .Errorf ("cannot set enable_eip_config to true if enable_public_net was disable" )
885+ }
886+ status = "ENABLE"
887+ }
888+ functionInfo .publicNetConfig .EipConfig = & scf.EipConfigIn {
889+ EipStatus : helper .String (status ),
890+ }
891+ }
892+
809893 // update function configuration
810894 if len (updateAttrs ) > 0 {
811895 if err := scfService .ModifyFunctionConfig (ctx , functionInfo ); err != nil {
0 commit comments