Skip to content

Commit e76400c

Browse files
committed
add
1 parent c9c3cb5 commit e76400c

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

tencentcloud/services/scf/resource_tc_scf_function.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ func ResourceTencentCloudScfFunction() *schema.Resource {
523523
},
524524
},
525525
},
526+
"function_id": {
527+
Type: schema.TypeString,
528+
Computed: true,
529+
Description: "function ID.",
530+
},
526531
},
527532
}
528533
}
@@ -535,7 +540,10 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{}
535540
client := m.(tccommon.ProviderMeta).GetAPIV3Conn()
536541
scfService := ScfService{client: client}
537542

538-
var functionInfo scfFunctionInfo
543+
var (
544+
functionInfo scfFunctionInfo
545+
functionId string
546+
)
539547

540548
functionInfo.name = d.Get("name").(string)
541549
functionInfo.desc = helper.String(d.Get("description").(string))
@@ -841,12 +849,15 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{}
841849
}
842850
}
843851

844-
_, err = scfService.DescribeFunction(ctx, functionInfo.name, *functionInfo.namespace)
852+
funcResp, err := scfService.DescribeFunction(ctx, functionInfo.name, *functionInfo.namespace)
845853
if err != nil {
846854
log.Printf("[CRITAL]%s get function id failed: %+v", logId, err)
847855
return err
848856
}
849857

858+
functionId = *funcResp.Response.FunctionId
859+
_ = d.Set("function_id", functionId)
860+
850861
return resourceTencentCloudScfFunctionRead(d, m)
851862
}
852863

@@ -868,7 +879,8 @@ func resourceTencentCloudScfFunctionRead(d *schema.ResourceData, m interface{})
868879
}
869880
namespace, name := split[0], split[1]
870881

871-
response, err := service.DescribeFunction(ctx, name, namespace)
882+
functionId := d.Get("function_id").(string)
883+
response, err := service.DescribeFunction(ctx, name, namespace, functionId)
872884
if err != nil {
873885
log.Printf("[CRITAL]%s read function failed: %+v", logId, err)
874886
}
@@ -901,6 +913,7 @@ func resourceTencentCloudScfFunctionRead(d *schema.ResourceData, m interface{})
901913
_ = d.Set("cls_topic_id", resp.ClsTopicId)
902914
_ = d.Set("func_type", resp.Type)
903915
_ = d.Set("l5_enable", *resp.L5Enable == "TRUE")
916+
_ = d.Set("function_id", resp.FunctionId)
904917

905918
tags := make(map[string]string, len(resp.Tags))
906919
for _, tag := range resp.Tags {

tencentcloud/services/scf/service_tencentcloud_scf.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scf
22

33
import (
44
"context"
5+
"fmt"
56
"log"
67
"strings"
78

@@ -147,15 +148,21 @@ func (me *ScfService) CreateFunction(ctx context.Context, info scfFunctionInfo)
147148
return nil
148149
}
149150

150-
func (me *ScfService) DescribeFunction(ctx context.Context, name, namespace string) (resp *scf.GetFunctionResponse, err error) {
151+
func (me *ScfService) DescribeFunction(ctx context.Context, name, namespace string, functionId ...string) (resp *scf.GetFunctionResponse, err error) {
151152
request := scf.NewGetFunctionRequest()
153+
response := scf.NewGetFunctionResponse()
152154
request.FunctionName = &name
153155
request.Namespace = &namespace
154-
var iacExtInfo connectivity.IacExtInfo
155-
iacExtInfo.InstanceId = strings.Join([]string{name, namespace}, tccommon.FILED_SP)
156156
if err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
157157
ratelimit.Check(request.GetAction())
158-
response, err := me.client.UseScfClient(iacExtInfo).GetFunction(request)
158+
if len(functionId) == 1 {
159+
var iacExtInfo connectivity.IacExtInfo
160+
iacExtInfo.InstanceId = functionId[0]
161+
response, err = me.client.UseScfClient(iacExtInfo).GetFunction(request)
162+
} else {
163+
response, err = me.client.UseScfClient().GetFunction(request)
164+
}
165+
159166
if err != nil {
160167
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
161168
for _, code := range SCF_FUNCTIONS_NOT_FOUND_SET {
@@ -168,6 +175,10 @@ func (me *ScfService) DescribeFunction(ctx context.Context, name, namespace stri
168175
return tccommon.RetryError(errors.WithStack(err), tccommon.InternalError)
169176
}
170177

178+
if response == nil || *response.Response.FunctionId == "" {
179+
return resource.NonRetryableError(fmt.Errorf("functionId is empty"))
180+
}
181+
171182
resp = response
172183
return nil
173184
}); err != nil {

website/docs/r/scf_function.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ In addition to all arguments above, the following attributes are exported:
174174
* `eip_fixed` - Whether EIP is a fixed IP.
175175
* `eips` - SCF function EIP list.
176176
* `err_no` - SCF function code error code.
177+
* `function_id` - function ID.
177178
* `host` - SCF function domain name.
178179
* `install_dependency` - Whether to automatically install dependencies.
179180
* `modify_time` - SCF function last modified time.

0 commit comments

Comments
 (0)