Skip to content

Commit 8383d78

Browse files
authored
update config (#1833)
* update config * update changelog * add scf operation
1 parent 0f08724 commit 8383d78

23 files changed

+5127
-571
lines changed

.changelog/1833.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-resource
2+
tencentcloud_scf_provisioned_concurrency_config
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_scf_invoke_function
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_scf_sync_invoke_function
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_scf_terminate_async_event
15+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.599
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.663
41-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.663
41+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.664
4242
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.572
@@ -65,7 +65,7 @@ require (
6565
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.533
6666
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.657
6767
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.542
68-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.275
68+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.664
6969
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.529
7070
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.486
7171
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver v1.0.662

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,9 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.658/go.mod
844844
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.659/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
845845
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.661/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
846846
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.662/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
847-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.663 h1:Xk/rySXVRQEsw0v4CIYxhIl0d2nLtaynQA4jiajSxUQ=
848847
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.663/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
848+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.664 h1:Han+TNmpXPp45uE8h8yU95QZbhglrpSl+TG7qec6eEI=
849+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.664/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
849850
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
850851
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624/go.mod h1:+TXSVyeKwt1IhZRqKPbTREteBcP+K07Q846/ilNzLWA=
851852
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589 h1:LZihgirMH0vsaGScYexxwY0fTss9vHaSZs/YOQUVESg=
@@ -899,8 +900,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.657 h1:9p/4/
899900
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.657/go.mod h1:CPc7SSKl8I21UmhTf2AVYZqZfy8MbDr/RrMsSqMkOAM=
900901
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.542 h1:/U0rTVKXD7Y8Opw6OtnqSDPnWiP3zMMAlxOKayII/5Q=
901902
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.542/go.mod h1:QF1J13hmuMY5gMrBopRFmHWFs/KsLr5uCNBRJt5aA1M=
902-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.275 h1:hn5RrN/qkcObnyKfJ+raey/riVeRqHJFvY34l2YgELs=
903-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.275/go.mod h1:Pew6DV5oBGrzHYWZ8ssiHeJS/Z39ggVv1y5ADGWdO4s=
903+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.664 h1:57r4xDd0t9zQw8tLO9k13gYy/EYYGtFV3fMPx1BJinY=
904+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.664/go.mod h1:dFFSCohvDzW2jidqjb5GFDhQD/2AfM1tZ8ijkuJUr9Y=
904905
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.529 h1:NezuBQEG7ihXbwueREo4qavBAo6ZcHuWGZt1dR+VdKc=
905906
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.529/go.mod h1:Xfmf4Rq4J2ukz6NoEwpADQS5ws3By3KDPemCQeeMF+M=
906907
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.486 h1:eHLaL+hl5X5f8Apuf2SGVclO3MRev/E3AfA/0aZQGUA=

tencentcloud/provider.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,10 @@ Serverless Cloud Function(SCF)
638638
tencentcloud_scf_function_version
639639
tencentcloud_scf_function_event_invoke_config
640640
tencentcloud_scf_reserved_concurrency_config
641+
tencentcloud_scf_provisioned_concurrency_config
642+
tencentcloud_scf_invoke_function
643+
tencentcloud_scf_sync_invoke_function
644+
tencentcloud_scf_terminate_async_event
641645
tencentcloud_scf_namespace
642646
tencentcloud_scf_layer
643647
tencentcloud_scf_function_alias
@@ -1984,6 +1988,10 @@ func Provider() *schema.Provider {
19841988
"tencentcloud_scf_function_version": resourceTencentCloudScfFunctionVersion(),
19851989
"tencentcloud_scf_function_event_invoke_config": resourceTencentCloudScfFunctionEventInvokeConfig(),
19861990
"tencentcloud_scf_reserved_concurrency_config": resourceTencentCloudScfReservedConcurrencyConfig(),
1991+
"tencentcloud_scf_provisioned_concurrency_config": resourceTencentCloudScfProvisionedConcurrencyConfig(),
1992+
"tencentcloud_scf_invoke_function": resourceTencentCloudScfInvokeFunction(),
1993+
"tencentcloud_scf_sync_invoke_function": resourceTencentCloudScfSyncInvokeFunction(),
1994+
"tencentcloud_scf_terminate_async_event": resourceTencentCloudScfTerminateAsyncEvent(),
19871995
"tencentcloud_scf_namespace": resourceTencentCloudScfNamespace(),
19881996
"tencentcloud_scf_layer": resourceTencentCloudScfLayer(),
19891997
"tencentcloud_scf_function_alias": resourceTencentCloudScfFunctionAlias(),
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
Provides a resource to create a scf invoke_function
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_scf_invoke_function" "invoke_function" {
8+
function_name = "keep-1676351130"
9+
qualifier = "2"
10+
namespace = "default"
11+
}
12+
```
13+
14+
*/
15+
package tencentcloud
16+
17+
import (
18+
"log"
19+
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
21+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
22+
scf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
23+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
24+
)
25+
26+
func resourceTencentCloudScfInvokeFunction() *schema.Resource {
27+
return &schema.Resource{
28+
Create: resourceTencentCloudScfInvokeFunctionCreate,
29+
Read: resourceTencentCloudScfInvokeFunctionRead,
30+
Delete: resourceTencentCloudScfInvokeFunctionDelete,
31+
Schema: map[string]*schema.Schema{
32+
"function_name": {
33+
Required: true,
34+
ForceNew: true,
35+
Type: schema.TypeString,
36+
Description: "Function name.",
37+
},
38+
39+
"invocation_type": {
40+
Optional: true,
41+
ForceNew: true,
42+
Type: schema.TypeString,
43+
Description: "Fill in RequestResponse for synchronized invocations (default and recommended) and Event for asychronized invocations. Note that for synchronized invocations, the max timeout period is 300s. Choose asychronized invocations if the required timeout period is longer than 300 seconds. You can also use InvokeFunction for synchronized invocations.",
44+
},
45+
46+
"qualifier": {
47+
Optional: true,
48+
ForceNew: true,
49+
Type: schema.TypeString,
50+
Description: "The version or alias of the triggered function. It defaults to $LATEST.",
51+
},
52+
53+
"client_context": {
54+
Optional: true,
55+
ForceNew: true,
56+
Type: schema.TypeString,
57+
Description: "Function running parameter, which is in the JSON format. The maximum parameter size is 6 MB for synchronized invocations and 128KB for asynchronized invocations. This field corresponds to event input parameter.",
58+
},
59+
60+
"log_type": {
61+
Optional: true,
62+
ForceNew: true,
63+
Type: schema.TypeString,
64+
Description: "Null for async invocations.",
65+
},
66+
67+
"namespace": {
68+
Optional: true,
69+
ForceNew: true,
70+
Type: schema.TypeString,
71+
Description: "Namespace.",
72+
},
73+
74+
"routing_key": {
75+
Optional: true,
76+
ForceNew: true,
77+
Type: schema.TypeString,
78+
Description: "Traffic routing config in json format, e.g., {k:v}. Please note that both k and v must be strings. Up to 1024 bytes allowed.",
79+
},
80+
},
81+
}
82+
}
83+
84+
func resourceTencentCloudScfInvokeFunctionCreate(d *schema.ResourceData, meta interface{}) error {
85+
defer logElapsed("resource.tencentcloud_scf_invoke_function.create")()
86+
defer inconsistentCheck(d, meta)()
87+
88+
logId := getLogId(contextNil)
89+
90+
var (
91+
request = scf.NewInvokeRequest()
92+
response = scf.NewInvokeResponse()
93+
)
94+
if v, ok := d.GetOk("function_name"); ok {
95+
request.FunctionName = helper.String(v.(string))
96+
}
97+
98+
if v, ok := d.GetOk("invocation_type"); ok {
99+
request.InvocationType = helper.String(v.(string))
100+
}
101+
102+
if v, ok := d.GetOk("qualifier"); ok {
103+
request.Qualifier = helper.String(v.(string))
104+
}
105+
106+
if v, ok := d.GetOk("client_context"); ok {
107+
request.ClientContext = helper.String(v.(string))
108+
}
109+
110+
if v, ok := d.GetOk("log_type"); ok {
111+
request.LogType = helper.String(v.(string))
112+
}
113+
114+
if v, ok := d.GetOk("namespace"); ok {
115+
request.Namespace = helper.String(v.(string))
116+
}
117+
118+
if v, ok := d.GetOk("routing_key"); ok {
119+
request.RoutingKey = helper.String(v.(string))
120+
}
121+
122+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
123+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseScfClient().Invoke(request)
124+
if e != nil {
125+
return retryError(e)
126+
} else {
127+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
128+
}
129+
response = result
130+
return nil
131+
})
132+
if err != nil {
133+
log.Printf("[CRITAL]%s operate scf InvokeFunction failed, reason:%+v", logId, err)
134+
return err
135+
}
136+
137+
functionRequestId := *response.Response.Result.FunctionRequestId
138+
139+
d.SetId(functionRequestId)
140+
141+
return resourceTencentCloudScfInvokeFunctionRead(d, meta)
142+
}
143+
144+
func resourceTencentCloudScfInvokeFunctionRead(d *schema.ResourceData, meta interface{}) error {
145+
defer logElapsed("resource.tencentcloud_scf_invoke_function.read")()
146+
defer inconsistentCheck(d, meta)()
147+
148+
return nil
149+
}
150+
151+
func resourceTencentCloudScfInvokeFunctionDelete(d *schema.ResourceData, meta interface{}) error {
152+
defer logElapsed("resource.tencentcloud_scf_invoke_function.delete")()
153+
defer inconsistentCheck(d, meta)()
154+
155+
return nil
156+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudScfInvokeFunctionResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccScfInvokeFunction,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_scf_invoke_function.invoke_function", "id")),
20+
},
21+
},
22+
})
23+
}
24+
25+
const testAccScfInvokeFunction = `
26+
27+
resource "tencentcloud_scf_invoke_function" "invoke_function" {
28+
function_name = "keep-1676351130"
29+
qualifier = "2"
30+
namespace = "default"
31+
}
32+
33+
`

0 commit comments

Comments
 (0)