Skip to content

Commit ab302b1

Browse files
authored
Merge pull request #660 from tencentcloudstack/feature/scf-public-net-config
scf: enable public net config and eip config
2 parents c193ebf + a1d36e8 commit ab302b1

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

tencentcloud/data_source_tc_scf_functions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ func dataSourceTencentCloudScfFunctionsRead(d *schema.ResourceData, m interface{
349349
m["host"] = resp.AccessInfo.Host
350350
m["vip"] = resp.AccessInfo.Vip
351351
m["l5_enable"] = *resp.L5Enable == "TRUE"
352+
if resp.PublicNetConfig != nil {
353+
m["enable_public_net"] = *resp.PublicNetConfig.PublicNetStatus == "ENABLE"
354+
m["enable_eip_config"] = *resp.PublicNetConfig.EipConfig.EipStatus == "ENABLE"
355+
}
352356

353357
triggers := make([]map[string]interface{}, 0, len(resp.Triggers))
354358
for _, trigger := range resp.Triggers {

tencentcloud/resource_tc_scf_function.go

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,18 @@ 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+
Description: "Indicates whether EIP config set to `ENABLE` when `enable_public_net` was true.",
205+
},
194206
// cos code
195207
"cos_bucket_name": {
196208
Type: schema.TypeString,
@@ -433,6 +445,37 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{}
433445
functionInfo.cosBucketRegion = helper.String(raw.(string))
434446
}
435447

448+
enablePublicNet, enablePublicNetOk := d.GetOk("enable_public_net")
449+
enableEipConfig, enableEipConfigOk := d.GetOk("enable_eip_config")
450+
451+
if enablePublicNetOk {
452+
enable := enablePublicNet.(bool)
453+
publicNetStatus := helper.String("ENABLE")
454+
if !enable {
455+
publicNetStatus = helper.String("DISABLE")
456+
}
457+
functionInfo.publicNetConfig = &scf.PublicNetConfigIn{
458+
PublicNetStatus: publicNetStatus,
459+
EipConfig: &scf.EipConfigIn{
460+
EipStatus: helper.String("DISABLE"),
461+
},
462+
}
463+
}
464+
465+
if enableEipConfigOk {
466+
enableEip := enableEipConfig.(bool)
467+
eipStatus := "DISABLE"
468+
if enableEip {
469+
if !enablePublicNet.(bool) {
470+
return fmt.Errorf("cannot set enable_eip_config to true if enable_public_net was disable")
471+
}
472+
eipStatus = "ENABLE"
473+
}
474+
functionInfo.publicNetConfig.EipConfig = &scf.EipConfigIn{
475+
EipStatus: helper.String(eipStatus),
476+
}
477+
}
478+
436479
if raw, ok := d.GetOk("zip_file"); ok {
437480
path, err := homedir.Expand(raw.(string))
438481
if err != nil {
@@ -606,6 +649,10 @@ func resourceTencentCloudScfFunctionRead(d *schema.ResourceData, m interface{})
606649
_ = d.Set("eips", resp.EipConfig.Eips)
607650
_ = d.Set("host", resp.AccessInfo.Host)
608651
_ = d.Set("vip", resp.AccessInfo.Vip)
652+
if resp.PublicNetConfig != nil {
653+
_ = d.Set("enable_public_net", *resp.PublicNetConfig.PublicNetStatus == "ENABLE")
654+
_ = d.Set("enable_eip_config", *resp.PublicNetConfig.EipConfig.EipStatus == "ENABLE")
655+
}
609656

610657
triggers := make([]map[string]interface{}, 0, len(resp.Triggers))
611658
for _, trigger := range resp.Triggers {
@@ -806,6 +853,42 @@ func resourceTencentCloudScfFunctionUpdate(d *schema.ResourceData, m interface{}
806853
functionInfo.l5Enable = helper.Bool(d.Get("l5_enable").(bool))
807854
}
808855

856+
if d.HasChange("enable_public_net") {
857+
updateAttrs = append(updateAttrs, "enable_public_net")
858+
}
859+
860+
if d.HasChange("enable_eip_config") {
861+
updateAttrs = append(updateAttrs, "enable_eip_config")
862+
}
863+
864+
if raw, ok := d.GetOk("enable_public_net"); ok {
865+
enablePublicNet := raw.(bool)
866+
publicNetStatus := helper.String("ENABLE")
867+
if !enablePublicNet {
868+
publicNetStatus = helper.String("DISABLE")
869+
}
870+
functionInfo.publicNetConfig = &scf.PublicNetConfigIn{
871+
PublicNetStatus: publicNetStatus,
872+
EipConfig: &scf.EipConfigIn{
873+
EipStatus: helper.String("DISABLE"),
874+
},
875+
}
876+
}
877+
878+
if raw, ok := d.GetOk("enable_eip_config"); ok {
879+
status := "DISABLE"
880+
enablePublicNet := d.Get("enable_public_net").(bool)
881+
if raw.(bool) {
882+
if !enablePublicNet {
883+
return fmt.Errorf("cannot set enable_eip_config to true if enable_public_net was disable")
884+
}
885+
status = "ENABLE"
886+
}
887+
functionInfo.publicNetConfig.EipConfig = &scf.EipConfigIn{
888+
EipStatus: helper.String(status),
889+
}
890+
}
891+
809892
// update function configuration
810893
if len(updateAttrs) > 0 {
811894
if err := scfService.ModifyFunctionConfig(ctx, functionInfo); err != nil {

tencentcloud/service_tencentcloud_scf.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type scfFunctionInfo struct {
2828
clsTopicId *string
2929
namespace *string
3030
l5Enable *bool
31+
publicNetConfig *scf.PublicNetConfigIn
3132

3233
cosBucketName *string
3334
cosObjectName *string
@@ -54,6 +55,7 @@ func (me *ScfService) CreateFunction(ctx context.Context, info scfFunctionInfo)
5455
request.Handler = info.handler
5556
request.Description = info.desc
5657
request.MemorySize = helper.IntInt64(*info.memSize)
58+
request.PublicNetConfig = info.publicNetConfig
5759
request.Timeout = helper.IntInt64(*info.timeout)
5860
for k, v := range info.environment {
5961
if request.Environment == nil {
@@ -249,6 +251,9 @@ func (me *ScfService) ModifyFunctionConfig(ctx context.Context, info scfFunction
249251
}
250252
request.VpcConfig.SubnetId = info.subnetId
251253
}
254+
if info.publicNetConfig != nil {
255+
request.PublicNetConfig = info.publicNetConfig
256+
}
252257
request.Role = info.role
253258
request.ClsLogsetId = info.clsLogsetId
254259
request.ClsTopicId = info.clsTopicId

website/docs/r/scf_function.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The following arguments are supported:
3838
* `cos_bucket_region` - (Optional) Cos bucket region of the SCF function, conflict with `zip_file`.
3939
* `cos_object_name` - (Optional) Cos object name of the SCF function, should have suffix `.zip` or `.jar`, conflict with `zip_file`.
4040
* `description` - (Optional) Description of the SCF function. Description supports English letters, numbers, spaces, commas, newlines, periods and Chinese, the maximum length is 1000.
41+
* `enable_eip_config` - (Optional) Indicates whether EIP config set to `ENABLE` when `enable_public_net` was true.
42+
* `enable_public_net` - (Optional) Indicates whether public net config enabled.
4143
* `environment` - (Optional) Environment of the SCF function.
4244
* `l5_enable` - (Optional) Enable L5 for SCF function, default is `false`.
4345
* `mem_size` - (Optional) Memory size of the SCF function, unit is MB. The default is `128`MB. The range is 128M-1536M, and the ladder is 128M.

0 commit comments

Comments
 (0)