diff --git a/.changelog/3335.txt b/.changelog/3335.txt new file mode 100644 index 0000000000..df47bb6b29 --- /dev/null +++ b/.changelog/3335.txt @@ -0,0 +1,7 @@ +```release-note:new-resource +tencentcloud_cls_cloud_product_log_task_v2 +``` + +```release-note:enhancement +resource/tencentcloud_cls_cloud_product_log_task: This resource has been deprecated in Terraform TencentCloud provider version 1.81.188. Please use `tencentcloud_cls_cloud_product_log_task_v2` instead. +``` diff --git a/go.mod b/go.mod index dc30c7a97b..f2ab1c3e77 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.1073 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033 - github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1135 + github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1153 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1128 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 diff --git a/go.sum b/go.sum index d8809bee3e..023b82e8d7 100644 --- a/go.sum +++ b/go.sum @@ -873,6 +873,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1078 h1:6yf63s github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1078/go.mod h1:D0n69Y0uDnHt31Wp5Z+uqmgBzr8xTZhrXPJ6d6KJL6E= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1135 h1:FTWpacOgtZCLC3Kwdf9gOpG2yYzfEzjKHsCR2k89LD0= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1135/go.mod h1:upjXJ5ISzUgxChOoUUcr9tQd8PB7FG3rFtMrxhozYzU= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148 h1:tPQHJE07DGCJWrQJklrkrF0CasB86M7AEb0PrkXNjAM= +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148/go.mod h1:dnj7aObyt7kqbM7vgHsvSpubXLjGc70Wos708PsdcEo= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.414/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.524/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index d0051884ae..e13c1928f5 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1834,6 +1834,7 @@ func Provider() *schema.Provider { "tencentcloud_cls_cloud_product_log_task": cls.ResourceTencentCloudClsCloudProductLogTask(), "tencentcloud_cls_notice_content": cls.ResourceTencentCloudClsNoticeContent(), "tencentcloud_cls_web_callback": cls.ResourceTencentCloudClsWebCallback(), + "tencentcloud_cls_cloud_product_log_task_v2": cls.ResourceTencentCloudClsCloudProductLogTaskV2(), "tencentcloud_lighthouse_instance": lighthouse.ResourceTencentCloudLighthouseInstance(), "tencentcloud_lighthouse_firewall_template": lighthouse.ResourceTencentCloudLighthouseFirewallTemplate(), "tencentcloud_tem_environment": tem.ResourceTencentCloudTemEnvironment(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 40b532e105..92e7fc4a8f 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -1425,6 +1425,7 @@ tencentcloud_cls_data_transform tencentcloud_cls_cloud_product_log_task tencentcloud_cls_notice_content tencentcloud_cls_web_callback +tencentcloud_cls_cloud_product_log_task_v2 Data Source tencentcloud_cls_shipper_tasks diff --git a/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task.go b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task.go index 65d799f695..6de1622796 100644 --- a/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task.go +++ b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task.go @@ -17,10 +17,11 @@ import ( func ResourceTencentCloudClsCloudProductLogTask() *schema.Resource { return &schema.Resource{ - Create: resourceTencentCloudClsCloudProductLogTaskCreate, - Read: resourceTencentCloudClsCloudProductLogTaskRead, - Update: resourceTencentCloudClsCloudProductLogTaskUpdate, - Delete: resourceTencentCloudClsCloudProductLogTaskDelete, + DeprecationMessage: "This resource has been deprecated in Terraform TencentCloud provider version 1.81.188. Please use `tencentcloud_cls_cloud_product_log_task_v2` instead.", + Create: resourceTencentCloudClsCloudProductLogTaskCreate, + Read: resourceTencentCloudClsCloudProductLogTaskRead, + Update: resourceTencentCloudClsCloudProductLogTaskUpdate, + Delete: resourceTencentCloudClsCloudProductLogTaskDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, diff --git a/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task.md b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task.md index 0f89740205..4c92915d27 100644 --- a/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task.md +++ b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task.md @@ -1,5 +1,7 @@ Provides a resource to create a cls cloud product log task +~> **NOTE:** This resource has been deprecated in Terraform TencentCloud provider version 1.81.188. Please use `tencentcloud_cls_cloud_product_log_task_v2` instead. + ~> **NOTE:** Using this resource will create new `logset` and `topic` Example Usage diff --git a/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2.go b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2.go new file mode 100644 index 0000000000..1351085b10 --- /dev/null +++ b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2.go @@ -0,0 +1,443 @@ +package cls + +import ( + "context" + "fmt" + "log" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + clsv20201016 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudClsCloudProductLogTaskV2() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudClsCloudProductLogTaskV2Create, + Read: resourceTencentCloudClsCloudProductLogTaskV2Read, + Update: resourceTencentCloudClsCloudProductLogTaskV2Update, + Delete: resourceTencentCloudClsCloudProductLogTaskV2Delete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "instance_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Instance ID.", + }, + + "assumer_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Cloud product identification, Values: CDS, CWP, CDB, TDSQL-C, MongoDB, TDStore, DCDB, MariaDB, PostgreSQL, BH, APIS.", + }, + + "log_type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Log type, Values: CDS-AUDIT, CDS-RISK, CDB-AUDIT, TDSQL-C-AUDIT, MongoDB-AUDIT, MongoDB-SlowLog, MongoDB-ErrorLog, TDMYSQL-SLOW, DCDB-AUDIT, DCDB-SLOW, DCDB-ERROR, MariaDB-AUDIT, MariaDB-SLOW, MariaDB-ERROR, PostgreSQL-SLOW, PostgreSQL-ERROR, PostgreSQL-AUDIT, BH-FILELOG, BH-COMMANDLOG, APIS-ACCESS.", + }, + + "cloud_product_region": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Cloud product region. There are differences in the input format of different log types in different regions. Please refer to the following example:\n- CDS(all log type): ap-guangzhou\n- CDB-AUDIT: gz\n- TDSQL-C-AUDIT: gz\n- MongoDB-AUDIT: gz\n- MongoDB-SlowLog: ap-guangzhou\n- MongoDB-ErrorLog: ap-guangzhou\n- TDMYSQL-SLOW: gz\n- DCDB(all log type): gz\n- MariaDB(all log type): gz\n- PostgreSQL(all log type): gz\n- BH(all log type): overseas-polaris(Domestic sites overseas)/fsi-polaris(Domestic sites finance)/general-polaris(Domestic sites)/intl-sg-prod(International sites)\n- APIS(all log type): gz.", + }, + + "cls_region": { + Type: schema.TypeString, + Required: true, + Description: "CLS target region.", + }, + + "logset_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + Description: "Log set name, required if `logset_id` is not filled in. If the log set does not exist, it will be automatically created.", + }, + + "topic_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + Description: "The name of the log topic is required when `topic_id` is not filled in. If the log theme does not exist, it will be automatically created.", + }, + + "extend": { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "Log configuration extension information, generally used to store additional log delivery configurations.", + }, + + "logset_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + Description: "Log set ID.", + }, + + "topic_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + Description: "Log theme ID.", + }, + + "force_delete": { + Type: schema.TypeBool, + Optional: true, + Description: "Indicate whether to forcibly delete the corresponding logset and topic. If set to true, it will be forcibly deleted. Default is false.", + }, + }, + } +} + +func resourceTencentCloudClsCloudProductLogTaskV2Create(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cls_cloud_product_log_task_v2.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = clsv20201016.NewCreateCloudProductLogCollectionRequest() + instanceId string + assumerName string + logType string + cloudProductRegion string + ) + + if v, ok := d.GetOk("instance_id"); ok { + request.InstanceId = helper.String(v.(string)) + instanceId = v.(string) + } + + if v, ok := d.GetOk("assumer_name"); ok { + request.AssumerName = helper.String(v.(string)) + assumerName = v.(string) + } + + if v, ok := d.GetOk("log_type"); ok { + request.LogType = helper.String(v.(string)) + logType = v.(string) + } + + if v, ok := d.GetOk("cloud_product_region"); ok { + request.CloudProductRegion = helper.String(v.(string)) + cloudProductRegion = v.(string) + } + + if v, ok := d.GetOk("cls_region"); ok { + request.ClsRegion = helper.String(v.(string)) + } + + if v, ok := d.GetOk("logset_name"); ok { + request.LogsetName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("topic_name"); ok { + request.TopicName = helper.String(v.(string)) + } + + if v, ok := d.GetOk("extend"); ok { + request.Extend = helper.String(v.(string)) + } + + if v, ok := d.GetOk("logset_id"); ok { + request.LogsetId = helper.String(v.(string)) + } + + if v, ok := d.GetOk("topic_id"); ok { + request.TopicId = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsV20201016Client().CreateCloudProductLogCollectionWithContext(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()) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Create cls cloud product log task failed, Response is nil.")) + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create cls cloud product log task failed, reason:%+v", logId, err) + return err + } + + // wait + service := ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + conf := tccommon.BuildStateChangeConf([]string{}, []string{"1"}, 10*tccommon.ReadRetryTimeout, time.Second, service.ClsCloudProductLogTaskStateRefreshFunc(ctx, instanceId, assumerName, logType, []string{})) + if _, e := conf.WaitForState(); e != nil { + return e + } + + d.SetId(strings.Join([]string{instanceId, assumerName, logType, cloudProductRegion}, tccommon.FILED_SP)) + + return resourceTencentCloudClsCloudProductLogTaskV2Read(d, meta) +} + +func resourceTencentCloudClsCloudProductLogTaskV2Read(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cls_cloud_product_log_task_v2.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + deleteForce bool + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 4 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + instanceId := idSplit[0] + assumerName := idSplit[1] + logType := idSplit[2] + cloudProductRegion := idSplit[3] + + respData, err := service.DescribeClsCloudProductLogTaskById(ctx, instanceId, assumerName, logType) + if err != nil { + return err + } + + if respData == nil || len(respData.Tasks) < 1 { + d.SetId("") + log.Printf("[WARN]%s resource `cls_cloud_product_log_task` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + + _ = d.Set("instance_id", instanceId) + _ = d.Set("assumer_name", assumerName) + _ = d.Set("log_type", logType) + _ = d.Set("cloud_product_region", cloudProductRegion) + + if respData.Tasks[0].ClsRegion != nil { + _ = d.Set("cls_region", respData.Tasks[0].ClsRegion) + } + + if respData.Tasks[0].Extend != nil { + _ = d.Set("extend", respData.Tasks[0].Extend) + } + + if respData.Tasks[0].LogsetId != nil { + _ = d.Set("logset_id", respData.Tasks[0].LogsetId) + info, err := service.DescribeClsLogset(ctx, *respData.Tasks[0].LogsetId) + if err != nil { + return err + } + + if info.LogsetName != nil { + _ = d.Set("logset_name", info.LogsetName) + } + } + + if respData.Tasks[0].TopicId != nil { + _ = d.Set("topic_id", respData.Tasks[0].TopicId) + info, err := service.DescribeClsTopicById(ctx, *respData.Tasks[0].TopicId) + if err != nil { + return err + } + + if info.TopicName != nil { + _ = d.Set("topic_name", info.TopicName) + } + } + + if v, ok := d.GetOkExists("force_delete"); ok { + deleteForce = v.(bool) + } + + _ = d.Set("force_delete", deleteForce) + + return nil +} + +func resourceTencentCloudClsCloudProductLogTaskV2Update(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cls_cloud_product_log_task_v2.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + ) + + immutableArgs := []string{"cls_region"} + for _, v := range immutableArgs { + if d.HasChange(v) { + return fmt.Errorf("argument `%s` cannot be changed", v) + } + } + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 4 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + instanceId := idSplit[0] + assumerName := idSplit[1] + logType := idSplit[2] + cloudProductRegion := idSplit[3] + + needChange := false + mutableArgs := []string{"extend"} + for _, v := range mutableArgs { + if d.HasChange(v) { + needChange = true + break + } + } + + if needChange { + request := clsv20201016.NewModifyCloudProductLogCollectionRequest() + request.InstanceId = helper.String(instanceId) + request.AssumerName = helper.String(assumerName) + request.LogType = helper.String(logType) + request.CloudProductRegion = helper.String(cloudProductRegion) + if v, ok := d.GetOk("extend"); ok { + request.Extend = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsV20201016Client().ModifyCloudProductLogCollectionWithContext(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 cls cloud product log task failed, reason:%+v", logId, err) + return err + } + } + + return resourceTencentCloudClsCloudProductLogTaskV2Read(d, meta) +} + +func resourceTencentCloudClsCloudProductLogTaskV2Delete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_cls_cloud_product_log_task_v2.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = clsv20201016.NewDeleteCloudProductLogCollectionRequest() + deleteForce bool + ) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 4 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + + instanceId := idSplit[0] + assumerName := idSplit[1] + logType := idSplit[2] + cloudProductRegion := idSplit[3] + + request.InstanceId = helper.String(instanceId) + request.AssumerName = helper.String(assumerName) + request.LogType = helper.String(logType) + request.CloudProductRegion = helper.String(cloudProductRegion) + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsV20201016Client().DeleteCloudProductLogCollectionWithContext(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 delete cls cloud product log task failed, reason:%+v", logId, err) + return err + } + + // wait delete + service := ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + conf := tccommon.BuildStateChangeConf([]string{}, []string{"3"}, 10*tccommon.ReadRetryTimeout, time.Second, service.ClsCloudProductLogTaskStateRefreshFunc(ctx, instanceId, assumerName, logType, []string{})) + if _, e := conf.WaitForState(); e != nil { + return e + } + + if v, ok := d.GetOkExists("force_delete"); ok { + deleteForce = v.(bool) + } + + if deleteForce { + var ( + request1 = clsv20201016.NewDeleteTopicRequest() + request2 = clsv20201016.NewDeleteLogsetRequest() + ) + + if v, ok := d.GetOk("topic_id"); ok { + request1.TopicId = helper.String(v.(string)) + } + + err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsV20201016Client().DeleteTopicWithContext(ctx, request1) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request1.GetAction(), request1.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s delete cls cloud product log task topic failed, reason:%+v", logId, err) + return err + } + + if v, ok := d.GetOk("logset_id"); ok { + request2.LogsetId = helper.String(v.(string)) + } + + err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseClsV20201016Client().DeleteLogsetWithContext(ctx, request2) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request2.GetAction(), request2.ToJsonString(), result.ToJsonString()) + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s delete cls cloud product log task logset failed, reason:%+v", logId, err) + return err + } + } + + return nil +} diff --git a/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2.md b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2.md new file mode 100644 index 0000000000..b5d0779edf --- /dev/null +++ b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2.md @@ -0,0 +1,43 @@ +Provides a resource to create a cls cloud product log task + +~> **NOTE:** In the destruction of resources, if cascading deletion of logset and topic is required, please set `force_delete` to `true`. + +Example Usage + +Create log delivery using the default newly created logset and topic + +```hcl +resource "tencentcloud_cls_cloud_product_log_task_v2" "example" { + instance_id = "postgres-0an6hpv3" + assumer_name = "PostgreSQL" + log_type = "PostgreSQL-SLOW" + cloud_product_region = "gz" + cls_region = "ap-guangzhou" + logset_name = "tf-example" + topic_name = "tf-example" + force_delete = true +} +``` + +Create log delivery using existing logset and topic + +```hcl +resource "tencentcloud_cls_cloud_product_log_task_v2" "example" { + instance_id = "postgres-0an6hpv3" + assumer_name = "PostgreSQL" + log_type = "PostgreSQL-SLOW" + cloud_product_region = "gz" + cls_region = "ap-guangzhou" + logset_id = "ca5b4f56-1174-4eee-bc4c-69e48e0e8c45" + topic_id = "d8177ca9-466b-42f4-a110-5933daf0a83a" + force_delete = false +} +``` + +Import + +cls cloud product log task can be imported using the id, e.g. + +``` +terraform import tencentcloud_cls_cloud_product_log_task_v2.example postgres-1p7xvpc1#PostgreSQL#PostgreSQL-SLOW#gz +``` diff --git a/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2_test.go b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2_test.go new file mode 100644 index 0000000000..9eebd67e8c --- /dev/null +++ b/tencentcloud/services/cls/resource_tc_cls_cloud_product_log_task_v2_test.go @@ -0,0 +1,72 @@ +package cls_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +// go test -i; go test -test.run TestAccTencentCloudNeedFixClsCloudProductLogTaskV2Resource_basic -v +func TestAccTencentCloudNeedFixClsCloudProductLogTaskV2Resource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccClsCloudProductLogTaskV2, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "instance_id"), + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "assumer_name"), + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "log_type"), + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "cloud_product_region"), + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "cls_region"), + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "logset_name"), + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "topic_name"), + ), + }, + { + Config: testAccClsCloudProductLogTaskV2Update, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_cls_cloud_product_log_task_v2.example", "extend"), + ), + }, + { + ResourceName: "tencentcloud_cls_cloud_product_log_task_v2.example", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccClsCloudProductLogTaskV2 = ` +resource "tencentcloud_cls_cloud_product_log_task_v2" "example" { + instance_id = "postgres-mcdstv8l" + assumer_name = "PostgreSQL" + log_type = "PostgreSQL-SLOW" + cloud_product_region = "gz" + cls_region = "ap-guangzhou" + logset_name = "tf-example" + topic_name = "tf-example" +} +` + +const testAccClsCloudProductLogTaskV2Update = ` +resource "tencentcloud_cls_cloud_product_log_task_v2" "example" { + instance_id = "postgres-mcdstv8l" + assumer_name = "PostgreSQL" + log_type = "PostgreSQL-SLOW" + cloud_product_region = "gz" + cls_region = "ap-guangzhou" + logset_name = "tf-example" + topic_name = "tf-example" + extend = "{\"ServiceName\":[\"HDFS\",\"KNOX\",\"YARN\",\"ZOOKEEPER\"],\"Policy\":0}" +} +` diff --git a/tencentcloud/services/cls/service_tencentcloud_cls.go b/tencentcloud/services/cls/service_tencentcloud_cls.go index 2535186af7..32bd0906d7 100644 --- a/tencentcloud/services/cls/service_tencentcloud_cls.go +++ b/tencentcloud/services/cls/service_tencentcloud_cls.go @@ -1431,7 +1431,7 @@ func (me *ClsService) DescribeClsCloudProductLogTaskById(ctx context.Context, in } }() - err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { ratelimit.Check(request.GetAction()) response, e := me.client.UseClsV20201016Client().DescribeCloudProductLogTasks(request) if e != nil { @@ -1439,6 +1439,7 @@ func (me *ClsService) DescribeClsCloudProductLogTaskById(ctx context.Context, in } else { 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 nil }) diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/client.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/client.go index f06c194ee6..31c1c3318d 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/client.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/client.go @@ -2499,6 +2499,77 @@ func (c *Client) DeleteConsumerWithContext(ctx context.Context, request *DeleteC return } +func NewDeleteCosRechargeRequest() (request *DeleteCosRechargeRequest) { + request = &DeleteCosRechargeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + + request.Init().WithApiInfo("cls", APIVersion, "DeleteCosRecharge") + + + return +} + +func NewDeleteCosRechargeResponse() (response *DeleteCosRechargeResponse) { + response = &DeleteCosRechargeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return + +} + +// DeleteCosRecharge +// 本接口用于删除cos导入任务 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// FAILEDOPERATION_TIMEOUT = "FailedOperation.Timeout" +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER = "InvalidParameter" +// INVALIDPARAMETER_DBDUPLICATION = "InvalidParameter.DbDuplication" +// MISSINGPARAMETER = "MissingParameter" +// OPERATIONDENIED = "OperationDenied" +// OPERATIONDENIED_ACLFAILED = "OperationDenied.ACLFailed" +// OPERATIONDENIED_ACCOUNTDESTROY = "OperationDenied.AccountDestroy" +// OPERATIONDENIED_ACCOUNTISOLATE = "OperationDenied.AccountIsolate" +// OPERATIONDENIED_ACCOUNTNOTEXISTS = "OperationDenied.AccountNotExists" +// RESOURCENOTFOUND_TOPICNOTEXIST = "ResourceNotFound.TopicNotExist" +func (c *Client) DeleteCosRecharge(request *DeleteCosRechargeRequest) (response *DeleteCosRechargeResponse, err error) { + return c.DeleteCosRechargeWithContext(context.Background(), request) +} + +// DeleteCosRecharge +// 本接口用于删除cos导入任务 +// +// 可能返回的错误码: +// FAILEDOPERATION = "FailedOperation" +// FAILEDOPERATION_TIMEOUT = "FailedOperation.Timeout" +// INTERNALERROR = "InternalError" +// INVALIDPARAMETER = "InvalidParameter" +// INVALIDPARAMETER_DBDUPLICATION = "InvalidParameter.DbDuplication" +// MISSINGPARAMETER = "MissingParameter" +// OPERATIONDENIED = "OperationDenied" +// OPERATIONDENIED_ACLFAILED = "OperationDenied.ACLFailed" +// OPERATIONDENIED_ACCOUNTDESTROY = "OperationDenied.AccountDestroy" +// OPERATIONDENIED_ACCOUNTISOLATE = "OperationDenied.AccountIsolate" +// OPERATIONDENIED_ACCOUNTNOTEXISTS = "OperationDenied.AccountNotExists" +// RESOURCENOTFOUND_TOPICNOTEXIST = "ResourceNotFound.TopicNotExist" +func (c *Client) DeleteCosRechargeWithContext(ctx context.Context, request *DeleteCosRechargeRequest) (response *DeleteCosRechargeResponse, err error) { + if request == nil { + request = NewDeleteCosRechargeRequest() + } + + if c.GetCredential() == nil { + return nil, errors.New("DeleteCosRecharge require credential") + } + + request.SetContext(ctx) + + response = NewDeleteCosRechargeResponse() + err = c.Send(request, response) + return +} + func NewDeleteDashboardSubscribeRequest() (request *DeleteDashboardSubscribeRequest) { request = &DeleteDashboardSubscribeRequest{ BaseRequest: &tchttp.BaseRequest{}, diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/models.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/models.go index 44bfc0f868..cf8ab60f40 100644 --- a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/models.go +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016/models.go @@ -173,6 +173,9 @@ type AlarmInfo struct { // 分组触发条件。 GroupTriggerCondition []*string `json:"GroupTriggerCondition,omitnil,omitempty" name:"GroupTriggerCondition"` + // 告警策略绑定的标签信息。 + Tags []*Tag `json:"Tags,omitnil,omitempty" name:"Tags"` + // 监控对象类型。0:执行语句共用监控对象;1:每个执行语句单独选择监控对象。 MonitorObjectType *uint64 `json:"MonitorObjectType,omitnil,omitempty" name:"MonitorObjectType"` @@ -4630,6 +4633,67 @@ func (r *DeleteConsumerResponse) FromJsonString(s string) error { return json.Unmarshal([]byte(s), &r) } +// Predefined struct for user +type DeleteCosRechargeRequestParams struct { + // COS导入配置Id + Id *string `json:"Id,omitnil,omitempty" name:"Id"` + + // 日志主题Id + TopicId *string `json:"TopicId,omitnil,omitempty" name:"TopicId"` +} + +type DeleteCosRechargeRequest struct { + *tchttp.BaseRequest + + // COS导入配置Id + Id *string `json:"Id,omitnil,omitempty" name:"Id"` + + // 日志主题Id + TopicId *string `json:"TopicId,omitnil,omitempty" name:"TopicId"` +} + +func (r *DeleteCosRechargeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +// FromJsonString It is highly **NOT** recommended to use this function +// because it has no param check, nor strict type check +func (r *DeleteCosRechargeRequest) FromJsonString(s string) error { + f := make(map[string]interface{}) + if err := json.Unmarshal([]byte(s), &f); err != nil { + return err + } + delete(f, "Id") + delete(f, "TopicId") + if len(f) > 0 { + return tcerr.NewTencentCloudSDKError("ClientError.BuildRequestError", "DeleteCosRechargeRequest has unknown keys!", "") + } + return json.Unmarshal([]byte(s), &r) +} + +// Predefined struct for user +type DeleteCosRechargeResponseParams struct { + // 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitnil,omitempty" name:"RequestId"` +} + +type DeleteCosRechargeResponse struct { + *tchttp.BaseResponse + Response *DeleteCosRechargeResponseParams `json:"Response"` +} + +func (r *DeleteCosRechargeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +// FromJsonString It is highly **NOT** recommended to use this function +// because it has no param check, nor strict type check +func (r *DeleteCosRechargeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + // Predefined struct for user type DeleteDashboardSubscribeRequestParams struct { // 仪表盘订阅记录id。 @@ -8707,10 +8771,10 @@ type GroupTriggerConditionInfo struct { } type HighLightItem struct { - // 高亮的日志Key + // 高亮的日志字段名称 Key *string `json:"Key,omitnil,omitempty" name:"Key"` - // 高亮的语法 + // 高亮的关键词 Values []*string `json:"Values,omitnil,omitempty" name:"Values"` } @@ -8926,6 +8990,9 @@ type LogInfo struct { // 请求包内日志的ID PkgLogId *string `json:"PkgLogId,omitnil,omitempty" name:"PkgLogId"` + // 符合检索条件的关键词,一般用于高亮显示。仅支持键值检索,不支持全文检索 + HighLights []*HighLightItem `json:"HighLights,omitnil,omitempty" name:"HighLights"` + // 日志内容的Json序列化字符串 LogJson *string `json:"LogJson,omitnil,omitempty" name:"LogJson"` @@ -12772,6 +12839,9 @@ type SearchLogRequestParams struct { // 为false时代表使用老的检索结果返回方式, 输出AnalysisResults和ColNames有效 // 两种返回方式在编码格式上有少量区别,建议使用true UseNewAnalysis *bool `json:"UseNewAnalysis,omitnil,omitempty" name:"UseNewAnalysis"` + + // 是否高亮符合检索条件的关键词,一般用于高亮显示。仅支持键值检索,不支持全文检索 + HighLight *bool `json:"HighLight,omitnil,omitempty" name:"HighLight"` } type SearchLogRequest struct { @@ -12848,6 +12918,9 @@ type SearchLogRequest struct { // 为false时代表使用老的检索结果返回方式, 输出AnalysisResults和ColNames有效 // 两种返回方式在编码格式上有少量区别,建议使用true UseNewAnalysis *bool `json:"UseNewAnalysis,omitnil,omitempty" name:"UseNewAnalysis"` + + // 是否高亮符合检索条件的关键词,一般用于高亮显示。仅支持键值检索,不支持全文检索 + HighLight *bool `json:"HighLight,omitnil,omitempty" name:"HighLight"` } func (r *SearchLogRequest) ToJsonString() string { @@ -12874,6 +12947,7 @@ func (r *SearchLogRequest) FromJsonString(s string) error { delete(f, "Context") delete(f, "SamplingRate") delete(f, "UseNewAnalysis") + delete(f, "HighLight") if len(f) > 0 { return tcerr.NewTencentCloudSDKError("ClientError.BuildRequestError", "SearchLogRequest has unknown keys!", "") } @@ -13333,6 +13407,9 @@ type ValueInfo struct { // 是否包含中文,long及double类型字段需为false ContainZH *bool `json:"ContainZH,omitnil,omitempty" name:"ContainZH"` + + // 字段别名 + Alias *string `json:"Alias,omitnil,omitempty" name:"Alias"` } type WebCallback struct { diff --git a/vendor/modules.txt b/vendor/modules.txt index 8582e9d7fc..367d800595 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1163,7 +1163,7 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317 # github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033 ## explicit; go 1.14 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit/v20190319 -# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1135 +# github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148 ## explicit; go 1.14 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016 # github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1153 diff --git a/website/docs/r/cls_cloud_product_log_task.html.markdown b/website/docs/r/cls_cloud_product_log_task.html.markdown index 1a88d5bf23..304415ebff 100644 --- a/website/docs/r/cls_cloud_product_log_task.html.markdown +++ b/website/docs/r/cls_cloud_product_log_task.html.markdown @@ -11,6 +11,8 @@ description: |- Provides a resource to create a cls cloud product log task +~> **NOTE:** This resource has been deprecated in Terraform TencentCloud provider version 1.81.188. Please use `tencentcloud_cls_cloud_product_log_task_v2` instead. + ~> **NOTE:** Using this resource will create new `logset` and `topic` ## Example Usage diff --git a/website/docs/r/cls_cloud_product_log_task_v2.html.markdown b/website/docs/r/cls_cloud_product_log_task_v2.html.markdown new file mode 100644 index 0000000000..aa567237e0 --- /dev/null +++ b/website/docs/r/cls_cloud_product_log_task_v2.html.markdown @@ -0,0 +1,91 @@ +--- +subcategory: "Cloud Log Service(CLS)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cls_cloud_product_log_task_v2" +sidebar_current: "docs-tencentcloud-resource-cls_cloud_product_log_task_v2" +description: |- + Provides a resource to create a cls cloud product log task +--- + +# tencentcloud_cls_cloud_product_log_task_v2 + +Provides a resource to create a cls cloud product log task + +~> **NOTE:** In the destruction of resources, if cascading deletion of logset and topic is required, please set `force_delete` to `true`. + +## Example Usage + +### Create log delivery using the default newly created logset and topic + +```hcl +resource "tencentcloud_cls_cloud_product_log_task_v2" "example" { + instance_id = "postgres-0an6hpv3" + assumer_name = "PostgreSQL" + log_type = "PostgreSQL-SLOW" + cloud_product_region = "gz" + cls_region = "ap-guangzhou" + logset_name = "tf-example" + topic_name = "tf-example" + force_delete = true +} +``` + +### Create log delivery using existing logset and topic + +```hcl +resource "tencentcloud_cls_cloud_product_log_task_v2" "example" { + instance_id = "postgres-0an6hpv3" + assumer_name = "PostgreSQL" + log_type = "PostgreSQL-SLOW" + cloud_product_region = "gz" + cls_region = "ap-guangzhou" + logset_id = "ca5b4f56-1174-4eee-bc4c-69e48e0e8c45" + topic_id = "d8177ca9-466b-42f4-a110-5933daf0a83a" + force_delete = false +} +``` + +## Argument Reference + +The following arguments are supported: + +* `assumer_name` - (Required, String, ForceNew) Cloud product identification, Values: CDS, CWP, CDB, TDSQL-C, MongoDB, TDStore, DCDB, MariaDB, PostgreSQL, BH, APIS. +* `cloud_product_region` - (Required, String, ForceNew) Cloud product region. There are differences in the input format of different log types in different regions. Please refer to the following example: +- CDS(all log type): ap-guangzhou +- CDB-AUDIT: gz +- TDSQL-C-AUDIT: gz +- MongoDB-AUDIT: gz +- MongoDB-SlowLog: ap-guangzhou +- MongoDB-ErrorLog: ap-guangzhou +- TDMYSQL-SLOW: gz +- DCDB(all log type): gz +- MariaDB(all log type): gz +- PostgreSQL(all log type): gz +- BH(all log type): overseas-polaris(Domestic sites overseas)/fsi-polaris(Domestic sites finance)/general-polaris(Domestic sites)/intl-sg-prod(International sites) +- APIS(all log type): gz. +* `cls_region` - (Required, String) CLS target region. +* `instance_id` - (Required, String, ForceNew) Instance ID. +* `log_type` - (Required, String, ForceNew) Log type, Values: CDS-AUDIT, CDS-RISK, CDB-AUDIT, TDSQL-C-AUDIT, MongoDB-AUDIT, MongoDB-SlowLog, MongoDB-ErrorLog, TDMYSQL-SLOW, DCDB-AUDIT, DCDB-SLOW, DCDB-ERROR, MariaDB-AUDIT, MariaDB-SLOW, MariaDB-ERROR, PostgreSQL-SLOW, PostgreSQL-ERROR, PostgreSQL-AUDIT, BH-FILELOG, BH-COMMANDLOG, APIS-ACCESS. +* `extend` - (Optional, String) Log configuration extension information, generally used to store additional log delivery configurations. +* `force_delete` - (Optional, Bool) Indicate whether to forcibly delete the corresponding logset and topic. If set to true, it will be forcibly deleted. Default is false. +* `logset_id` - (Optional, String, ForceNew) Log set ID. +* `logset_name` - (Optional, String, ForceNew) Log set name, required if `logset_id` is not filled in. If the log set does not exist, it will be automatically created. +* `topic_id` - (Optional, String, ForceNew) Log theme ID. +* `topic_name` - (Optional, String, ForceNew) The name of the log topic is required when `topic_id` is not filled in. If the log theme does not exist, it will be automatically created. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + +## Import + +cls cloud product log task can be imported using the id, e.g. + +``` +terraform import tencentcloud_cls_cloud_product_log_task_v2.example postgres-1p7xvpc1#PostgreSQL#PostgreSQL-SLOW#gz +``` + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 7d3c51a01f..eeeb4b0871 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -1555,6 +1555,9 @@