From 018a721abdc3d88d6be2c29c571e374bf330200a Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 5 Nov 2025 17:17:45 +0800 Subject: [PATCH 1/3] add --- tencentcloud/provider.go | 3 +- tencentcloud/provider.md | 1 + .../clb/resource_tc_clb_cls_log_attachment.go | 193 ++++++++++++++++++ .../clb/resource_tc_clb_cls_log_attachment.md | 16 ++ ...resource_tc_clb_cls_log_attachment_test.go | 33 +++ .../services/clb/resource_tc_clb_log_topic.go | 75 ++++++- .../services/clb/resource_tc_clb_log_topic.md | 12 +- .../services/clb/service_tencentcloud_clb.go | 39 ++++ .../r/clb_cls_log_attachment.html.markdown | 48 +++++ website/docs/r/clb_log_topic.html.markdown | 16 +- website/tencentcloud.erb | 3 + 11 files changed, 417 insertions(+), 22 deletions(-) create mode 100644 tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.go create mode 100644 tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.md create mode 100644 tencentcloud/services/clb/resource_tc_clb_cls_log_attachment_test.go create mode 100644 website/docs/r/clb_cls_log_attachment.html.markdown diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 93f69699fa..0e53fb0c61 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1448,6 +1448,8 @@ func Provider() *schema.Provider { "tencentcloud_clb_instance_sla_config": clb.ResourceTencentCloudClbInstanceSlaConfig(), "tencentcloud_clb_replace_cert_for_lbs": clb.ResourceTencentCloudClbReplaceCertForLbs(), "tencentcloud_clb_security_group_attachment": clb.ResourceTencentCloudClbSecurityGroupAttachment(), + "tencentcloud_clb_target_group_attachments": clb.ResourceTencentCloudClbTargetGroupAttachments(), + "tencentcloud_clb_cls_log_attachment": clb.ResourceTencentCloudClbClsLogAttachment(), "tencentcloud_gwlb_instance": gwlb.ResourceTencentCloudGwlbInstance(), "tencentcloud_gwlb_target_group": gwlb.ResourceTencentCloudGwlbTargetGroup(), "tencentcloud_gwlb_instance_associate_target_group": gwlb.ResourceTencentCloudGwlbInstanceAssociateTargetGroup(), @@ -2412,7 +2414,6 @@ func Provider() *schema.Provider { "tencentcloud_cdwpg_userhba": cdwpg.ResourceTencentCloudCdwpgUserhba(), "tencentcloud_clickhouse_keyval_config": cdwch.ResourceTencentCloudClickhouseKeyvalConfig(), "tencentcloud_clickhouse_xml_config": cdwch.ResourceTencentCloudClickhouseXmlConfig(), - "tencentcloud_clb_target_group_attachments": clb.ResourceTencentCloudClbTargetGroupAttachments(), "tencentcloud_vpc_peer_connect_manager": vpc.ResourceTencentCloudVpcPeerConnectManager(), "tencentcloud_vpc_peer_connect_accept_operation": vpc.ResourceTencentCloudVpcPeerConnectAcceptOperation(), "tencentcloud_vpc_peer_connect_reject_operation": vpc.ResourceTencentCloudVpcPeerConnectRejectOperation(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index c26b0b41fa..e2ba060464 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -418,6 +418,7 @@ tencentcloud_clb_instance_sla_config tencentcloud_clb_instance_mix_ip_target_config tencentcloud_clb_replace_cert_for_lbs tencentcloud_clb_security_group_attachment +tencentcloud_clb_cls_log_attachment Cloud Object Storage(COS) Data Source diff --git a/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.go b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.go new file mode 100644 index 0000000000..cc2efecaab --- /dev/null +++ b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.go @@ -0,0 +1,193 @@ +package clb + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + clbv20180317 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudClbClsLogAttachment() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudClbClsLogAttachmentCreate, + Read: resourceTencentCloudClbClsLogAttachmentRead, + Delete: resourceTencentCloudClbClsLogAttachmentDelete, + Schema: map[string]*schema.Schema{ + "load_balancer_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "CLB instance ID.", + }, + + "log_set_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Logset ID of the Cloud Log Service (CLS).
  • When adding or updating a log topic, call the [DescribeLogsets](https://intl.cloud.tencent.com/document/product/614/58624?from_cn_redirect=1) API to obtain the logset ID.
  • When deleting a log topic, set this parameter to null.
  • .", + }, + + "log_topic_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Log topic ID of the CLS.
  • When adding or updating a log topic, call the [DescribeTopics](https://intl.cloud.tencent.com/document/product/614/56454?from_cn_redirect=1) API to obtain the log topic ID.
  • When deleting a log topic, set this parameter to null.
  • .", + }, + + "log_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + Description: "Log type:\n
  • `ACCESS`: access logs
  • \n
  • `HEALTH`: health check logs
  • \nDefault: `ACCESS`.", + }, + }, + } +} + +func resourceTencentCloudClbClsLogAttachmentCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_cls_log_attachment.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = clbv20180317.NewSetLoadBalancerClsLogRequest() + loadBalancerId string + logSetId string + logTopicId string + ) + + if v, ok := d.GetOk("load_balancer_id"); ok { + request.LoadBalancerId = helper.String(v.(string)) + loadBalancerId = v.(string) + } + + if v, ok := d.GetOk("log_set_id"); ok { + request.LogSetId = helper.String(v.(string)) + logSetId = v.(string) + } + + if v, ok := d.GetOk("log_topic_id"); ok { + request.LogTopicId = helper.String(v.(string)) + logTopicId = v.(string) + } + + if v, ok := d.GetOk("log_type"); ok { + request.LogType = helper.String(v.(string)) + } + + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().SetLoadBalancerClsLogWithContext(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 reqErr != nil { + log.Printf("[CRITAL]%s create clb cls log attachment failed, reason:%+v", logId, reqErr) + return reqErr + } + + d.SetId(strings.Join([]string{loadBalancerId, logSetId, logTopicId}, tccommon.FILED_SP)) + return resourceTencentCloudClbClsLogAttachmentRead(d, meta) +} + +func resourceTencentCloudClbClsLogAttachmentRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_cls_log_attachment.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = ClbService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 3 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + loadBalancerId := idSplit[0] + logSetId := idSplit[1] + logTopicId := idSplit[2] + + respData, err := service.DescribeClbClsLogAttachmentById(ctx, loadBalancerId, logSetId, logTopicId) + if err != nil { + return err + } + + if respData == nil { + log.Printf("[WARN]%s resource `tencentcloud_clb_cls_log_attachment` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + d.SetId("") + return nil + } + + if respData.LoadBalancerId != nil { + _ = d.Set("load_balancer_id", respData.LoadBalancerId) + } + + if respData.LogSetId != nil && respData.LogTopicId != nil { + _ = d.Set("log_set_id", respData.LogSetId) + _ = d.Set("log_topic_id", respData.LogTopicId) + _ = d.Set("log_type", "ACCESS") + } + + if respData.HealthLogSetId != nil && respData.HealthLogTopicId != nil { + _ = d.Set("log_set_id", respData.HealthLogSetId) + _ = d.Set("log_topic_id", respData.HealthLogTopicId) + _ = d.Set("log_type", "HEALTH") + } + + return nil +} + +func resourceTencentCloudClbClsLogAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_cls_log_attachment.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = clbv20180317.NewSetLoadBalancerClsLogRequest() + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 3 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + loadBalancerId := idSplit[0] + + request.LoadBalancerId = &loadBalancerId + request.LogSetId = helper.String("") + request.LogTopicId = helper.String("") + reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().SetLoadBalancerClsLogWithContext(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 reqErr != nil { + log.Printf("[CRITAL]%s delete clb cls log attachment failed, reason:%+v", logId, reqErr) + return reqErr + } + + return nil +} diff --git a/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.md b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.md new file mode 100644 index 0000000000..086e561c72 --- /dev/null +++ b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.md @@ -0,0 +1,16 @@ +Provides a resource to create a clb clb_cls_log_attachment + +Example Usage + +```hcl +resource "tencentcloud_clb_cls_log_attachment" "clb_cls_log_attachment" { +} +``` + +Import + +clb clb_cls_log_attachment can be imported using the id, e.g. + +``` +terraform import tencentcloud_clb_cls_log_attachment.clb_cls_log_attachment clb_cls_log_attachment_id +``` diff --git a/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment_test.go b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment_test.go new file mode 100644 index 0000000000..ccaf5c0824 --- /dev/null +++ b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment_test.go @@ -0,0 +1,33 @@ +package clb_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudClbClsLogAttachmentResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccClbClsLogAttachment, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_clb_cls_log_attachment.clb_cls_log_attachment", "id")), + }, { + ResourceName: "tencentcloud_clb_cls_log_attachment.clb_cls_log_attachment", + ImportState: true, + ImportStateVerify: true, + }}, + }) +} + +const testAccClbClsLogAttachment = ` + +resource "tencentcloud_clb_cls_log_attachment" "clb_cls_log_attachment" { +} +` diff --git a/tencentcloud/services/clb/resource_tc_clb_log_topic.go b/tencentcloud/services/clb/resource_tc_clb_log_topic.go index 80660be692..c253138197 100644 --- a/tencentcloud/services/clb/resource_tc_clb_log_topic.go +++ b/tencentcloud/services/clb/resource_tc_clb_log_topic.go @@ -7,9 +7,13 @@ import ( "sync" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" svccls "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cls" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + cls "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016" ) var clsActionMu = &sync.Mutex{} @@ -18,6 +22,7 @@ func ResourceTencentCloudClbLogTopic() *schema.Resource { return &schema.Resource{ Create: resourceTencentCloudClbInstanceTopicCreate, Read: resourceTencentCloudClbInstanceTopicRead, + Update: resourceTencentCloudClbInstanceTopicUpdate, Delete: resourceTencentCloudClbInstanceTopicDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -36,18 +41,13 @@ func ResourceTencentCloudClbLogTopic() *schema.Resource { ForceNew: true, Description: "Log topic of CLB instance.", }, - //"partition_count": { - // Type: schema.TypeInt, - // Optional: true, - // ValidateFunc: tccommon.ValidateIntegerInRange(1, 10), - // Description: "Topic partition count of CLB instance.(Default 1).", - //}, - //compute "status": { Type: schema.TypeBool, + Optional: true, Computed: true, - Description: "The status of log topic.", + Description: "The status of log topic. true: enable; false: disable. Default is true.", }, + //compute "create_time": { Type: schema.TypeString, Computed: true, @@ -88,7 +88,32 @@ func resourceTencentCloudClbInstanceTopicCreate(d *schema.ResourceData, meta int log.Printf("[CRITAL]%s create clb topic failed, reason:%+v", logId, err) return err } - d.SetId(*resp.Response.TopicId) + + topicId := *resp.Response.TopicId + d.SetId(topicId) + + if v, ok := d.GetOkExists("status"); ok { + if !v.(bool) { + request := cls.NewModifyTopicRequest() + request.TopicId = &topicId + request.Status = helper.Bool(false) + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().ModifyTopic(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 { + return err + } + } + } + return resourceTencentCloudClbInstanceTopicRead(d, meta) } @@ -113,7 +138,39 @@ func resourceTencentCloudClbInstanceTopicRead(d *schema.ResourceData, meta inter _ = d.Set("create_time", res.CreateTime) _ = d.Set("status", res.Status) return nil +} + +func resourceTencentCloudClbInstanceTopicUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_clb_log_topic.update")() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + topicId = d.Id() + ) + + if d.HasChange("status") { + if v, ok := d.GetOkExists("status"); ok { + request := cls.NewModifyTopicRequest() + request.TopicId = &topicId + request.Status = helper.Bool(v.(bool)) + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsClient().ModifyTopic(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 { + return err + } + } + } + + return resourceTencentCloudClbInstanceTopicRead(d, meta) } func resourceTencentCloudClbInstanceTopicDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/tencentcloud/services/clb/resource_tc_clb_log_topic.md b/tencentcloud/services/clb/resource_tc_clb_log_topic.md index 09035ea5d4..9927f180eb 100644 --- a/tencentcloud/services/clb/resource_tc_clb_log_topic.md +++ b/tencentcloud/services/clb/resource_tc_clb_log_topic.md @@ -1,11 +1,12 @@ -Provides a resource to create a CLB instance topic. +Provides a resource to create a CLB log topic. Example Usage ```hcl -resource "tencentcloud_clb_log_topic" "topic" { - log_set_id = "${tencentcloud_clb_log_set.set.id}" - topic_name = "clb-topic" +resource "tencentcloud_clb_log_topic" "example" { + log_set_id = "2ed70190-bf06-4777-980d-2d8a327a2554" + topic_name = "tf-example" + status = true } ``` @@ -14,4 +15,5 @@ Import CLB log topic can be imported using the id, e.g. ``` -$ terraform import tencentcloud_clb_log_topic.topic lb-7a0t6zqb \ No newline at end of file +terraform import tencentcloud_clb_log_topic.example be1a83dd-04b4-4807-89bf-8daddce0df71 +``` diff --git a/tencentcloud/services/clb/service_tencentcloud_clb.go b/tencentcloud/services/clb/service_tencentcloud_clb.go index 7c946aea04..92a4d3684e 100644 --- a/tencentcloud/services/clb/service_tencentcloud_clb.go +++ b/tencentcloud/services/clb/service_tencentcloud_clb.go @@ -2593,3 +2593,42 @@ func (me *ClbService) DescribeDescribeCustomizedConfigAssociateListById(ctx cont return } + +func (me *ClbService) DescribeClbClsLogAttachmentById(ctx context.Context, loadBalancerId, logSetId, logTopicId string) (ret *clb.LoadBalancer, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := clb.NewDescribeLoadBalancersRequest() + response := clb.NewDescribeLoadBalancersResponse() + request.LoadBalancerIds = []*string{&loadBalancerId} + + 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()) + } + }() + + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseClbClient().DescribeLoadBalancers(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()) + } + + if result == nil || result.Response == nil || result.Response.LoadBalancerSet == nil || len(result.Response.LoadBalancerSet) < 1 { + return resource.NonRetryableError(fmt.Errorf("Describe load balancers failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + ret = response.Response.LoadBalancerSet[0] + return +} diff --git a/website/docs/r/clb_cls_log_attachment.html.markdown b/website/docs/r/clb_cls_log_attachment.html.markdown new file mode 100644 index 0000000000..75851bfe7b --- /dev/null +++ b/website/docs/r/clb_cls_log_attachment.html.markdown @@ -0,0 +1,48 @@ +--- +subcategory: "Cloud Load Balancer(CLB)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_clb_cls_log_attachment" +sidebar_current: "docs-tencentcloud-resource-clb_cls_log_attachment" +description: |- + Provides a resource to create a clb clb_cls_log_attachment +--- + +# tencentcloud_clb_cls_log_attachment + +Provides a resource to create a clb clb_cls_log_attachment + +## Example Usage + +```hcl +resource "tencentcloud_clb_cls_log_attachment" "clb_cls_log_attachment" { +} +``` + +## Argument Reference + +The following arguments are supported: + +* `load_balancer_id` - (Required, String, ForceNew) CLB instance ID. +* `log_set_id` - (Required, String, ForceNew) Logset ID of the Cloud Log Service (CLS).
  • When adding or updating a log topic, call the [DescribeLogsets](https://intl.cloud.tencent.com/document/product/614/58624?from_cn_redirect=1) API to obtain the logset ID.
  • When deleting a log topic, set this parameter to null.
  • . +* `log_topic_id` - (Required, String, ForceNew) Log topic ID of the CLS.
  • When adding or updating a log topic, call the [DescribeTopics](https://intl.cloud.tencent.com/document/product/614/56454?from_cn_redirect=1) API to obtain the log topic ID.
  • When deleting a log topic, set this parameter to null.
  • . +* `log_type` - (Optional, String, ForceNew) Log type: +
  • `ACCESS`: access logs
  • +
  • `HEALTH`: health check logs
  • +Default: `ACCESS`. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +clb clb_cls_log_attachment can be imported using the id, e.g. + +``` +terraform import tencentcloud_clb_cls_log_attachment.clb_cls_log_attachment clb_cls_log_attachment_id +``` + diff --git a/website/docs/r/clb_log_topic.html.markdown b/website/docs/r/clb_log_topic.html.markdown index 004e251977..eeadcf12c5 100644 --- a/website/docs/r/clb_log_topic.html.markdown +++ b/website/docs/r/clb_log_topic.html.markdown @@ -4,19 +4,20 @@ layout: "tencentcloud" page_title: "TencentCloud: tencentcloud_clb_log_topic" sidebar_current: "docs-tencentcloud-resource-clb_log_topic" description: |- - Provides a resource to create a CLB instance topic. + Provides a resource to create a CLB log topic. --- # tencentcloud_clb_log_topic -Provides a resource to create a CLB instance topic. +Provides a resource to create a CLB log topic. ## Example Usage ```hcl -resource "tencentcloud_clb_log_topic" "topic" { - log_set_id = "${tencentcloud_clb_log_set.set.id}" - topic_name = "clb-topic" +resource "tencentcloud_clb_log_topic" "example" { + log_set_id = "2ed70190-bf06-4777-980d-2d8a327a2554" + topic_name = "tf-example" + status = true } ``` @@ -26,6 +27,7 @@ The following arguments are supported: * `log_set_id` - (Required, String, ForceNew) Log topic of CLB instance. * `topic_name` - (Required, String, ForceNew) Log topic of CLB instance. +* `status` - (Optional, Bool) The status of log topic. true: enable; false: disable. Default is true. ## Attributes Reference @@ -33,7 +35,6 @@ In addition to all arguments above, the following attributes are exported: * `id` - ID of the resource. * `create_time` - Log topic creation time. -* `status` - The status of log topic. ## Import @@ -41,5 +42,6 @@ In addition to all arguments above, the following attributes are exported: CLB log topic can be imported using the id, e.g. ``` -$ terraform import tencentcloud_clb_log_topic.topic lb-7a0t6zqb +terraform import tencentcloud_clb_log_topic.example be1a83dd-04b4-4807-89bf-8daddce0df71 +``` diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 04b0970431..97bb64778f 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -1480,6 +1480,9 @@
  • tencentcloud_clb_attachment
  • +
  • + tencentcloud_clb_cls_log_attachment +
  • tencentcloud_clb_customized_config
  • From 26902df682a320206a947779288943d5ae3823cb Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 5 Nov 2025 17:19:44 +0800 Subject: [PATCH 2/3] add --- .changelog/3584.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changelog/3584.txt diff --git a/.changelog/3584.txt b/.changelog/3584.txt new file mode 100644 index 0000000000..3ae9030b14 --- /dev/null +++ b/.changelog/3584.txt @@ -0,0 +1,7 @@ +```release-note:new-resource +tencentcloud_clb_cls_log_attachment +``` + +```release-note:enhancement +resource/tencentcloud_clb_log_topic: support `status` +``` From c3779f7c2ae935344791f673c07776a63e0b5584 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Thu, 6 Nov 2025 14:36:07 +0800 Subject: [PATCH 3/3] add --- .../clb/resource_tc_clb_cls_log_attachment.go | 43 +++++++++++-------- .../clb/resource_tc_clb_cls_log_attachment.md | 17 ++++++-- .../r/clb_cls_log_attachment.html.markdown | 23 ++++++---- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.go b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.go index cc2efecaab..40316f188f 100644 --- a/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.go +++ b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.go @@ -19,6 +19,9 @@ func ResourceTencentCloudClbClsLogAttachment() *schema.Resource { Create: resourceTencentCloudClbClsLogAttachmentCreate, Read: resourceTencentCloudClbClsLogAttachmentRead, Delete: resourceTencentCloudClbClsLogAttachmentDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "load_balancer_id": { Type: schema.TypeString, @@ -41,13 +44,13 @@ func ResourceTencentCloudClbClsLogAttachment() *schema.Resource { Description: "Log topic ID of the CLS.
  • When adding or updating a log topic, call the [DescribeTopics](https://intl.cloud.tencent.com/document/product/614/56454?from_cn_redirect=1) API to obtain the log topic ID.
  • When deleting a log topic, set this parameter to null.
  • .", }, - "log_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - Description: "Log type:\n
  • `ACCESS`: access logs
  • \n
  • `HEALTH`: health check logs
  • \nDefault: `ACCESS`.", - }, + // "log_type": { + // Type: schema.TypeString, + // Optional: true, + // ForceNew: true, + // Computed: true, + // Description: "Log type:\n
  • `ACCESS`: access logs
  • \n
  • `HEALTH`: health check logs
  • \nDefault: `ACCESS`.", + // }, }, } } @@ -80,9 +83,9 @@ func resourceTencentCloudClbClsLogAttachmentCreate(d *schema.ResourceData, meta logTopicId = v.(string) } - if v, ok := d.GetOk("log_type"); ok { - request.LogType = helper.String(v.(string)) - } + // if v, ok := d.GetOk("log_type"); ok { + // request.LogType = helper.String(v.(string)) + // } reqErr := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClbClient().SetLoadBalancerClsLogWithContext(ctx, request) @@ -139,16 +142,20 @@ func resourceTencentCloudClbClsLogAttachmentRead(d *schema.ResourceData, meta in } if respData.LogSetId != nil && respData.LogTopicId != nil { - _ = d.Set("log_set_id", respData.LogSetId) - _ = d.Set("log_topic_id", respData.LogTopicId) - _ = d.Set("log_type", "ACCESS") + if *respData.LogSetId == logSetId && *respData.LogTopicId == logTopicId { + _ = d.Set("log_set_id", respData.LogSetId) + _ = d.Set("log_topic_id", respData.LogTopicId) + // _ = d.Set("log_type", "ACCESS") + } } - if respData.HealthLogSetId != nil && respData.HealthLogTopicId != nil { - _ = d.Set("log_set_id", respData.HealthLogSetId) - _ = d.Set("log_topic_id", respData.HealthLogTopicId) - _ = d.Set("log_type", "HEALTH") - } + // if respData.HealthLogSetId != nil && respData.HealthLogTopicId != nil { + // if *respData.HealthLogSetId == logSetId && *respData.HealthLogTopicId == logTopicId { + // _ = d.Set("log_set_id", respData.HealthLogSetId) + // _ = d.Set("log_topic_id", respData.HealthLogTopicId) + // _ = d.Set("log_type", "HEALTH") + // } + // } return nil } diff --git a/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.md b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.md index 086e561c72..ddaac7372b 100644 --- a/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.md +++ b/tencentcloud/services/clb/resource_tc_clb_cls_log_attachment.md @@ -1,16 +1,25 @@ -Provides a resource to create a clb clb_cls_log_attachment +Provides a resource to create a CLB cls log attachment Example Usage ```hcl -resource "tencentcloud_clb_cls_log_attachment" "clb_cls_log_attachment" { +resource "tencentcloud_clb_log_topic" "example" { + log_set_id = "2ed70190-bf06-4777-980d-2d8a327a2554" + topic_name = "tf-example" + status = true +} + +resource "tencentcloud_clb_cls_log_attachment" "example" { + load_balancer_id = "lb-n26tx0bm" + log_set_id = "2ed70190-bf06-4777-980d-2d8a327a2554" + log_topic_id = tencentcloud_clb_log_topic.example.id } ``` Import -clb clb_cls_log_attachment can be imported using the id, e.g. +CLB cls log attachment can be imported using the loadBalancerId#logSetId#logTopicId, e.g. ``` -terraform import tencentcloud_clb_cls_log_attachment.clb_cls_log_attachment clb_cls_log_attachment_id +terraform import tencentcloud_clb_cls_log_attachment.example lb-n26tx0bm#2ed70190-bf06-4777-980d-2d8a327a2554#ac2fda28-3e79-4b51-b193-bfcf1aeece24 ``` diff --git a/website/docs/r/clb_cls_log_attachment.html.markdown b/website/docs/r/clb_cls_log_attachment.html.markdown index 75851bfe7b..96f46c3715 100644 --- a/website/docs/r/clb_cls_log_attachment.html.markdown +++ b/website/docs/r/clb_cls_log_attachment.html.markdown @@ -4,17 +4,26 @@ layout: "tencentcloud" page_title: "TencentCloud: tencentcloud_clb_cls_log_attachment" sidebar_current: "docs-tencentcloud-resource-clb_cls_log_attachment" description: |- - Provides a resource to create a clb clb_cls_log_attachment + Provides a resource to create a CLB cls log attachment --- # tencentcloud_clb_cls_log_attachment -Provides a resource to create a clb clb_cls_log_attachment +Provides a resource to create a CLB cls log attachment ## Example Usage ```hcl -resource "tencentcloud_clb_cls_log_attachment" "clb_cls_log_attachment" { +resource "tencentcloud_clb_log_topic" "example" { + log_set_id = "2ed70190-bf06-4777-980d-2d8a327a2554" + topic_name = "tf-example" + status = true +} + +resource "tencentcloud_clb_cls_log_attachment" "example" { + load_balancer_id = "lb-n26tx0bm" + log_set_id = "2ed70190-bf06-4777-980d-2d8a327a2554" + log_topic_id = tencentcloud_clb_log_topic.example.id } ``` @@ -25,10 +34,6 @@ The following arguments are supported: * `load_balancer_id` - (Required, String, ForceNew) CLB instance ID. * `log_set_id` - (Required, String, ForceNew) Logset ID of the Cloud Log Service (CLS).
  • When adding or updating a log topic, call the [DescribeLogsets](https://intl.cloud.tencent.com/document/product/614/58624?from_cn_redirect=1) API to obtain the logset ID.
  • When deleting a log topic, set this parameter to null.
  • . * `log_topic_id` - (Required, String, ForceNew) Log topic ID of the CLS.
  • When adding or updating a log topic, call the [DescribeTopics](https://intl.cloud.tencent.com/document/product/614/56454?from_cn_redirect=1) API to obtain the log topic ID.
  • When deleting a log topic, set this parameter to null.
  • . -* `log_type` - (Optional, String, ForceNew) Log type: -
  • `ACCESS`: access logs
  • -
  • `HEALTH`: health check logs
  • -Default: `ACCESS`. ## Attributes Reference @@ -40,9 +45,9 @@ In addition to all arguments above, the following attributes are exported: ## Import -clb clb_cls_log_attachment can be imported using the id, e.g. +CLB cls log attachment can be imported using the loadBalancerId#logSetId#logTopicId, e.g. ``` -terraform import tencentcloud_clb_cls_log_attachment.clb_cls_log_attachment clb_cls_log_attachment_id +terraform import tencentcloud_clb_cls_log_attachment.example lb-n26tx0bm#2ed70190-bf06-4777-980d-2d8a327a2554#ac2fda28-3e79-4b51-b193-bfcf1aeece24 ```