Skip to content

Commit 0f08724

Browse files
authored
update dc (#1832)
* update dc * update doc * update doc
1 parent a70e32a commit 0f08724

File tree

6 files changed

+313
-0
lines changed

6 files changed

+313
-0
lines changed

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ Serverless Cloud Function(SCF)
637637
tencentcloud_scf_function
638638
tencentcloud_scf_function_version
639639
tencentcloud_scf_function_event_invoke_config
640+
tencentcloud_scf_reserved_concurrency_config
640641
tencentcloud_scf_namespace
641642
tencentcloud_scf_layer
642643
tencentcloud_scf_function_alias
@@ -1982,6 +1983,7 @@ func Provider() *schema.Provider {
19821983
"tencentcloud_scf_function": resourceTencentCloudScfFunction(),
19831984
"tencentcloud_scf_function_version": resourceTencentCloudScfFunctionVersion(),
19841985
"tencentcloud_scf_function_event_invoke_config": resourceTencentCloudScfFunctionEventInvokeConfig(),
1986+
"tencentcloud_scf_reserved_concurrency_config": resourceTencentCloudScfReservedConcurrencyConfig(),
19851987
"tencentcloud_scf_namespace": resourceTencentCloudScfNamespace(),
19861988
"tencentcloud_scf_layer": resourceTencentCloudScfLayer(),
19871989
"tencentcloud_scf_function_alias": resourceTencentCloudScfFunctionAlias(),
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
Provides a resource to create a scf reserved_concurrency_config
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_scf_reserved_concurrency_config" "reserved_concurrency_config" {
8+
function_name = "keep-1676351130"
9+
reserved_concurrency_mem = 128000
10+
namespace = "default"
11+
}
12+
```
13+
14+
Import
15+
16+
scf reserved_concurrency_config can be imported using the id, e.g.
17+
18+
```
19+
terraform import tencentcloud_scf_reserved_concurrency_config.reserved_concurrency_config reserved_concurrency_config_id
20+
```
21+
*/
22+
package tencentcloud
23+
24+
import (
25+
"context"
26+
"fmt"
27+
"log"
28+
"strings"
29+
30+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
31+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
32+
scf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
33+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
34+
)
35+
36+
func resourceTencentCloudScfReservedConcurrencyConfig() *schema.Resource {
37+
return &schema.Resource{
38+
Create: resourceTencentCloudScfReservedConcurrencyConfigCreate,
39+
Read: resourceTencentCloudScfReservedConcurrencyConfigRead,
40+
Delete: resourceTencentCloudScfReservedConcurrencyConfigDelete,
41+
Importer: &schema.ResourceImporter{
42+
State: schema.ImportStatePassthrough,
43+
},
44+
Schema: map[string]*schema.Schema{
45+
"function_name": {
46+
Required: true,
47+
ForceNew: true,
48+
Type: schema.TypeString,
49+
Description: "Specifies the function of which you want to configure the reserved quota.",
50+
},
51+
52+
"reserved_concurrency_mem": {
53+
Required: true,
54+
ForceNew: true,
55+
Type: schema.TypeInt,
56+
Description: "Reserved memory quota of the function. Note: the upper limit for the total reserved quota of the function is the user's total concurrency memory minus 12800.",
57+
},
58+
59+
"namespace": {
60+
Optional: true,
61+
ForceNew: true,
62+
Default: "default",
63+
Type: schema.TypeString,
64+
Description: "Function namespace. Default value: default.",
65+
},
66+
},
67+
}
68+
}
69+
70+
func resourceTencentCloudScfReservedConcurrencyConfigCreate(d *schema.ResourceData, meta interface{}) error {
71+
defer logElapsed("resource.tencentcloud_scf_reserved_concurrency_config.create")()
72+
defer inconsistentCheck(d, meta)()
73+
74+
logId := getLogId(contextNil)
75+
76+
var (
77+
request = scf.NewPutReservedConcurrencyConfigRequest()
78+
namespace string
79+
functionName string
80+
)
81+
if v, ok := d.GetOk("function_name"); ok {
82+
functionName = v.(string)
83+
request.FunctionName = helper.String(v.(string))
84+
}
85+
86+
if v, ok := d.GetOkExists("reserved_concurrency_mem"); ok {
87+
request.ReservedConcurrencyMem = helper.IntUint64(v.(int))
88+
}
89+
90+
if v, ok := d.GetOk("namespace"); ok {
91+
namespace = v.(string)
92+
request.Namespace = helper.String(v.(string))
93+
}
94+
95+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
96+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseScfClient().PutReservedConcurrencyConfig(request)
97+
if e != nil {
98+
return retryError(e)
99+
} else {
100+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
101+
}
102+
return nil
103+
})
104+
if err != nil {
105+
log.Printf("[CRITAL]%s create scf ReservedConcurrencyConfig failed, reason:%+v", logId, err)
106+
return err
107+
}
108+
109+
d.SetId(namespace + FILED_SP + functionName)
110+
111+
return resourceTencentCloudScfReservedConcurrencyConfigRead(d, meta)
112+
}
113+
114+
func resourceTencentCloudScfReservedConcurrencyConfigRead(d *schema.ResourceData, meta interface{}) error {
115+
defer logElapsed("resource.tencentcloud_scf_reserved_concurrency_config.read")()
116+
defer inconsistentCheck(d, meta)()
117+
118+
logId := getLogId(contextNil)
119+
120+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
121+
122+
service := ScfService{client: meta.(*TencentCloudClient).apiV3Conn}
123+
124+
idSplit := strings.Split(d.Id(), FILED_SP)
125+
if len(idSplit) != 2 {
126+
return fmt.Errorf("id is broken,%s", d.Id())
127+
}
128+
namespace := idSplit[0]
129+
functionName := idSplit[1]
130+
131+
reservedConcurrencyConfig, err := service.DescribeScfReservedConcurrencyConfigById(ctx, namespace, functionName)
132+
if err != nil {
133+
return err
134+
}
135+
136+
if reservedConcurrencyConfig == nil {
137+
d.SetId("")
138+
log.Printf("[WARN]%s resource `ScfReservedConcurrencyConfig` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
139+
return nil
140+
}
141+
142+
_ = d.Set("namespace", namespace)
143+
_ = d.Set("function_name", functionName)
144+
145+
if reservedConcurrencyConfig.Response.ReservedMem != nil {
146+
_ = d.Set("reserved_concurrency_mem", reservedConcurrencyConfig.Response.ReservedMem)
147+
}
148+
149+
return nil
150+
}
151+
152+
func resourceTencentCloudScfReservedConcurrencyConfigDelete(d *schema.ResourceData, meta interface{}) error {
153+
defer logElapsed("resource.tencentcloud_scf_reserved_concurrency_config.delete")()
154+
defer inconsistentCheck(d, meta)()
155+
156+
logId := getLogId(contextNil)
157+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
158+
159+
service := ScfService{client: meta.(*TencentCloudClient).apiV3Conn}
160+
idSplit := strings.Split(d.Id(), FILED_SP)
161+
if len(idSplit) != 2 {
162+
return fmt.Errorf("id is broken,%s", d.Id())
163+
}
164+
namespace := idSplit[0]
165+
functionName := idSplit[1]
166+
167+
if err := service.DeleteScfReservedConcurrencyConfigById(ctx, namespace, functionName); err != nil {
168+
return err
169+
}
170+
171+
return nil
172+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudScfReservedConcurrencyConfigResource_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: testAccScfReservedConcurrencyConfig,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_scf_reserved_concurrency_config.reserved_concurrency_config", "id")),
20+
},
21+
{
22+
ResourceName: "tencentcloud_scf_reserved_concurrency_config.reserved_concurrency_config",
23+
ImportState: true,
24+
ImportStateVerify: true,
25+
},
26+
},
27+
})
28+
}
29+
30+
const testAccScfReservedConcurrencyConfig = `
31+
32+
resource "tencentcloud_scf_reserved_concurrency_config" "reserved_concurrency_config" {
33+
function_name = "keep-1676351130"
34+
reserved_concurrency_mem = 128000
35+
namespace = "default"
36+
}
37+
38+
`

tencentcloud/service_tencentcloud_scf.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,54 @@ func (me *ScfService) DescribeScfFunctionEventInvokeConfigById(ctx context.Conte
738738
FunctionEventInvokeConfig = response.Response.AsyncTriggerConfig
739739
return
740740
}
741+
742+
func (me *ScfService) DescribeScfReservedConcurrencyConfigById(ctx context.Context, namespace string, functionName string) (reservedConcurrencyConfig *scf.GetReservedConcurrencyConfigResponse, errRet error) {
743+
logId := getLogId(ctx)
744+
745+
request := scf.NewGetReservedConcurrencyConfigRequest()
746+
request.Namespace = &namespace
747+
request.FunctionName = &functionName
748+
749+
defer func() {
750+
if errRet != nil {
751+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
752+
}
753+
}()
754+
755+
ratelimit.Check(request.GetAction())
756+
757+
response, err := me.client.UseScfClient().GetReservedConcurrencyConfig(request)
758+
if err != nil {
759+
errRet = err
760+
return
761+
}
762+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
763+
764+
reservedConcurrencyConfig = response
765+
return
766+
}
767+
768+
func (me *ScfService) DeleteScfReservedConcurrencyConfigById(ctx context.Context, namespace string, functionName string) (errRet error) {
769+
logId := getLogId(ctx)
770+
771+
request := scf.NewDeleteReservedConcurrencyConfigRequest()
772+
request.Namespace = &namespace
773+
request.FunctionName = &functionName
774+
775+
defer func() {
776+
if errRet != nil {
777+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
778+
}
779+
}()
780+
781+
ratelimit.Check(request.GetAction())
782+
783+
response, err := me.client.UseScfClient().DeleteReservedConcurrencyConfig(request)
784+
if err != nil {
785+
errRet = err
786+
return
787+
}
788+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
789+
790+
return
791+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
subcategory: "Serverless Cloud Function(SCF)"
3+
layout: "tencentcloud"
4+
page_title: "TencentCloud: tencentcloud_scf_reserved_concurrency_config"
5+
sidebar_current: "docs-tencentcloud-resource-scf_reserved_concurrency_config"
6+
description: |-
7+
Provides a resource to create a scf reserved_concurrency_config
8+
---
9+
10+
# tencentcloud_scf_reserved_concurrency_config
11+
12+
Provides a resource to create a scf reserved_concurrency_config
13+
14+
## Example Usage
15+
16+
```hcl
17+
resource "tencentcloud_scf_reserved_concurrency_config" "reserved_concurrency_config" {
18+
function_name = "keep-1676351130"
19+
reserved_concurrency_mem = 128000
20+
namespace = "default"
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `function_name` - (Required, String, ForceNew) Specifies the function of which you want to configure the reserved quota.
29+
* `reserved_concurrency_mem` - (Required, Int, ForceNew) Reserved memory quota of the function. Note: the upper limit for the total reserved quota of the function is the user's total concurrency memory minus 12800.
30+
* `namespace` - (Optional, String, ForceNew) Function namespace. Default value: default.
31+
32+
## Attributes Reference
33+
34+
In addition to all arguments above, the following attributes are exported:
35+
36+
* `id` - ID of the resource.
37+
38+
39+
40+
## Import
41+
42+
scf reserved_concurrency_config can be imported using the id, e.g.
43+
44+
```
45+
terraform import tencentcloud_scf_reserved_concurrency_config.reserved_concurrency_config reserved_concurrency_config_id
46+
```
47+

website/tencentcloud.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,9 @@
20702070
<li>
20712071
<a href="/docs/providers/tencentcloud/r/scf_namespace.html">tencentcloud_scf_namespace</a>
20722072
</li>
2073+
<li>
2074+
<a href="/docs/providers/tencentcloud/r/scf_reserved_concurrency_config.html">tencentcloud_scf_reserved_concurrency_config</a>
2075+
</li>
20732076
</ul>
20742077
</li>
20752078
</ul>

0 commit comments

Comments
 (0)