From d3a6ab1ae32628f17b9cbb57a3a176463b29c44c Mon Sep 17 00:00:00 2001 From: mikatong Date: Fri, 29 Nov 2024 17:28:23 +0800 Subject: [PATCH 1/2] support scf custom domain --- tencentcloud/provider.go | 1 + tencentcloud/provider.md | 1 + .../scf/resource_tc_scf_custom_domain.go | 490 ++++++++++++++++++ .../scf/resource_tc_scf_custom_domain.md | 27 + .../scf/resource_tc_scf_custom_domain_test.go | 105 ++++ .../services/scf/service_tencentcloud_scf.go | 25 + .../docs/r/scf_custom_domain.html.markdown | 80 +++ website/tencentcloud.erb | 3 + 8 files changed, 732 insertions(+) create mode 100644 tencentcloud/services/scf/resource_tc_scf_custom_domain.go create mode 100644 tencentcloud/services/scf/resource_tc_scf_custom_domain.md create mode 100644 tencentcloud/services/scf/resource_tc_scf_custom_domain_test.go create mode 100644 website/docs/r/scf_custom_domain.html.markdown diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 94820d1551..b1ebc9b4a0 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1445,6 +1445,7 @@ func Provider() *schema.Provider { "tencentcloud_scf_layer": scf.ResourceTencentCloudScfLayer(), "tencentcloud_scf_function_alias": scf.ResourceTencentCloudScfFunctionAlias(), "tencentcloud_scf_trigger_config": scf.ResourceTencentCloudScfTriggerConfig(), + "tencentcloud_scf_custom_domain": scf.ResourceTencentCloudScfCustomDomain(), "tencentcloud_tcaplus_cluster": tcaplusdb.ResourceTencentCloudTcaplusCluster(), "tencentcloud_tcaplus_tablegroup": tcaplusdb.ResourceTencentCloudTcaplusTableGroup(), "tencentcloud_tcaplus_idl": tcaplusdb.ResourceTencentCloudTcaplusIdl(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 2f559a1ee4..47ea634d00 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -972,6 +972,7 @@ Serverless Cloud Function(SCF) tencentcloud_scf_layer tencentcloud_scf_function_alias tencentcloud_scf_trigger_config + tencentcloud_scf_custom_domain SQLServer Data Source diff --git a/tencentcloud/services/scf/resource_tc_scf_custom_domain.go b/tencentcloud/services/scf/resource_tc_scf_custom_domain.go new file mode 100644 index 0000000000..c08ea7551c --- /dev/null +++ b/tencentcloud/services/scf/resource_tc_scf_custom_domain.go @@ -0,0 +1,490 @@ +package scf + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + scf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudScfCustomDomain() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudScfCustomDomainCreate, + Read: resourceTencentCloudScfCustomDomainRead, + Update: resourceTencentCloudScfCustomDomainUpdate, + Delete: resourceTencentCloudScfCustomDomainDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "domain": { + Type: schema.TypeString, + Required: true, + Description: "Domain names, pan-domain names are not supported.", + }, + + "protocol": { + Type: schema.TypeString, + Required: true, + Description: "Protocol, value range: HTTP, HTTPS, HTTP&HTTPS.", + }, + + "endpoints_config": { + Type: schema.TypeList, + Required: true, + Description: "Routing configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "namespace": { + Type: schema.TypeString, + Required: true, + Description: "Function namespace.", + }, + "function_name": { + Type: schema.TypeString, + Required: true, + Description: "Function name.", + }, + "qualifier": { + Type: schema.TypeString, + Required: true, + Description: "Function alias or version.", + }, + "path_match": { + Type: schema.TypeString, + Required: true, + Description: "Path, value specification: /,/*,/xxx,/xxx/a,/xxx/*.", + }, + "path_rewrite": { + Type: schema.TypeList, + Optional: true, + Description: "Path rewriting policy.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "path": { + Type: schema.TypeString, + Required: true, + Description: "Path that needs to be rerouted, value specification: /,/*,/xxx,/xxx/a,/xxx/*.", + }, + "type": { + Type: schema.TypeString, + Required: true, + Description: "Matching rules, value range: WildcardRules wildcard matching, ExactRules exact matching.", + }, + "rewrite": { + Type: schema.TypeString, + Required: true, + Description: "Replacement values: such as/, /$.", + }, + }, + }, + }, + }, + }, + }, + + "cert_config": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Description: "Certificate configuration information, required for HTTPS protocol.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "certificate_id": { + Type: schema.TypeString, + Optional: true, + Description: "SSL Certificates ID.", + }, + }, + }, + }, + + "waf_config": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Description: "Web Application Firewall Configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "waf_open": { + Type: schema.TypeString, + Optional: true, + Description: "Whether the Web Application Firewall is turned on, value range:OPEN, CLOSE.", + }, + "waf_instance_id": { + Type: schema.TypeString, + Optional: true, + Description: "Web Application Firewall Instance ID.", + }, + }, + }, + }, + }, + } +} + +func resourceTencentCloudScfCustomDomainCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_scf_custom_domain.create")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + var ( + domain string + ) + var ( + request = scf.NewCreateCustomDomainRequest() + response = scf.NewCreateCustomDomainResponse() + ) + + if v, ok := d.GetOk("domain"); ok { + domain = v.(string) + } + + if v, ok := d.GetOk("domain"); ok { + request.Domain = helper.String(v.(string)) + } + + if v, ok := d.GetOk("protocol"); ok { + request.Protocol = helper.String(v.(string)) + } + + if v, ok := d.GetOk("endpoints_config"); ok { + for _, item := range v.([]interface{}) { + endpointsConfigMap := item.(map[string]interface{}) + endpointsConf := scf.EndpointsConf{} + if v, ok := endpointsConfigMap["namespace"]; ok { + endpointsConf.Namespace = helper.String(v.(string)) + } + if v, ok := endpointsConfigMap["function_name"]; ok { + endpointsConf.FunctionName = helper.String(v.(string)) + } + if v, ok := endpointsConfigMap["qualifier"]; ok { + endpointsConf.Qualifier = helper.String(v.(string)) + } + if v, ok := endpointsConfigMap["path_match"]; ok { + endpointsConf.PathMatch = helper.String(v.(string)) + } + if v, ok := endpointsConfigMap["path_rewrite"]; ok { + for _, item := range v.([]interface{}) { + pathRewriteMap := item.(map[string]interface{}) + pathRewriteRule := scf.PathRewriteRule{} + if v, ok := pathRewriteMap["path"]; ok { + pathRewriteRule.Path = helper.String(v.(string)) + } + if v, ok := pathRewriteMap["type"]; ok { + pathRewriteRule.Type = helper.String(v.(string)) + } + if v, ok := pathRewriteMap["rewrite"]; ok { + pathRewriteRule.Rewrite = helper.String(v.(string)) + } + endpointsConf.PathRewrite = append(endpointsConf.PathRewrite, &pathRewriteRule) + } + } + request.EndpointsConfig = append(request.EndpointsConfig, &endpointsConf) + } + } + + if certConfigMap, ok := helper.InterfacesHeadMap(d, "cert_config"); ok { + certConf := scf.CertConf{} + if v, ok := certConfigMap["certificate_id"]; ok { + certConf.CertificateId = helper.String(v.(string)) + } + request.CertConfig = &certConf + } + + if wafConfigMap, ok := helper.InterfacesHeadMap(d, "waf_config"); ok { + wafConf := scf.WafConf{} + if v, ok := wafConfigMap["waf_open"]; ok { + wafConf.WafOpen = helper.String(v.(string)) + } + if v, ok := wafConfigMap["waf_instance_id"]; ok { + wafConf.WafInstanceId = helper.String(v.(string)) + } + request.WafConfig = &wafConf + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseScfClient().CreateCustomDomainWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s create scf custom domain failed, reason:%+v", logId, err) + return err + } + + _ = response + + d.SetId(domain) + + return resourceTencentCloudScfCustomDomainRead(d, meta) +} + +func resourceTencentCloudScfCustomDomainRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_scf_custom_domain.read")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + service := ScfService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + + domain := d.Id() + + _ = d.Set("domain", domain) + + respData, err := service.DescribeScfCustomDomainById(ctx, domain) + if err != nil { + return err + } + + if respData == nil { + d.SetId("") + log.Printf("[WARN]%s resource `scf_custom_domain` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + if respData.Domain != nil { + _ = d.Set("domain", respData.Domain) + } + + if respData.Protocol != nil { + _ = d.Set("protocol", respData.Protocol) + } + + endpointsConfigList := make([]map[string]interface{}, 0, len(respData.EndpointsConfig)) + if respData.EndpointsConfig != nil { + for _, endpointsConfig := range respData.EndpointsConfig { + endpointsConfigMap := map[string]interface{}{} + + if endpointsConfig.Namespace != nil { + endpointsConfigMap["namespace"] = endpointsConfig.Namespace + } + + if endpointsConfig.FunctionName != nil { + endpointsConfigMap["function_name"] = endpointsConfig.FunctionName + } + + if endpointsConfig.Qualifier != nil { + endpointsConfigMap["qualifier"] = endpointsConfig.Qualifier + } + + if endpointsConfig.PathMatch != nil { + endpointsConfigMap["path_match"] = endpointsConfig.PathMatch + } + + pathRewriteList := make([]map[string]interface{}, 0, len(endpointsConfig.PathRewrite)) + if endpointsConfig.PathRewrite != nil { + for _, pathRewrite := range endpointsConfig.PathRewrite { + pathRewriteMap := map[string]interface{}{} + + if pathRewrite.Path != nil { + pathRewriteMap["path"] = pathRewrite.Path + } + + if pathRewrite.Type != nil { + pathRewriteMap["type"] = pathRewrite.Type + } + + if pathRewrite.Rewrite != nil { + pathRewriteMap["rewrite"] = pathRewrite.Rewrite + } + + pathRewriteList = append(pathRewriteList, pathRewriteMap) + } + + endpointsConfigMap["path_rewrite"] = pathRewriteList + } + endpointsConfigList = append(endpointsConfigList, endpointsConfigMap) + } + + _ = d.Set("endpoints_config", endpointsConfigList) + } + + certConfigMap := map[string]interface{}{} + + if respData.CertConfig != nil { + if respData.CertConfig.CertificateId != nil { + certConfigMap["certificate_id"] = respData.CertConfig.CertificateId + } + + _ = d.Set("cert_config", []interface{}{certConfigMap}) + } + + wafConfigMap := map[string]interface{}{} + + if respData.WafConfig != nil { + if respData.WafConfig.WafOpen != nil { + wafConfigMap["waf_open"] = respData.WafConfig.WafOpen + } + + if respData.WafConfig.WafInstanceId != nil { + wafConfigMap["waf_instance_id"] = respData.WafConfig.WafInstanceId + } + + _ = d.Set("waf_config", []interface{}{wafConfigMap}) + } + + return nil +} + +func resourceTencentCloudScfCustomDomainUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_scf_custom_domain.update")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + immutableArgs := []string{"domain"} + for _, v := range immutableArgs { + if d.HasChange(v) { + return fmt.Errorf("argument `%s` cannot be changed", v) + } + } + domain := d.Id() + + needChange := false + mutableArgs := []string{"domain", "protocol", "cert_config", "waf_config", "endpoints_config"} + for _, v := range mutableArgs { + if d.HasChange(v) { + needChange = true + break + } + } + + if needChange { + request := scf.NewUpdateCustomDomainRequest() + + if v, ok := d.GetOk("domain"); ok { + request.Domain = helper.String(v.(string)) + } + + if v, ok := d.GetOk("protocol"); ok { + request.Protocol = helper.String(v.(string)) + } + + if certConfigMap, ok := helper.InterfacesHeadMap(d, "cert_config"); ok { + certConf := scf.CertConf{} + if v, ok := certConfigMap["certificate_id"]; ok { + certConf.CertificateId = helper.String(v.(string)) + } + request.CertConfig = &certConf + } + + if wafConfigMap, ok := helper.InterfacesHeadMap(d, "waf_config"); ok { + wafConf := scf.WafConf{} + if v, ok := wafConfigMap["waf_open"]; ok { + wafConf.WafOpen = helper.String(v.(string)) + } + if v, ok := wafConfigMap["waf_instance_id"]; ok { + wafConf.WafInstanceId = helper.String(v.(string)) + } + request.WafConfig = &wafConf + } + + if v, ok := d.GetOk("endpoints_config"); ok { + for _, item := range v.([]interface{}) { + endpointsConfigMap := item.(map[string]interface{}) + endpointsConf := scf.EndpointsConf{} + if v, ok := endpointsConfigMap["namespace"]; ok { + endpointsConf.Namespace = helper.String(v.(string)) + } + if v, ok := endpointsConfigMap["function_name"]; ok { + endpointsConf.FunctionName = helper.String(v.(string)) + } + if v, ok := endpointsConfigMap["qualifier"]; ok { + endpointsConf.Qualifier = helper.String(v.(string)) + } + if v, ok := endpointsConfigMap["path_match"]; ok { + endpointsConf.PathMatch = helper.String(v.(string)) + } + if v, ok := endpointsConfigMap["path_rewrite"]; ok { + for _, item := range v.([]interface{}) { + pathRewriteMap := item.(map[string]interface{}) + pathRewriteRule := scf.PathRewriteRule{} + if v, ok := pathRewriteMap["path"]; ok { + pathRewriteRule.Path = helper.String(v.(string)) + } + if v, ok := pathRewriteMap["type"]; ok { + pathRewriteRule.Type = helper.String(v.(string)) + } + if v, ok := pathRewriteMap["rewrite"]; ok { + pathRewriteRule.Rewrite = helper.String(v.(string)) + } + endpointsConf.PathRewrite = append(endpointsConf.PathRewrite, &pathRewriteRule) + } + } + request.EndpointsConfig = append(request.EndpointsConfig, &endpointsConf) + } + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseScfClient().UpdateCustomDomainWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s update scf custom domain failed, reason:%+v", logId, err) + return err + } + } + + _ = domain + return resourceTencentCloudScfCustomDomainRead(d, meta) +} + +func resourceTencentCloudScfCustomDomainDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_scf_custom_domain.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + domain := d.Id() + + var ( + request = scf.NewDeleteCustomDomainRequest() + response = scf.NewDeleteCustomDomainResponse() + ) + + request.Domain = helper.String(domain) + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseScfClient().DeleteCustomDomainWithContext(ctx, request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s delete scf custom domain failed, reason:%+v", logId, err) + return err + } + + _ = response + return nil +} diff --git a/tencentcloud/services/scf/resource_tc_scf_custom_domain.md b/tencentcloud/services/scf/resource_tc_scf_custom_domain.md new file mode 100644 index 0000000000..b7f8f6d97a --- /dev/null +++ b/tencentcloud/services/scf/resource_tc_scf_custom_domain.md @@ -0,0 +1,27 @@ +Provides a resource to create a scf custom domain + +Example Usage + +```hcl +resource "tencentcloud_scf_custom_domain" "scf_custom_domain" { + domain ="xxxxxx" + protocol = "HTTP" + endpoints_config { + namespace = "default" + function_name = "xxxxxx" + qualifier = "$LATEST" + path_match = "/aa/*" + } + waf_config { + waf_open = "CLOSE" + } +} +``` + +Import + +scf scf_custom_domain can be imported using the id, e.g. + +``` +terraform import tencentcloud_scf_custom_domain.scf_custom_domain ${domain} +``` diff --git a/tencentcloud/services/scf/resource_tc_scf_custom_domain_test.go b/tencentcloud/services/scf/resource_tc_scf_custom_domain_test.go new file mode 100644 index 0000000000..7ff2681bae --- /dev/null +++ b/tencentcloud/services/scf/resource_tc_scf_custom_domain_test.go @@ -0,0 +1,105 @@ +package scf_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudScfCustomDomainResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccScfCustomDomain, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_scf_custom_domain.scf_custom_domain", "id"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "domain", "scf.iac-tf.cloud"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "protocol", "HTTP"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "endpoints_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "endpoints_config.0.namespace", "default"), + resource.TestCheckResourceAttrSet("tencentcloud_scf_custom_domain.scf_custom_domain", "endpoints_config.0.function_name"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "endpoints_config.0.qualifier", "$LATEST"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "endpoints_config.0.path_match", "/a/*"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "waf_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "waf_config.0.waf_open", "CLOSE"), + ), + }, + { + Config: testAccScfCustomDomainUpdate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_scf_custom_domain.scf_custom_domain", "id"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "endpoints_config.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_scf_custom_domain.scf_custom_domain", "endpoints_config.0.path_match", "/aa/*"), + ), + }, + { + ResourceName: "tencentcloud_scf_custom_domain.scf_custom_domain", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccScfFunctionForCustomDomain = ` +resource "tencentcloud_scf_function" "foo" { + name = "%s" + handler = "first.do_it_first" + runtime = "Python3.6" + enable_public_net = true + async_run_enable = "FALSE" + + dns_cache = false + intranet_config { + ip_fixed = "DISABLE" + } + + zip_file = "%s" + triggers { + name = "url-trigger" + type = "http" + trigger_desc = "{\"AuthType\":\"NONE\",\"NetConfig\":{\"EnableIntranet\":true,\"EnableExtranet\":false}}" + } +} +` + +var testAccScfCustomDomain = scfFunctionCodeEmbed("first.zip", testAccScfFunctionForCustomDomain) + ` + +resource "tencentcloud_scf_custom_domain" "scf_custom_domain" { + domain ="scf.iac-tf.cloud" + protocol = "HTTP" + endpoints_config { + namespace = "default" + function_name = tencentcloud_scf_function.foo.name + qualifier = "$LATEST" + path_match = "/a/*" + } + waf_config { + waf_open = "CLOSE" + } +} +` + +var testAccScfCustomDomainUpdate = scfFunctionCodeEmbed("first.zip", testAccScfFunctionForCustomDomain) + ` + +resource "tencentcloud_scf_custom_domain" "scf_custom_domain" { + domain ="scf.iac-tf.cloud" + protocol = "HTTP" + endpoints_config { + namespace = "default" + function_name = tencentcloud_scf_function.foo.name + qualifier = "$LATEST" + path_match = "/aa/*" + } + waf_config { + waf_open = "CLOSE" + } +} +` diff --git a/tencentcloud/services/scf/service_tencentcloud_scf.go b/tencentcloud/services/scf/service_tencentcloud_scf.go index 1dc6f9bdd8..9328587339 100644 --- a/tencentcloud/services/scf/service_tencentcloud_scf.go +++ b/tencentcloud/services/scf/service_tencentcloud_scf.go @@ -1400,3 +1400,28 @@ func (me *ScfService) DescribeScfTriggerConfigById(ctx context.Context, function triggerConfig = instances[0] return } + +func (me *ScfService) DescribeScfCustomDomainById(ctx context.Context, domain string) (ret *scf.GetCustomDomainResponseParams, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := scf.NewGetCustomDomainRequest() + request.Domain = helper.String(domain) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseScfClient().GetCustomDomain(request) + if err != nil { + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + ret = response.Response + return +} diff --git a/website/docs/r/scf_custom_domain.html.markdown b/website/docs/r/scf_custom_domain.html.markdown new file mode 100644 index 0000000000..991be49661 --- /dev/null +++ b/website/docs/r/scf_custom_domain.html.markdown @@ -0,0 +1,80 @@ +--- +subcategory: "Serverless Cloud Function(SCF)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_scf_custom_domain" +sidebar_current: "docs-tencentcloud-resource-scf_custom_domain" +description: |- + Provides a resource to create a scf custom domain +--- + +# tencentcloud_scf_custom_domain + +Provides a resource to create a scf custom domain + +## Example Usage + +```hcl +resource "tencentcloud_scf_custom_domain" "scf_custom_domain" { + domain = "xxxxxx" + protocol = "HTTP" + endpoints_config { + namespace = "default" + function_name = "xxxxxx" + qualifier = "$LATEST" + path_match = "/aa/*" + } + waf_config { + waf_open = "CLOSE" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `domain` - (Required, String) Domain names, pan-domain names are not supported. +* `endpoints_config` - (Required, List) Routing configuration. +* `protocol` - (Required, String) Protocol, value range: HTTP, HTTPS, HTTP&HTTPS. +* `cert_config` - (Optional, List) Certificate configuration information, required for HTTPS protocol. +* `waf_config` - (Optional, List) Web Application Firewall Configuration. + +The `cert_config` object supports the following: + +* `certificate_id` - (Optional, String) SSL Certificates ID. + +The `endpoints_config` object supports the following: + +* `function_name` - (Required, String) Function name. +* `namespace` - (Required, String) Function namespace. +* `path_match` - (Required, String) Path, value specification: /,/*,/xxx,/xxx/a,/xxx/*. +* `qualifier` - (Required, String) Function alias or version. +* `path_rewrite` - (Optional, List) Path rewriting policy. + +The `path_rewrite` object of `endpoints_config` supports the following: + +* `path` - (Required, String) Path that needs to be rerouted, value specification: /,/*,/xxx,/xxx/a,/xxx/*. +* `rewrite` - (Required, String) Replacement values: such as/, /$. +* `type` - (Required, String) Matching rules, value range: WildcardRules wildcard matching, ExactRules exact matching. + +The `waf_config` object supports the following: + +* `waf_instance_id` - (Optional, String) Web Application Firewall Instance ID. +* `waf_open` - (Optional, String) Whether the Web Application Firewall is turned on, value range:OPEN, CLOSE. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +scf scf_custom_domain can be imported using the id, e.g. + +``` +terraform import tencentcloud_scf_custom_domain.scf_custom_domain ${domain} +``` + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 243803c04c..96792cb595 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -3755,6 +3755,9 @@
  • Resources