Skip to content

Commit ed60624

Browse files
Feat/scf support (#2308)
* [Do Not Merge]add container_image_accelerate and image_port, and fix the problem of multiple tag keys update failure * add changelog 2308.txt * read ScfFunction and add image_config parameter return * add the IpFixed parameter of IntranetConfig and the DnsCache parameter * update scf function test and changelog 2038.txt * update changelog 2308.txt * update scf function datasource --------- Co-authored-by: andrewjiang <104899514+andrew-tx@users.noreply.github.com>
1 parent 7264456 commit ed60624

File tree

14 files changed

+1599
-1012
lines changed

14 files changed

+1599
-1012
lines changed

.changelog/2308.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
datasource/tencentcloud_scf_function: add container_image_accelerate, image_port, dns_cache and intranet_config parameters
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_scf_function: add container_image_accelerate, image_port, dns_cache and intranet_config parameters
7+
```
8+
9+
```release-note:bug
10+
resource/tencentcloud_scf_function: fix the issue where only one of multiple tag key updates takes effect
11+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ require (
7575
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.762
7676
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/redis v1.0.657
7777
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.744
78-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.729
78+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.807
7979
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.748
8080
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.486
8181
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sqlserver v1.0.689

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.800 h1:sQFd
924924
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.800/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
925925
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.802/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
926926
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.804/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
927+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.805 h1:o8eGctpf5LAIBv1iUiRqrdQhetUxVyIU79Cbm11POH8=
928+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.805/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
929+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.806 h1:FnKMbjwJcsR8VnaBjDAivh/R5Zig2DYCf5oR/n4HBr4=
930+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.806/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
927931
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.807 h1:L/frkQ4e34Q9WsVJn+666Mk3WmJQuAwBKOs5198c/So=
928932
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.807/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
929933
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
@@ -988,6 +992,12 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.744 h1:Z6xqpgn
988992
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/rum v1.0.744/go.mod h1:prlrCvxmnWH4yCkA5cIIjGZMMuuvPs5EuCx1rV+F8jk=
989993
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.729 h1:UWTpLpN3UngFNTuMosxSMCcmuoLksvuc9tt7ulCe0D8=
990994
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.729/go.mod h1:P5cLcaPdmOiRhv79OAvAKf+9JTg/64N7ZxwZHBW2mZA=
995+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.805 h1:jvYQiASfey7At/FXlB9IioR878/7yfBffa+Tu4qXywM=
996+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.805/go.mod h1:+FIvazryI2lUJ6cYthU4hIx2VyvLN+QwZ1imlJofNzk=
997+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.806 h1:oSA9wDfV01Q+jrQkOlN09V+YmaOKZADdyEQeKhUjzbg=
998+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.806/go.mod h1:PEVvA3Gb4huioOmJmSRKPS7+24cUgYt8CgvYFteItQo=
999+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.807 h1:8yfLBKc7/kBSFM+yXrXtH2w00g9rP39SpgXOsHCpVdg=
1000+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf v1.0.807/go.mod h1:YtnZZS/ejJwUqPyqMPmiscKOoGDD1Q9dbQ3cJKwjwIo=
9911001
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.748 h1:pG2i5MHLmDkn8RC5wGjqRUx2db4L79JmV7qJyFzK5cs=
9921002
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.748/go.mod h1:ZADb5YPBRKNvhdQVl74jPKf9gMCDX8rxtDkBsYMSDfU=
9931003
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.486 h1:eHLaL+hl5X5f8Apuf2SGVclO3MRev/E3AfA/0aZQGUA=

tencentcloud/data_source_tc_scf_functions.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,82 @@ func dataSourceTencentCloudScfFunctions() *schema.Resource {
268268
},
269269
},
270270
},
271+
"image_config": {
272+
Type: schema.TypeList,
273+
Computed: true,
274+
Description: "Image of the SCF function, conflict with `cos_bucket_name`, `cos_object_name`, `cos_bucket_region`, `zip_file`.",
275+
Elem: &schema.Resource{
276+
Schema: map[string]*schema.Schema{
277+
"image_type": {
278+
Type: schema.TypeString,
279+
Computed: true,
280+
Description: "The image type. personal or enterprise.",
281+
},
282+
"image_uri": {
283+
Type: schema.TypeString,
284+
Computed: true,
285+
Description: "The uri of image.",
286+
},
287+
"registry_id": {
288+
Type: schema.TypeString,
289+
Computed: true,
290+
Description: "The registry id of TCR. When image type is enterprise, it must be set.",
291+
},
292+
"entry_point": {
293+
Type: schema.TypeString,
294+
Computed: true,
295+
Description: "The entrypoint of app.",
296+
},
297+
"command": {
298+
Type: schema.TypeString,
299+
Computed: true,
300+
Description: "The command of entrypoint.",
301+
},
302+
"args": {
303+
Type: schema.TypeString,
304+
Computed: true,
305+
Description: "the parameters of command.",
306+
},
307+
"container_image_accelerate": {
308+
Type: schema.TypeBool,
309+
Computed: true,
310+
Description: "Image accelerate switch.",
311+
},
312+
"image_port": {
313+
Type: schema.TypeInt,
314+
Computed: true,
315+
Description: "Image function port setting. Default is `9000`, -1 indicates no port mirroring function. Other value ranges 0 ~ 65535.",
316+
},
317+
},
318+
},
319+
},
320+
"dns_cache": {
321+
Type: schema.TypeBool,
322+
Computed: true,
323+
Description: "Whether to enable Dns caching capability, only the EVENT function is supported. Default is false.",
324+
},
325+
"intranet_config": {
326+
Type: schema.TypeList,
327+
Computed: true,
328+
Description: "Intranet access configuration.",
329+
Elem: &schema.Resource{
330+
Schema: map[string]*schema.Schema{
331+
"ip_fixed": {
332+
Type: schema.TypeString,
333+
Computed: true,
334+
Description: "Whether to enable fixed intranet IP, ENABLE is enabled, DISABLE is disabled.",
335+
},
336+
"ip_address": {
337+
Type: schema.TypeList,
338+
Elem: &schema.Schema{
339+
Type: schema.TypeString,
340+
},
341+
Computed: true,
342+
Description: "If fixed intranet IP is enabled, this field returns the IP list used.",
343+
},
344+
},
345+
},
346+
},
271347
},
272348
},
273349
},
@@ -402,6 +478,54 @@ func dataSourceTencentCloudScfFunctionsRead(d *schema.ResourceData, m interface{
402478
m["tags"] = fnTags
403479
m["async_run_enable"] = resp.AsyncRunEnable
404480

481+
imageConfigs := make([]map[string]interface{}, 0, 1)
482+
if resp.ImageConfig != nil {
483+
imageConfigResp := resp.ImageConfig
484+
485+
imageConfig := map[string]interface{}{
486+
"image_type": imageConfigResp.ImageType,
487+
"image_uri": imageConfigResp.ImageUri,
488+
}
489+
if imageConfigResp.RegistryId != nil {
490+
imageConfig["registry_id"] = imageConfigResp.RegistryId
491+
}
492+
if imageConfigResp.EntryPoint != nil {
493+
imageConfig["entry_point"] = imageConfigResp.EntryPoint
494+
}
495+
if imageConfigResp.Command != nil {
496+
imageConfig["command"] = imageConfigResp.Command
497+
}
498+
if imageConfigResp.Args != nil {
499+
imageConfig["args"] = imageConfigResp.Args
500+
}
501+
if imageConfigResp.ContainerImageAccelerate != nil {
502+
imageConfig["container_image_accelerate"] = imageConfigResp.ContainerImageAccelerate
503+
}
504+
if imageConfigResp.ImagePort != nil {
505+
imageConfig["image_port"] = imageConfigResp.ImagePort
506+
}
507+
imageConfigs = append(imageConfigs, imageConfig)
508+
}
509+
m["image_config"] = imageConfigs
510+
511+
if resp.DnsCache != nil {
512+
m["dns_cache"] = *resp.DnsCache == "TRUE"
513+
}
514+
515+
intranetConfigs := make([]map[string]interface{}, 0, 1)
516+
if resp.IntranetConfig != nil {
517+
intranetConfigResp := resp.IntranetConfig
518+
519+
intranetConfig := map[string]interface{}{
520+
"ip_fixed": intranetConfigResp.IpFixed,
521+
}
522+
if intranetConfigResp.IpAddress != nil {
523+
intranetConfig["ip_address"] = intranetConfigResp.IpAddress
524+
}
525+
intranetConfigs = append(intranetConfigs, intranetConfig)
526+
}
527+
m["intranet_config"] = intranetConfigs
528+
405529
functions = append(functions, m)
406530
}
407531

tencentcloud/data_source_tc_scf_functions_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tencentcloud
22

33
import (
4+
"fmt"
45
"regexp"
56
"testing"
67

@@ -35,6 +36,8 @@ func TestAccDataSourceTencentCloudScfFunctions_basic(t *testing.T) {
3536
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.l5_enable"),
3637
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.trigger_info.#"),
3738
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.async_run_enable"),
39+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.dns_cache", "false"),
40+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.intranet_config.0.ip_fixed", "DISABLE"),
3841
),
3942
},
4043
},
@@ -68,6 +71,8 @@ func TestAccDataSourceTencentCloudScfFunctions_namespace(t *testing.T) {
6871
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.eips.#"),
6972
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.l5_enable"),
7073
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.trigger_info.#"),
74+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.dns_cache", "false"),
75+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.intranet_config.0.ip_fixed", "DISABLE"),
7176
),
7277
},
7378
},
@@ -102,6 +107,8 @@ func TestAccDataSourceTencentCloudScfFunctions_Desc(t *testing.T) {
102107
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.eips.#"),
103108
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.l5_enable"),
104109
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.trigger_info.#"),
110+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.dns_cache", "false"),
111+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.intranet_config.0.ip_fixed", "DISABLE"),
105112
),
106113
},
107114
},
@@ -136,6 +143,44 @@ func TestAccDataSourceTencentCloudScfFunctions_tag(t *testing.T) {
136143
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.l5_enable"),
137144
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.trigger_info.#"),
138145
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.tags.test", "test"),
146+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.dns_cache", "false"),
147+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.intranet_config.0.ip_fixed", "DISABLE"),
148+
),
149+
},
150+
},
151+
})
152+
}
153+
154+
func TestAccDataSourceTencentCloudScfFunctions_IntranetConfig(t *testing.T) {
155+
t.Parallel()
156+
resource.Test(t, resource.TestCase{
157+
PreCheck: func() { testAccPreCheck(t) },
158+
Providers: testAccProviders,
159+
Steps: []resource.TestStep{
160+
{
161+
Config: scfFunctionCodeEmbed("first.zip", TestAccDataSourceTencentCloudScfFunctionsIntranetConfig),
162+
Check: resource.ComposeTestCheckFunc(
163+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_scf_functions.foo"),
164+
resource.TestMatchResourceAttr("data.tencentcloud_scf_functions.foo", "functions.#", regexp.MustCompile(`^[1-9]\d*$`)),
165+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.name"),
166+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.handler"),
167+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.mem_size"),
168+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.timeout"),
169+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.runtime"),
170+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.namespace"),
171+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.create_time"),
172+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.modify_time"),
173+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.code_size"),
174+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.err_no"),
175+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.install_dependency"),
176+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.status"),
177+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.eip_fixed"),
178+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.eips.#"),
179+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.l5_enable"),
180+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.trigger_info.#"),
181+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.dns_cache", "true"),
182+
resource.TestCheckResourceAttr("data.tencentcloud_scf_functions.foo", "functions.0.intranet_config.0.ip_fixed", "ENABLE"),
183+
resource.TestCheckResourceAttrSet("data.tencentcloud_scf_functions.foo", "functions.0.intranet_config.0.ip_address.#"),
139184
),
140185
},
141186
},
@@ -207,3 +252,25 @@ data "tencentcloud_scf_functions" "foo" {
207252
tags = tencentcloud_scf_function.foo.tags
208253
}
209254
`
255+
256+
var TestAccDataSourceTencentCloudScfFunctionsIntranetConfig = fmt.Sprintf(defaultVpcVariable+`
257+
resource "tencentcloud_scf_function" "foo" {
258+
name = "%s"
259+
handler = "first.do_it_first"
260+
runtime = "Python3.6"
261+
enable_public_net = true
262+
dns_cache = true
263+
264+
intranet_config {
265+
ip_fixed = "ENABLE"
266+
}
267+
vpc_id = var.vpc_id
268+
subnet_id = var.subnet_id
269+
270+
zip_file = "%s"
271+
}
272+
273+
data "tencentcloud_scf_functions" "foo" {
274+
name = tencentcloud_scf_function.foo.name
275+
}
276+
`, "%s", "%s")

tencentcloud/extension_scf.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ const (
1010
SCF_FUNCTION_STATUS_UPDATE_FAILED = "UpdateFailed"
1111
SCF_FUNCTION_STATUS_PUBLISH_FAILED = "PublishFailed"
1212

13-
SCF_SERVICE = "scf"
14-
SCF_FUNCTION_RESOURCE = "lam"
13+
SCF_SERVICE = "scf"
14+
SCF_FUNCTION_RESOURCE = "lam"
15+
SCF_FUNCTION_RESOURCE_PREFIX = "namespace"
1516

1617
SCF_TRIGGER_TYPE_COS = "cos"
1718
SCF_TRIGGER_TYPE_CMQ = "cmq"

0 commit comments

Comments
 (0)