Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tencentcloud/data_source_tc_scf_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ func dataSourceTencentCloudScfFunctionsRead(d *schema.ResourceData, m interface{
m["host"] = resp.AccessInfo.Host
m["vip"] = resp.AccessInfo.Vip
m["l5_enable"] = *resp.L5Enable == "TRUE"
if resp.PublicNetConfig != nil {
m["enable_public_net"] = *resp.PublicNetConfig.PublicNetStatus == "ENABLE"
m["enable_eip_config"] = *resp.PublicNetConfig.EipConfig.EipStatus == "ENABLE"
}

triggers := make([]map[string]interface{}, 0, len(resp.Triggers))
for _, trigger := range resp.Triggers {
Expand Down
85 changes: 84 additions & 1 deletion tencentcloud/resource_tc_scf_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
scf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -190,7 +191,18 @@ func resourceTencentCloudScfFunction() *schema.Resource {
Optional: true,
Description: "Tags of the SCF function.",
},

"enable_public_net": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Indicates whether public net config enabled.",
},
"enable_eip_config": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Indicates whether EIP config set to `ENABLE` when `enable_public_net` was true.",
},
// cos code
"cos_bucket_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -433,6 +445,37 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{}
functionInfo.cosBucketRegion = helper.String(raw.(string))
}

enablePublicNet, enablePublicNetOk := d.GetOk("enable_public_net")
enableEipConfig, enableEipConfigOk := d.GetOk("enable_eip_config")

if enablePublicNetOk {
enable := enablePublicNet.(bool)
publicNetStatus := helper.String("ENABLE")
if !enable {
publicNetStatus = helper.String("DISABLE")
}
functionInfo.publicNetConfig = &scf.PublicNetConfigIn{
PublicNetStatus: publicNetStatus,
EipConfig: &scf.EipConfigIn{
EipStatus: helper.String("DISABLE"),
},
}
}

if enableEipConfigOk {
enableEip := enableEipConfig.(bool)
eipStatus := "DISABLE"
if enableEip {
if !enablePublicNet.(bool) {
return fmt.Errorf("cannot set enable_eip_config to true if enable_public_net was disable")
}
eipStatus = "ENABLE"
}
functionInfo.publicNetConfig.EipConfig = &scf.EipConfigIn{
EipStatus: helper.String(eipStatus),
}
}

if raw, ok := d.GetOk("zip_file"); ok {
path, err := homedir.Expand(raw.(string))
if err != nil {
Expand Down Expand Up @@ -606,6 +649,10 @@ func resourceTencentCloudScfFunctionRead(d *schema.ResourceData, m interface{})
_ = d.Set("eips", resp.EipConfig.Eips)
_ = d.Set("host", resp.AccessInfo.Host)
_ = d.Set("vip", resp.AccessInfo.Vip)
if resp.PublicNetConfig != nil {
_ = d.Set("enable_public_net", *resp.PublicNetConfig.PublicNetStatus == "ENABLE")
_ = d.Set("enable_eip_config", *resp.PublicNetConfig.EipConfig.EipStatus == "ENABLE")
}

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

if d.HasChange("enable_public_net") {
updateAttrs = append(updateAttrs, "enable_public_net")
}

if d.HasChange("enable_eip_config") {
updateAttrs = append(updateAttrs, "enable_eip_config")
}

if raw, ok := d.GetOk("enable_public_net"); ok {
enablePublicNet := raw.(bool)
publicNetStatus := helper.String("ENABLE")
if !enablePublicNet {
publicNetStatus = helper.String("DISABLE")
}
functionInfo.publicNetConfig = &scf.PublicNetConfigIn{
PublicNetStatus: publicNetStatus,
EipConfig: &scf.EipConfigIn{
EipStatus: helper.String("DISABLE"),
},
}
}

if raw, ok := d.GetOk("enable_eip_config"); ok {
status := "DISABLE"
enablePublicNet := d.Get("enable_public_net").(bool)
if raw.(bool) {
if !enablePublicNet {
return fmt.Errorf("cannot set enable_eip_config to true if enable_public_net was disable")
}
status = "ENABLE"
}
functionInfo.publicNetConfig.EipConfig = &scf.EipConfigIn{
EipStatus: helper.String(status),
}
}

// update function configuration
if len(updateAttrs) > 0 {
if err := scfService.ModifyFunctionConfig(ctx, functionInfo); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions tencentcloud/service_tencentcloud_scf.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type scfFunctionInfo struct {
clsTopicId *string
namespace *string
l5Enable *bool
publicNetConfig *scf.PublicNetConfigIn

cosBucketName *string
cosObjectName *string
Expand All @@ -54,6 +55,7 @@ func (me *ScfService) CreateFunction(ctx context.Context, info scfFunctionInfo)
request.Handler = info.handler
request.Description = info.desc
request.MemorySize = helper.IntInt64(*info.memSize)
request.PublicNetConfig = info.publicNetConfig
request.Timeout = helper.IntInt64(*info.timeout)
for k, v := range info.environment {
if request.Environment == nil {
Expand Down Expand Up @@ -249,6 +251,9 @@ func (me *ScfService) ModifyFunctionConfig(ctx context.Context, info scfFunction
}
request.VpcConfig.SubnetId = info.subnetId
}
if info.publicNetConfig != nil {
request.PublicNetConfig = info.publicNetConfig
}
request.Role = info.role
request.ClsLogsetId = info.clsLogsetId
request.ClsTopicId = info.clsTopicId
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/scf_function.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The following arguments are supported:
* `cos_bucket_region` - (Optional) Cos bucket region of the SCF function, conflict with `zip_file`.
* `cos_object_name` - (Optional) Cos object name of the SCF function, should have suffix `.zip` or `.jar`, conflict with `zip_file`.
* `description` - (Optional) Description of the SCF function. Description supports English letters, numbers, spaces, commas, newlines, periods and Chinese, the maximum length is 1000.
* `enable_eip_config` - (Optional) Indicates whether EIP config set to `ENABLE` when `enable_public_net` was true.
* `enable_public_net` - (Optional) Indicates whether public net config enabled.
* `environment` - (Optional) Environment of the SCF function.
* `l5_enable` - (Optional) Enable L5 for SCF function, default is `false`.
* `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.
Expand Down