@@ -32,6 +32,7 @@ import (
32
32
"encoding/base64"
33
33
"encoding/json"
34
34
"fmt"
35
+ scf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
35
36
"io/ioutil"
36
37
"log"
37
38
"os"
@@ -190,7 +191,19 @@ func resourceTencentCloudScfFunction() *schema.Resource {
190
191
Optional : true ,
191
192
Description : "Tags of the SCF function." ,
192
193
},
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
+ },
194
207
// cos code
195
208
"cos_bucket_name" : {
196
209
Type : schema .TypeString ,
@@ -433,6 +446,37 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{}
433
446
functionInfo .cosBucketRegion = helper .String (raw .(string ))
434
447
}
435
448
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
+
436
480
if raw , ok := d .GetOk ("zip_file" ); ok {
437
481
path , err := homedir .Expand (raw .(string ))
438
482
if err != nil {
@@ -606,6 +650,10 @@ func resourceTencentCloudScfFunctionRead(d *schema.ResourceData, m interface{})
606
650
_ = d .Set ("eips" , resp .EipConfig .Eips )
607
651
_ = d .Set ("host" , resp .AccessInfo .Host )
608
652
_ = 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
+ }
609
657
610
658
triggers := make ([]map [string ]interface {}, 0 , len (resp .Triggers ))
611
659
for _ , trigger := range resp .Triggers {
@@ -806,6 +854,42 @@ func resourceTencentCloudScfFunctionUpdate(d *schema.ResourceData, m interface{}
806
854
functionInfo .l5Enable = helper .Bool (d .Get ("l5_enable" ).(bool ))
807
855
}
808
856
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
+
809
893
// update function configuration
810
894
if len (updateAttrs ) > 0 {
811
895
if err := scfService .ModifyFunctionConfig (ctx , functionInfo ); err != nil {
0 commit comments