@@ -409,6 +409,55 @@ func ResourceFgsFunctionV2() *schema.Resource {
409
409
Optional : true ,
410
410
Description : "schema: Internal; Specifies the maximum duration that the function can be initialized." ,
411
411
},
412
+ "func_vpc" : {
413
+ Type : schema .TypeList ,
414
+ Optional : true ,
415
+ Elem : & schema.Resource {
416
+ Schema : map [string ]* schema.Schema {
417
+ "cidr" : {
418
+ Type : schema .TypeString ,
419
+ Optional : true ,
420
+ },
421
+ "gateway" : {
422
+ Type : schema .TypeString ,
423
+ Optional : true ,
424
+ },
425
+ "security_groups" : {
426
+ Type : schema .TypeList ,
427
+ Optional : true ,
428
+ Elem : & schema.Schema {Type : schema .TypeString },
429
+ },
430
+ },
431
+ },
432
+ },
433
+ "network_controller" : {
434
+ Type : schema .TypeList ,
435
+ Optional : true ,
436
+ Elem : & schema.Resource {
437
+ Schema : map [string ]* schema.Schema {
438
+ "disable_public_network" : {
439
+ Type : schema .TypeBool ,
440
+ Optional : true ,
441
+ },
442
+ "trigger_access_vpcs" : {
443
+ Type : schema .TypeList ,
444
+ Optional : true ,
445
+ Elem : & schema.Resource {
446
+ Schema : map [string ]* schema.Schema {
447
+ "vpc_id" : {
448
+ Type : schema .TypeString ,
449
+ Optional : true ,
450
+ },
451
+ "vpc_name" : {
452
+ Type : schema .TypeString ,
453
+ Optional : true ,
454
+ },
455
+ },
456
+ },
457
+ },
458
+ },
459
+ },
460
+ },
412
461
"version" : {
413
462
Type : schema .TypeString ,
414
463
Computed : true ,
@@ -497,6 +546,46 @@ func buildCustomImage(imageConfig []interface{}) *function.CustomImage {
497
546
}
498
547
}
499
548
549
+ func buildFuncVpc (funcVpcConfig []interface {}) * function.FuncVpc {
550
+ if len (funcVpcConfig ) < 1 {
551
+ return nil
552
+ }
553
+
554
+ cfg := funcVpcConfig [0 ].(map [string ]interface {})
555
+ return & function.FuncVpc {
556
+ Cidr : cfg ["cidr" ].(string ),
557
+ Gateway : cfg ["gateway" ].(string ),
558
+ SecurityGroups : utils .ExpandToStringList (cfg ["security_groups" ].([]interface {})),
559
+ }
560
+ }
561
+
562
+ func buildNetworkController (networkControllerConfig []interface {}) * function.NetworkControlConfig {
563
+ if len (networkControllerConfig ) < 1 {
564
+ return nil
565
+ }
566
+
567
+ cfg := networkControllerConfig [0 ].(map [string ]interface {})
568
+ return & function.NetworkControlConfig {
569
+ DisablePublicNetwork : cfg ["disable_public_network" ].(bool ),
570
+ TriggerAccessVpcs : buildTriggerAccessVpcs (cfg ["trigger_access_vpcs" ].([]interface {})),
571
+ }
572
+ }
573
+
574
+ func buildTriggerAccessVpcs (vpcConfig []interface {}) []function.VpcConfig {
575
+ if len (vpcConfig ) < 1 {
576
+ return nil
577
+ }
578
+ result := make ([]function.VpcConfig , len (vpcConfig ))
579
+ for i , val := range vpcConfig {
580
+ cfg := val .(map [string ]interface {})
581
+ result [i ] = function.VpcConfig {
582
+ VpcId : cfg ["vpc_id" ].(string ),
583
+ VpcName : cfg ["vpc_name" ].(string ),
584
+ }
585
+ }
586
+ return result
587
+ }
588
+
500
589
func buildFgsFunctionParameters (d * schema.ResourceData , cfg * config.Config ) (function.CreateOpts , error ) {
501
590
// check app and package
502
591
app , appOk := d .GetOk ("app" )
@@ -539,6 +628,8 @@ func buildFgsFunctionParameters(d *schema.ResourceData, cfg *config.Config) (fun
539
628
GPUType : d .Get ("gpu_type" ).(string ),
540
629
PreStopHandler : d .Get ("pre_stop_handler" ).(string ),
541
630
PreStopTimeout : d .Get ("pre_stop_timeout" ).(int ),
631
+ FuncVpc : buildFuncVpc (d .Get ("func_vpc" ).([]interface {})),
632
+ NetworkController : buildNetworkController (d .Get ("network_controller" ).([]interface {})),
542
633
}
543
634
if v , ok := d .GetOk ("func_code" ); ok {
544
635
funcCode := function.FunctionCodeOpts {
@@ -674,9 +765,45 @@ func setFgsFunctionAgency(d *schema.ResourceData, agency string) error {
674
765
}
675
766
676
767
func setFgsFunctionVpcAccess (d * schema.ResourceData , funcVpc function.FuncVpc ) error {
768
+ result := []map [string ]interface {}{
769
+ {
770
+ "cidr" : funcVpc .Cidr ,
771
+ "gateway" : funcVpc .Gateway ,
772
+ },
773
+ }
774
+
677
775
mErr := multierror .Append (
678
776
d .Set ("vpc_id" , funcVpc .VpcId ),
679
777
d .Set ("network_id" , funcVpc .SubnetId ),
778
+ d .Set ("func_vpc" , result ),
779
+ )
780
+ if err := mErr .ErrorOrNil (); err != nil {
781
+ return fmt .Errorf ("error setting vault fields: %s" , err )
782
+ }
783
+ return nil
784
+ }
785
+
786
+ func setTriggerAccessVpcs (vpcConfigs []function.VpcConfig ) interface {} {
787
+ result := make ([]map [string ]interface {}, len (vpcConfigs ))
788
+ for i , val := range vpcConfigs {
789
+ result [i ] = map [string ]interface {}{
790
+ "vpc_id" : val .VpcId ,
791
+ "vpc_name" : val .VpcName ,
792
+ }
793
+ }
794
+ return result
795
+ }
796
+
797
+ func setNetworkController (d * schema.ResourceData , networkController function.NetworkControlConfig ) error {
798
+ result := []map [string ]interface {}{
799
+ {
800
+ "disable_public_network" : networkController .DisablePublicNetwork ,
801
+ "trigger_access_vpcs" : setTriggerAccessVpcs (networkController .TriggerAccessVpcs ),
802
+ },
803
+ }
804
+
805
+ mErr := multierror .Append (
806
+ d .Set ("network_controller" , result ),
680
807
)
681
808
if err := mErr .ErrorOrNil (); err != nil {
682
809
return fmt .Errorf ("error setting vault fields: %s" , err )
@@ -901,6 +1028,7 @@ func resourceFgsFunctionRead(_ context.Context, d *schema.ResourceData, meta int
901
1028
d .Set ("gpu_type" , f .GPUType ),
902
1029
d .Set ("pre_stop_handler" , f .PreStopHandler ),
903
1030
d .Set ("pre_stop_timeout" , f .PreStopTimeout ),
1031
+ setNetworkController (d , f .NetworkController ),
904
1032
)
905
1033
906
1034
reservedInstances , err := getReservedInstanceConfig (fgsClient , d )
@@ -1267,6 +1395,8 @@ func resourceFgsFunctionMetadataUpdate(fgsClient *golangsdk.ServiceClient, urn s
1267
1395
GPUType : d .Get ("gpu_type" ).(string ),
1268
1396
PreStopHandler : d .Get ("pre_stop_handler" ).(string ),
1269
1397
PreStopTimeout : d .Get ("pre_stop_timeout" ).(int ),
1398
+ FuncVpc : buildFuncVpc (d .Get ("func_vpc" ).([]interface {})),
1399
+ NetworkController : buildNetworkController (d .Get ("network_controller" ).([]interface {})),
1270
1400
}
1271
1401
1272
1402
if _ , ok := d .GetOk ("vpc_id" ); ok {
0 commit comments