diff --git a/tencentcloud/basic_test.go b/tencentcloud/basic_test.go index 4b61953359..366acd55c6 100644 --- a/tencentcloud/basic_test.go +++ b/tencentcloud/basic_test.go @@ -194,3 +194,35 @@ resource "tencentcloud_mysql_instance" "default" { force_delete = true } ` +const defaultSCFCosBucket = ` +data "tencentcloud_user_info" "info" {} + +data "tencentcloud_cos_buckets" "buckets" { + bucket_prefix = "preset-scf-bucket-${data.tencentcloud_user_info.info.app_id}" +} + +locals { + bucket_name = data.tencentcloud_cos_buckets.buckets.bucket_list.0.bucket + bucket_url = data.tencentcloud_cos_buckets.buckets.bucket_list.0.cos_bucket_url +} +` + +const defaultScfNamespace = "preset-scf-namespace" + +const defaultFileSystemName = "preset_cfs" + +const defaultFileSystem = ` +data "tencentcloud_cfs_file_systems" "fs" { + name = "` + defaultFileSystemName + `" +} + +# doesn't support datasource for now +variable "mount_id" { + default = "cfs-iobiaxtj" +} + +locals { + cfs = data.tencentcloud_cfs_file_systems.fs.file_system_list.0 + cfs_id = local.cfs.file_system_id + access_group_id = local.cfs.access_group_id +}` diff --git a/tencentcloud/data_source_tc_scf_functions.go b/tencentcloud/data_source_tc_scf_functions.go index 529881a7b4..fc005c5ef0 100644 --- a/tencentcloud/data_source_tc_scf_functions.go +++ b/tencentcloud/data_source_tc_scf_functions.go @@ -138,6 +138,16 @@ func dataSourceTencentCloudScfFunctions() *schema.Resource { Computed: true, Description: "Whether to enable L5.", }, + "enable_public_net": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the public net enabled.", + }, + "enable_eip_config": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the EIP enabled.", + }, "tags": { Type: schema.TypeMap, Computed: true, @@ -389,7 +399,9 @@ func dataSourceTencentCloudScfFunctionsRead(d *schema.ResourceData, m interface{ functions = append(functions, m) } - _ = d.Set("functions", functions) + if err := d.Set("functions", functions); err != nil { + return err + } d.SetId(helper.DataResourceIdsHash(ids)) if output, ok := d.GetOk("result_output_file"); ok && output.(string) != "" { diff --git a/tencentcloud/data_source_tc_scf_functions_test.go b/tencentcloud/data_source_tc_scf_functions_test.go index 9b5a4d0e5e..67a639a058 100644 --- a/tencentcloud/data_source_tc_scf_functions_test.go +++ b/tencentcloud/data_source_tc_scf_functions_test.go @@ -146,6 +146,7 @@ resource "tencentcloud_scf_function" "foo" { name = "%s" handler = "first.do_it_first" runtime = "Python3.6" + enable_public_net = true zip_file = "%s" } @@ -156,15 +157,12 @@ data "tencentcloud_scf_functions" "foo" { ` const TestAccDataSourceTencentCloudScfFunctionsNamespace = ` -resource "tencentcloud_scf_namespace" "foo" { - namespace = "ci-test-scf" -} - resource "tencentcloud_scf_function" "foo" { - namespace = tencentcloud_scf_namespace.foo.id + namespace = "` + defaultScfNamespace + `" name = "%s" handler = "first.do_it_first" runtime = "Python3.6" + enable_public_net = true zip_file = "%s" } @@ -180,6 +178,7 @@ resource "tencentcloud_scf_function" "foo" { handler = "first.do_it_first" runtime = "Python3.6" description = "test" + enable_public_net = true zip_file = "%s" } @@ -194,6 +193,7 @@ resource "tencentcloud_scf_function" "foo" { name = "%s" handler = "first.do_it_first" runtime = "Python3.6" + enable_public_net = true zip_file = "%s" diff --git a/tencentcloud/data_source_tc_scf_logs_test.go b/tencentcloud/data_source_tc_scf_logs_test.go index ff0da1d59d..e03634b9f7 100644 --- a/tencentcloud/data_source_tc_scf_logs_test.go +++ b/tencentcloud/data_source_tc_scf_logs_test.go @@ -56,6 +56,7 @@ resource "tencentcloud_scf_function" "foo" { name = "%s" handler = "first.do_it_first" runtime = "Python3.6" + enable_public_net = true zip_file = "%s" } @@ -70,6 +71,7 @@ resource "tencentcloud_scf_function" "foo" { name = "%s" handler = "first.do_it_first" runtime = "Python3.6" + enable_public_net = true zip_file = "%s" } diff --git a/tencentcloud/data_source_tc_scf_namespaces_test.go b/tencentcloud/data_source_tc_scf_namespaces_test.go index c404aa65d6..5ff6941910 100644 --- a/tencentcloud/data_source_tc_scf_namespaces_test.go +++ b/tencentcloud/data_source_tc_scf_namespaces_test.go @@ -17,9 +17,9 @@ func TestAccDataSourceTencentCloudScfNamespaces_basic(t *testing.T) { Config: TestAccDataSourceTencentCloudScfNamespaces, Check: resource.ComposeTestCheckFunc( testAccCheckTencentCloudDataSourceID("data.tencentcloud_scf_namespaces.foo"), - resource.TestCheckResourceAttr("data.tencentcloud_scf_namespaces.foo", "namespace", "ci-test-scf"), + resource.TestCheckResourceAttr("data.tencentcloud_scf_namespaces.foo", "namespace", defaultScfNamespace), resource.TestMatchResourceAttr("data.tencentcloud_scf_namespaces.foo", "namespaces.#", regexp.MustCompile(`^[1-9]\d*$`)), - resource.TestMatchResourceAttr("data.tencentcloud_scf_namespaces.foo", "namespaces.0.namespace", regexp.MustCompile(`ci-test-scf`)), + resource.TestCheckResourceAttr("data.tencentcloud_scf_namespaces.foo", "namespaces.0.namespace", defaultScfNamespace), resource.TestCheckResourceAttrSet("data.tencentcloud_scf_namespaces.foo", "namespaces.0.create_time"), resource.TestCheckResourceAttrSet("data.tencentcloud_scf_namespaces.foo", "namespaces.0.modify_time"), resource.TestCheckResourceAttrSet("data.tencentcloud_scf_namespaces.foo", "namespaces.0.type"), @@ -53,18 +53,14 @@ func TestAccDataSourceTencentCloudScfNamespaces_desc(t *testing.T) { } const TestAccDataSourceTencentCloudScfNamespaces = ` -resource "tencentcloud_scf_namespace" "foo" { - namespace = "ci-test-scf" -} - data "tencentcloud_scf_namespaces" "foo" { - namespace = tencentcloud_scf_namespace.foo.id + namespace = "` + defaultScfNamespace + `" } ` const TestAccDataSourceTencentCloudScfNamespacesDesc = ` resource "tencentcloud_scf_namespace" "foo" { - namespace = "ci-test-scf" + namespace = "ci-test-desc-namespace" description = "test" } diff --git a/tencentcloud/resource_tc_scf_function.go b/tencentcloud/resource_tc_scf_function.go index 350269b419..119781399a 100644 --- a/tencentcloud/resource_tc_scf_function.go +++ b/tencentcloud/resource_tc_scf_function.go @@ -15,6 +15,24 @@ resource "tencentcloud_scf_function" "foo" { } ``` +Using CFS config +``` +resource "tencentcloud_scf_function" "foo" { + name = "ci-test-function" + handler = "main.do_it" + runtime = "Python3.6" + + cfs_config { + user_id = "10000" + user_group_id = "10000" + cfs_id = "cfs-xxxxxxxx" + mount_ins_id = "cfs-xxxxxxxx" + local_mount_dir = "/mnt" + remote_mount_dir = "/" + } +} +``` + Import SCF function can be imported, e.g. @@ -327,6 +345,62 @@ func resourceTencentCloudScfFunction() *schema.Resource { }, }, + //cfs config + "cfs_config": { + Type: schema.TypeList, + Optional: true, + Description: "List of CFS configurations.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_id": { + Type: schema.TypeString, + Required: true, + Description: "ID of user.", + }, + "user_group_id": { + Type: schema.TypeString, + Required: true, + Description: "ID of user group.", + }, + "cfs_id": { + Type: schema.TypeString, + Required: true, + Description: "File system instance ID.", + }, + "mount_ins_id": { + Type: schema.TypeString, + Required: true, + Description: "File system mount instance ID.", + }, + "local_mount_dir": { + Type: schema.TypeString, + Required: true, + Description: "Local mount directory.", + }, + "remote_mount_dir": { + Type: schema.TypeString, + Required: true, + Description: "Remote mount directory.", + }, + "ip_address": { + Type: schema.TypeString, + Computed: true, + Description: "(Readonly) File system ip address.", + }, + "mount_vpc_id": { + Type: schema.TypeString, + Computed: true, + Description: "(Readonly) File system virtual private network ID.", + }, + "mount_subnet_id": { + Type: schema.TypeString, + Computed: true, + Description: "(Readonly) File system subnet ID.", + }, + }, + }, + }, + // computed "modify_time": { Type: schema.TypeString, @@ -444,8 +518,6 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{} client := m.(*TencentCloudClient).apiV3Conn scfService := ScfService{client: client} - tagService := TagService{client: client} - region := client.Region var functionInfo scfFunctionInfo @@ -611,6 +683,42 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{} return errors.New("no function code set") } + if v, ok := d.GetOk("cfs_config"); ok { + configs := v.([]interface{}) + cfsList := make([]*scf.CfsInsInfo, 0, len(configs)) + + for i := range configs { + var ( + item = configs[i].(map[string]interface{}) + userId = item["user_id"].(string) + userGroupId = item["user_group_id"].(string) + cfsId = item["cfs_id"].(string) + mountInsId = item["mount_ins_id"].(string) + localMount = item["local_mount_dir"].(string) + remoteMount = item["remote_mount_dir"].(string) + ) + + cfsInfo := &scf.CfsInsInfo{ + UserId: &userId, + UserGroupId: &userGroupId, + CfsId: &cfsId, + MountInsId: &mountInsId, + LocalMountDir: &localMount, + RemoteMountDir: &remoteMount, + } + cfsList = append(cfsList, cfsInfo) + } + + functionInfo.cfsConfig = &scf.CfsConfig{ + CfsInsList: cfsList, + } + } + + // Pass tag as creation param instead of modify and time.Sleep + if tags := helper.GetTags(d, "tags"); len(tags) > 0 { + functionInfo.tags = tags + } + if err := scfService.CreateFunction(ctx, functionInfo); err != nil { log.Printf("[CRITAL]%s create function failed: %+v", logId, err) return err @@ -663,23 +771,12 @@ func resourceTencentCloudScfFunctionCreate(d *schema.ResourceData, m interface{} } } - resp, err := scfService.DescribeFunction(ctx, functionInfo.name, *functionInfo.namespace) + _, err = scfService.DescribeFunction(ctx, functionInfo.name, *functionInfo.namespace) if err != nil { log.Printf("[CRITAL]%s get function id failed: %+v", logId, err) return err } - if tags := helper.GetTags(d, "tags"); len(tags) > 0 { - resourceName := BuildTagResourceName(SCF_SERVICE, SCF_FUNCTION_RESOURCE, region, *resp.Response.FunctionId) - if err := tagService.ModifyTags(ctx, resourceName, tags, nil); err != nil { - log.Printf("[CRITAL]%s set function tags failed: %+v", logId, err) - return err - } - } - - // wait for tags add successfully - time.Sleep(time.Second) - return resourceTencentCloudScfFunctionRead(d, m) } @@ -757,6 +854,35 @@ func resourceTencentCloudScfFunctionRead(d *schema.ResourceData, m interface{}) _ = d.Set("enable_eip_config", *resp.PublicNetConfig.EipConfig.EipStatus == "ENABLE") } + if resp.CfsConfig != nil { + cfsList := make([]interface{}, 0, len(resp.CfsConfig.CfsInsList)) + for i := range resp.CfsConfig.CfsInsList { + item := resp.CfsConfig.CfsInsList[i] + cfs := map[string]interface{}{ + "user_id": item.UserId, + "user_group_id": item.UserGroupId, + "cfs_id": item.CfsId, + "mount_ins_id": item.MountInsId, + "local_mount_dir": item.LocalMountDir, + "remote_mount_dir": item.RemoteMountDir, + } + + if item.IpAddress != nil { + cfs["ip_address"] = item.IpAddress + } + if item.MountVpcId != nil { + cfs["mount_vpc_id"] = item.MountVpcId + } + if item.MountSubnetId != nil { + cfs["mount_subnet_id"] = item.MountSubnetId + } + cfsList = append(cfsList, cfs) + } + if err := d.Set("cfs_config", cfsList); err != nil { + return err + } + } + triggers := make([]map[string]interface{}, 0, len(resp.Triggers)) for _, trigger := range resp.Triggers { switch *trigger.Type { @@ -895,6 +1021,44 @@ func resourceTencentCloudScfFunctionUpdate(d *schema.ResourceData, m interface{} } } + if d.HasChange("cfs_config") { + updateAttrs = append(updateAttrs, "cfs_config") + if v, ok := d.GetOk("cfs_config"); ok { + configs := v.([]interface{}) + cfsList := make([]*scf.CfsInsInfo, 0, len(configs)) + + for i := range configs { + var ( + item = configs[i].(map[string]interface{}) + userId = item["user_id"].(string) + userGroupId = item["user_group_id"].(string) + cfsId = item["cfs_id"].(string) + mountInsId = item["mount_ins_id"].(string) + localMount = item["local_mount_dir"].(string) + remoteMount = item["remote_mount_dir"].(string) + ) + + cfsInfo := &scf.CfsInsInfo{ + UserId: &userId, + UserGroupId: &userGroupId, + CfsId: &cfsId, + MountInsId: &mountInsId, + LocalMountDir: &localMount, + RemoteMountDir: &remoteMount, + } + cfsList = append(cfsList, cfsInfo) + } + + functionInfo.cfsConfig = &scf.CfsConfig{ + CfsInsList: cfsList, + } + } else { + functionInfo.cfsConfig = &scf.CfsConfig{ + CfsInsList: []*scf.CfsInsInfo{}, + } + } + } + // update function code if len(updateAttrs) > 0 { if len(updateAttrs) == 0 && updateAttrs[0] == "handler" { diff --git a/tencentcloud/resource_tc_scf_function_test.go b/tencentcloud/resource_tc_scf_function_test.go index 074967429a..87e6da1629 100644 --- a/tencentcloud/resource_tc_scf_function_test.go +++ b/tencentcloud/resource_tc_scf_function_test.go @@ -11,6 +11,8 @@ import ( "strings" "testing" + sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/pkg/errors" @@ -185,7 +187,7 @@ func TestAccTencentCloudScfFunction_role(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "vpc_id", ""), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "subnet_id", ""), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "namespace", "default"), - resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "role", "scf-role-test"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "role", defaultScfRoleName1), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "cls_logset_id"), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "cls_topic_id"), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "l5_enable", "false"), @@ -208,7 +210,7 @@ func TestAccTencentCloudScfFunction_role(t *testing.T) { Config: scfFunctionCodeEmbed("first.zip", testAccScfFunctionRoleUpdate), Check: resource.ComposeTestCheckFunc( testAccCheckScfFunctionExists("tencentcloud_scf_function.foo", &fnId), - resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "role", "scf-role-test-new"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "role", defaultScfRoleName2), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "zip_file"), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "modify_time"), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "code_size"), @@ -276,17 +278,14 @@ func TestAccTencentCloudScfFunction_trigger(t *testing.T) { Config: scfFunctionCodeEmbed("first.zip", testAccScfFunctionTriggerUpdate), Check: resource.ComposeTestCheckFunc( testAccCheckScfFunctionExists("tencentcloud_scf_function.foo", &fnId), - resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "triggers.#", "2"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "triggers.#", "1"), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "modify_time"), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "status", SCF_FUNCTION_STATUS_ACTIVE), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "status_desc", ""), - resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "trigger_info.#", "2"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "trigger_info.#", "1"), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "trigger_info.0.enable", "true"), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "trigger_info.0.create_time"), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "trigger_info.0.modify_time"), - resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "trigger_info.1.enable", "true"), - resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "trigger_info.1.create_time"), - resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "trigger_info.1.modify_time"), ), }, }, @@ -314,7 +313,7 @@ func TestAccTencentCloudScfFunction_customNamespace(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "runtime", "Python3.6"), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "vpc_id", ""), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "subnet_id", ""), - resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "namespace", "ci-test-scf"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "namespace", defaultScfNamespace), resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "role", ""), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "cls_logset_id"), resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "cls_topic_id"), @@ -340,6 +339,63 @@ func TestAccTencentCloudScfFunction_customNamespace(t *testing.T) { }) } +func TestAccTencentCloudScfFunction_fs(t *testing.T) { + t.Parallel() + var fnId string + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckScfFunctionDestroy(&fnId), + Steps: []resource.TestStep{ + { + Config: scfFunctionCodeEmbed("first.zip", testAccScfFunctionCfsConfigs), + Check: resource.ComposeTestCheckFunc( + testAccCheckScfFunctionExists("tencentcloud_scf_function.foo", &fnId), + resource.TestMatchResourceAttr("tencentcloud_scf_function.foo", "name", regexp.MustCompile(`ci-test-function`)), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "vpc_id"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "subnet_id"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "zip_file"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "modify_time"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.0.user_id", "10000"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.0.user_group_id", "10000"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "cfs_config.0.cfs_id"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "cfs_config.0.mount_ins_id"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.0.local_mount_dir", "/mnt"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.0.remote_mount_dir", "/"), + ), + }, + { + Config: scfFunctionCodeEmbed("second.zip", testAccScfFunctionCfsConfigsUpdate), + Check: resource.ComposeTestCheckFunc( + testAccCheckScfFunctionExists("tencentcloud_scf_function.foo", &fnId), + resource.TestMatchResourceAttr("tencentcloud_scf_function.foo", "name", regexp.MustCompile(`ci-test-function`)), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "vpc_id"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "subnet_id"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "zip_file"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "modify_time"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.0.user_id", "10000"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.0.user_group_id", "10000"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "cfs_config.0.cfs_id"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_function.foo", "cfs_config.0.mount_ins_id"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.0.local_mount_dir", "/mnt"), + resource.TestCheckResourceAttr("tencentcloud_scf_function.foo", "cfs_config.0.remote_mount_dir", "/foo"), + ), + }, + { + ResourceName: "tencentcloud_scf_function.foo", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "zip_file", + }, + }, + }, + }) +} + func testAccCheckScfFunctionExists(n string, id *string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -384,6 +440,10 @@ func testAccCheckScfFunctionDestroy(id *string) resource.TestCheckFunc { fn, err := service.DescribeFunction(context.TODO(), name, namespace) if err != nil { + code := err.(*sdkErrors.TencentCloudSDKError).Code + if strings.HasPrefix(code, "ResourceNotFound") { + return nil + } return err } @@ -444,8 +504,7 @@ resource "tencentcloud_scf_function" "foo" { } ` -var testAccScfFunctionBasicUpdate = fmt.Sprintf( - defaultVpcVariable+` +var testAccScfFunctionBasicUpdate = fmt.Sprintf(defaultVpcVariable+` resource "tencentcloud_scf_function" "foo" { name = "%s" handler = "second.do_it_second" @@ -473,13 +532,9 @@ resource "tencentcloud_scf_function" "foo" { func testAccScfFunctionCosCode(codeSource string) string { return fmt.Sprintf(` -resource "tencentcloud_cos_bucket" "foo" { - bucket = "scf-cos-%s" - acl = "public-read" -} - +%s resource "tencentcloud_cos_bucket_object" "myobject" { - bucket = tencentcloud_cos_bucket.foo.bucket + bucket = local.bucket_name key = "/new_object_key.zip" source = "%s" acl = "public-read" @@ -491,33 +546,25 @@ resource "tencentcloud_scf_function" "foo" { runtime = "Python3.6" enable_public_net = true - cos_bucket_name = tencentcloud_cos_bucket.foo.id + cos_bucket_name = local.bucket_name cos_object_name = tencentcloud_cos_bucket_object.myobject.key cos_bucket_region = "ap-guangzhou" -}`, appid, codeSource) +}`, defaultSCFCosBucket, codeSource) } func testAccScfFunctionCosUpdateCode(codeSource string) string { return fmt.Sprintf(` -resource "tencentcloud_cos_bucket" "foo" { - bucket = "scf-cos-%s" - acl = "public-read" -} +%s resource "tencentcloud_cos_bucket_object" "myobject" { - bucket = tencentcloud_cos_bucket.foo.bucket + bucket = local.bucket_name key = "/new_object_key.zip" source = "%s" acl = "public-read" } -resource "tencentcloud_cos_bucket" "bar" { - bucket = "scf-cos2-%s" - acl = "public-read" -} - resource "tencentcloud_cos_bucket_object" "bar" { - bucket = tencentcloud_cos_bucket.bar.bucket + bucket = local.bucket_name key = "/new_code.zip" source = "%s" acl = "public-read" @@ -529,12 +576,15 @@ resource "tencentcloud_scf_function" "foo" { runtime = "Python3.6" enable_public_net = true - cos_bucket_name = tencentcloud_cos_bucket.bar.id + cos_bucket_name = local.bucket_name cos_object_name = tencentcloud_cos_bucket_object.bar.key cos_bucket_region = "ap-guangzhou" -}`, appid, codeSource, appid, codeSource, scfFunctionRandomName()) +}`, defaultSCFCosBucket, codeSource, codeSource, scfFunctionRandomName()) } +const defaultScfRoleName1 = "preset-scf-role" +const defaultScfRoleName2 = "preset-scf-role-new" + var testAccScfFunctionRole = fmt.Sprintf(` variable "role_document" { default = < 0 { + request.CfsConfig = info.cfsConfig + } + + if len(info.tags) > 0 { + for k, v := range info.tags { + request.Tags = append(request.Tags, &scf.Tag{ + Key: &k, + Value: &v, + }) + } + } + if err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) diff --git a/website/docs/d/scf_functions.html.markdown b/website/docs/d/scf_functions.html.markdown index 295eb4b02b..03bc114dac 100644 --- a/website/docs/d/scf_functions.html.markdown +++ b/website/docs/d/scf_functions.html.markdown @@ -53,6 +53,8 @@ In addition to all arguments above, the following attributes are exported: * `description` - Description of the SCF function. * `eip_fixed` - Whether EIP is a fixed IP. * `eips` - EIP list of the SCF function. + * `enable_eip_config` - Whether the EIP enabled. + * `enable_public_net` - Whether the public net enabled. * `environment` - Environment variable of the SCF function. * `err_no` - Errno of the SCF function. * `handler` - Handler of the SCF function. diff --git a/website/docs/r/scf_function.html.markdown b/website/docs/r/scf_function.html.markdown index 6648f5ada1..f73133cab4 100644 --- a/website/docs/r/scf_function.html.markdown +++ b/website/docs/r/scf_function.html.markdown @@ -25,6 +25,25 @@ resource "tencentcloud_scf_function" "foo" { } ``` +Using CFS config + +```hcl +resource "tencentcloud_scf_function" "foo" { + name = "ci-test-function" + handler = "main.do_it" + runtime = "Python3.6" + + cfs_config { + user_id = "10000" + user_group_id = "10000" + cfs_id = "cfs-xxxxxxxx" + mount_ins_id = "cfs-xxxxxxxx" + local_mount_dir = "/mnt" + remote_mount_dir = "/" + } +} +``` + ## Argument Reference The following arguments are supported: @@ -32,6 +51,7 @@ The following arguments are supported: * `handler` - (Required) Handler of the SCF function. The format of name is `.`, and it supports 26 English letters, numbers, connectors, and underscores, it should start with a letter. The last character cannot be `-` or `_`. Available length is 2-60. * `name` - (Required, ForceNew) Name of the SCF function. Name supports 26 English letters, numbers, connectors, and underscores, it should start with a letter. The last character cannot be `-` or `_`. Available length is 2-60. * `runtime` - (Required) Runtime of the SCF function, only supports `Python2.7`, `Python3.6`, `Nodejs6.10`, `Nodejs8.9`, `Nodejs10.15`, `PHP5`, `PHP7`, `Golang1`, and `Java8`. +* `cfs_config` - (Optional) List of CFS configurations. * `cls_logset_id` - (Optional) cls logset id of the SCF function. * `cls_topic_id` - (Optional) cls topic id of the SCF function. * `cos_bucket_name` - (Optional) Cos bucket name of the SCF function, such as `cos-1234567890`, conflict with `zip_file`. @@ -54,6 +74,15 @@ The following arguments are supported: * `vpc_id` - (Optional) VPC ID of the SCF function. * `zip_file` - (Optional) Zip file of the SCF function, conflict with `cos_bucket_name`, `cos_object_name`, `cos_bucket_region`. +The `cfs_config` object supports the following: + +* `cfs_id` - (Required) File system instance ID. +* `local_mount_dir` - (Required) Local mount directory. +* `mount_ins_id` - (Required) File system mount instance ID. +* `remote_mount_dir` - (Required) Remote mount directory. +* `user_group_id` - (Required) ID of user group. +* `user_id` - (Required) ID of user. + The `image_config` object supports the following: * `image_type` - (Required) The image type. personal or enterprise.