diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 5cd78ea738..e616e89abc 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -605,6 +605,8 @@ CLS Resource tencentcloud_cls_logset tencentcloud_cls_topic + tencentcloud_cls_config + tencentcloud_cls_config_attachment tencentcloud_cls_machine_group tencentcloud_cls_cos_shipper */ @@ -1095,6 +1097,8 @@ func Provider() terraform.ResourceProvider { "tencentcloud_private_dns_record": resourceTencentCloudPrivateDnsRecord(), "tencentcloud_cls_logset": resourceTencentCloudClsLogset(), "tencentcloud_cls_topic": resourceTencentCloudClsTopic(), + "tencentcloud_cls_config": resourceTencentCloudClsConfig(), + "tencentcloud_cls_config_attachment": resourceTencentCloudClsConfigAttachment(), "tencentcloud_cls_machine_group": resourceTencentCloudClsMachineGroup(), "tencentcloud_cls_cos_shipper": resourceTencentCloudClsCosShipper(), }, diff --git a/tencentcloud/resource_tc_cls_config.go b/tencentcloud/resource_tc_cls_config.go new file mode 100644 index 0000000000..50a9733bbc --- /dev/null +++ b/tencentcloud/resource_tc_cls_config.go @@ -0,0 +1,442 @@ +/* +Provides a resource to create a cls config + +Example Usage + +```hcl +resource "tencentcloud_cls_config" "config" { + name = "config_hello" + output = "4d07fba0-b93e-4e0b-9a7f-d58542560bbb" + path = "/var/log/kubernetes" + log_type = "json_log" + extract_rule { + filter_key_regex { + key = "key1" + regex = "value1" + } + filter_key_regex { + key = "key2" + regex = "value2" + } + un_match_up_load_switch = true + un_match_log_key = "config" + backtracking = -1 + } + exclude_paths { + type = "Path" + value = "/data" + } + exclude_paths { + type = "File" + value = "/file" + } +# user_define_rule = "" +} +``` +*/ +package tencentcloud + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + cls "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudClsConfig() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudClsConfigCreate, + Read: resourceTencentCloudClsConfigRead, + Delete: resourceTencentCloudClsConfigDelete, + Update: resourceTencentCloudClsConfigUpdate, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Collection configuration name.", + }, + "output": { + Type: schema.TypeString, + Optional: true, + Description: "Log topic ID (TopicId) of collection configuration.", + }, + "path": { + Type: schema.TypeString, + Optional: true, + Description: "Log collection path containing the filename.", + }, + "log_type": { + Type: schema.TypeString, + Optional: true, + Description: "Type of the log to be collected. Valid values: json_log: log in JSON format; delimiter_log: log in delimited format; minimalist_log: minimalist log; multiline_log: log in multi-line format; " + + "fullregex_log: log in full regex format. Default value: minimalist_log.", + }, + "extract_rule": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Description: "Extraction rule. If ExtractRule is set, LogType must be set.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "time_key": { + Type: schema.TypeString, + Optional: true, + Description: "Time field key name. time_key and time_format must appear in pair.", + }, + "time_format": { + Type: schema.TypeString, + Optional: true, + Description: "Time field format. For more information, please see the output parameters of the time format description of the strftime function in C language.", + }, + "delimiter": { + Type: schema.TypeString, + Optional: true, + Description: "Delimiter for delimited log, which is valid only if log_type is delimiter_log.", + }, + "log_regex": { + Type: schema.TypeString, + Optional: true, + Description: "Full log matching rule, which is valid only if log_type is fullregex_log.", + }, + "begin_regex": { + Type: schema.TypeString, + Optional: true, + Description: "First-Line matching rule, which is valid only if log_type is multiline_log or fullregex_log.", + }, + "keys": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "Key name of each extracted field. An empty key indicates to discard the field. This parameter is valid only if log_type is delimiter_log. json_log logs use the key of JSON itself.", + }, + "filter_key_regex": { + Type: schema.TypeList, + Optional: true, + Description: "Log keys to be filtered and the corresponding regex.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Optional: true, + Description: "Log key to be filtered.", + }, + "regex": { + Type: schema.TypeString, + Optional: true, + Description: "Filter rule regex corresponding to key.", + }, + }, + }, + }, + "un_match_up_load_switch": { + Type: schema.TypeBool, + Optional: true, + Description: "Whether to upload the logs that failed to be parsed. Valid values: true: yes; false: no.", + }, + "un_match_log_key": { + Type: schema.TypeString, + Optional: true, + Description: "Unmatched log key.", + }, + "backtracking": { + Type: schema.TypeInt, + Optional: true, + Description: "Size of the data to be rewound in incremental collection mode. Default value: -1 (full collection).", + }, + }, + }, + }, + "exclude_paths": { + Type: schema.TypeList, + Optional: true, + Description: "Collection path blocklist.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Optional: true, + Description: "Type. Valid values: File, Path.", + }, + "value": { + Type: schema.TypeString, + Optional: true, + Description: "Specific content corresponding to Type.", + }, + }, + }, + }, + "user_define_rule": { + Type: schema.TypeString, + Optional: true, + Description: "Custom collection rule, which is a serialized JSON string.", + }, + }, + } +} + +func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cls_config.create")() + + logId := getLogId(contextNil) + + var ( + request = cls.NewCreateConfigRequest() + response *cls.CreateConfigResponse + ) + + if v, ok := d.GetOk("name"); ok { + request.Name = helper.String(v.(string)) + } + if v, ok := d.GetOk("output"); ok { + request.Output = helper.String(v.(string)) + } + if v, ok := d.GetOk("path"); ok { + request.Path = helper.String(v.(string)) + } + if v, ok := d.GetOk("log_type"); ok { + request.LogType = helper.String(v.(string)) + } + if v, ok := d.GetOk("extract_rule"); ok { + extractRules := make([]*cls.ExtractRuleInfo, 0, 10) + if len(v.([]interface{})) != 1 { + return fmt.Errorf("need only one extract rule.") + } + extractRule := cls.ExtractRuleInfo{} + dMap := v.([]interface{})[0].(map[string]interface{}) + if v, ok := dMap["format"]; ok { + extractRule.TimeKey = helper.String(v.(string)) + } + if v, ok := dMap["time_format"]; ok { + extractRule.TimeFormat = helper.String(v.(string)) + } + if v, ok := dMap["delimiter"]; ok { + extractRule.Delimiter = helper.String(v.(string)) + } + if v, ok := dMap["log_regex"]; ok { + extractRule.Delimiter = helper.String(v.(string)) + } + if v, ok := dMap["begin_regex"]; ok { + extractRule.Delimiter = helper.String(v.(string)) + } + if v, ok := dMap["keys"]; ok { + keys := v.(*schema.Set).List() + for _, key := range keys { + extractRule.Keys = append(extractRule.Keys, helper.String(key.(string))) + } + } + if v, ok := dMap["filter_key_regex"]; ok { + keyRegexs := make([]*cls.KeyRegexInfo, 0, 10) + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + keyRegex := cls.KeyRegexInfo{} + if v, ok := dMap["key"]; ok { + keyRegex.Key = helper.String(v.(string)) + } + if v, ok := dMap["regex"]; ok { + keyRegex.Regex = helper.String(v.(string)) + } + keyRegexs = append(keyRegexs, &keyRegex) + } + extractRule.FilterKeyRegex = keyRegexs + } + if v, ok := dMap["un_match_up_load_switch"]; ok { + extractRule.UnMatchUpLoadSwitch = helper.Bool(v.(bool)) + } + if v, ok := dMap["un_match_log_key"]; ok { + extractRule.UnMatchLogKey = helper.String(v.(string)) + } + if v, ok := dMap["backtracking"]; ok { + extractRule.Backtracking = helper.IntInt64(v.(int)) + } + extractRules = append(extractRules, &extractRule) + request.ExtractRule = extractRules[0] + } + if v, ok := d.GetOk("exclude_paths"); ok { + excludePaths := make([]*cls.ExcludePathInfo, 0, 10) + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + excludePath := cls.ExcludePathInfo{} + if v, ok := dMap["type"]; ok { + excludePath.Type = helper.String(v.(string)) + } + if v, ok := dMap["value"]; ok { + excludePath.Value = helper.String(v.(string)) + } + excludePaths = append(excludePaths, &excludePath) + } + request.ExcludePaths = excludePaths + } + if v, ok := d.GetOk("user_define_rule"); ok { + request.UserDefineRule = helper.String(v.(string)) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseClsClient().CreateConfig(request) + if e != nil { + return 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 cls logset failed, reason:%+v", logId, err) + return err + } + + id := *response.Response.ConfigId + d.SetId(id) + return nil +} + +func resourceTencentCloudClsConfigRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cls_config.read")() + + return nil +} + +func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cls_config.update")() + logId := getLogId(contextNil) + request := cls.NewModifyConfigRequest() + + request.ConfigId = helper.String(d.Id()) + + if d.HasChange("name") { + if v, ok := d.GetOk("name"); ok { + request.Name = helper.String(v.(string)) + } + } + if d.HasChange("output") { + if v, ok := d.GetOk("output"); ok { + request.Output = helper.String(v.(string)) + } + } + if d.HasChange("path") { + if v, ok := d.GetOk("path"); ok { + request.Path = helper.String(v.(string)) + } + } + if d.HasChange("log_type") || d.HasChange("extract_rule") { + if v, ok := d.GetOk("log_type"); ok { + request.LogType = helper.String(v.(string)) + } + if v, ok := d.GetOk("extract_rule"); ok { + extractRules := make([]*cls.ExtractRuleInfo, 0, 10) + if len(v.([]interface{})) != 1 { + return fmt.Errorf("need only one extract rule.") + } + extractRule := cls.ExtractRuleInfo{} + dMap := v.([]interface{})[0].(map[string]interface{}) + if v, ok := dMap["format"]; ok { + extractRule.TimeKey = helper.String(v.(string)) + } + if v, ok := dMap["time_format"]; ok { + extractRule.TimeFormat = helper.String(v.(string)) + } + if v, ok := dMap["delimiter"]; ok { + extractRule.Delimiter = helper.String(v.(string)) + } + if v, ok := dMap["log_regex"]; ok { + extractRule.Delimiter = helper.String(v.(string)) + } + if v, ok := dMap["begin_regex"]; ok { + extractRule.Delimiter = helper.String(v.(string)) + } + if v, ok := dMap["keys"]; ok { + keys := v.(*schema.Set).List() + for _, key := range keys { + extractRule.Keys = append(extractRule.Keys, helper.String(key.(string))) + } + } + if v, ok := dMap["filter_key_regex"]; ok { + keyRegexs := make([]*cls.KeyRegexInfo, 0, 10) + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + keyRegex := cls.KeyRegexInfo{} + if v, ok := dMap["key"]; ok { + keyRegex.Key = helper.String(v.(string)) + } + if v, ok := dMap["regex"]; ok { + keyRegex.Regex = helper.String(v.(string)) + } + keyRegexs = append(keyRegexs, &keyRegex) + } + extractRule.FilterKeyRegex = keyRegexs + } + if v, ok := dMap["un_match_up_load_switch"]; ok { + extractRule.UnMatchUpLoadSwitch = helper.Bool(v.(bool)) + } + if v, ok := dMap["un_match_log_key"]; ok { + extractRule.UnMatchLogKey = helper.String(v.(string)) + } + if v, ok := dMap["backtracking"]; ok { + extractRule.Backtracking = helper.IntInt64(v.(int)) + } + extractRules = append(extractRules, &extractRule) + request.ExtractRule = extractRules[0] + } + } + if d.HasChange("exclude_paths") { + if v, ok := d.GetOk("exclude_paths"); ok { + excludePaths := make([]*cls.ExcludePathInfo, 0, 10) + for _, item := range v.([]interface{}) { + dMap := item.(map[string]interface{}) + excludePath := cls.ExcludePathInfo{} + if v, ok := dMap["type"]; ok { + excludePath.Type = helper.String(v.(string)) + } + if v, ok := dMap["value"]; ok { + excludePath.Value = helper.String(v.(string)) + } + excludePaths = append(excludePaths, &excludePath) + } + request.ExcludePaths = excludePaths + } + } + + if d.HasChange("user_define_rule") { + if v, ok := d.GetOk("user_define_rule"); ok { + request.UserDefineRule = helper.String(v.(string)) + } + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseClsClient().ModifyConfig(request) + if e != nil { + return 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 nil +} + +func resourceTencentCloudClsConfigDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cls_config.delete")() + + logId := getLogId(contextNil) + ctx := context.WithValue(context.TODO(), logIdKey, logId) + service := ClsService{client: meta.(*TencentCloudClient).apiV3Conn} + id := d.Id() + + if err := service.DeleteClsConfig(ctx, id); err != nil { + return err + } + + return nil +} diff --git a/tencentcloud/resource_tc_cls_config_attachment.go b/tencentcloud/resource_tc_cls_config_attachment.go new file mode 100644 index 0000000000..04325fe093 --- /dev/null +++ b/tencentcloud/resource_tc_cls_config_attachment.go @@ -0,0 +1,127 @@ +/* +Provides a resource to create a cls config attachment + +Example Usage + +```hcl +resource "tencentcloud_cls_config_attachment" "attach" { + config_id = tencentcloud_cls_config.config.id + group_id = "27752a9b-9918-440a-8ee7-9c84a14a47ed" +} + +``` +*/ +package tencentcloud + +import ( + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + cls "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls/v20201016" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func resourceTencentCloudClsConfigAttachment() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudClsConfigAttachmentCreate, + Read: resourceTencentCloudClsConfigAttachmentRead, + Delete: resourceTencentCloudClsConfigAttachmentDelete, + Schema: map[string]*schema.Schema{ + "config_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Collection configuration id.", + }, + "group_id": { + Type: schema.TypeString, + Required: true, + + ForceNew: true, + Description: "Machine group id.", + }, + }, + } +} + +func resourceTencentCloudClsConfigAttachmentCreate(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cls_config_attachment.create")() + + logId := getLogId(contextNil) + + var ( + request = cls.NewApplyConfigToMachineGroupRequest() + configId string + groupId string + ) + + if v, ok := d.GetOk("config_id"); ok { + configId = v.(string) + request.ConfigId = helper.String(configId) + + } + if v, ok := d.GetOk("group_id"); ok { + groupId = v.(string) + request.GroupId = helper.String(groupId) + } + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseClsClient().ApplyConfigToMachineGroup(request) + if e != nil { + return 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 + } + + instanceId := helper.IdFormat(configId, groupId) + d.SetId(instanceId) + + return nil +} + +func resourceTencentCloudClsConfigAttachmentRead(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cls_config_attachment.read")() + + return nil +} + +func resourceTencentCloudClsConfigAttachmentDelete(d *schema.ResourceData, meta interface{}) error { + defer logElapsed("resource.tencentcloud_cls_config_attachment.delete")() + + logId := getLogId(contextNil) + request := cls.NewDeleteConfigFromMachineGroupRequest() + + idSplit := strings.Split(d.Id(), FILED_SP) + if len(idSplit) != 2 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + configId := idSplit[0] + groupId := idSplit[1] + request.GroupId = helper.String(groupId) + request.ConfigId = helper.String(configId) + + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { + result, e := meta.(*TencentCloudClient).apiV3Conn.UseClsClient().DeleteConfigFromMachineGroup(request) + if e != nil { + return 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 nil +} diff --git a/tencentcloud/resource_tc_cls_config_attachment_test.go b/tencentcloud/resource_tc_cls_config_attachment_test.go new file mode 100644 index 0000000000..a2a5d8541d --- /dev/null +++ b/tencentcloud/resource_tc_cls_config_attachment_test.go @@ -0,0 +1,92 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudClsConfigAttachment_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccClsConfigAttachment, + }, + }, + }) +} + +const testAccClsConfigAttachment = ` +resource "tencentcloud_cls_logset" "logset" { + logset_name = "tf-attach-test" + tags = { + "test" = "test" + } +} + +resource "tencentcloud_cls_topic" "topic" { + auto_split = true + logset_id = tencentcloud_cls_logset.logset.id + max_split_partitions = 20 + partition_count = 1 + period = 10 + storage_type = "hot" + tags = { + "test" = "test" + } + topic_name = "tf-attach-test" +} + +resource "tencentcloud_cls_config" "config" { + name = "attach" + output = tencentcloud_cls_topic.topic.id + path = "/var/log/kubernetes/**/kubernetes.audit" + log_type = "json_log" + extract_rule { + filter_key_regex { + key = "key1" + regex = "value1" + } + filter_key_regex { + key = "key2" + regex = "value2" + } + un_match_up_load_switch = true + un_match_log_key = "config" + backtracking = -1 + } + exclude_paths { + type = "Path" + value = "/data" + } + exclude_paths { + type = "File" + value = "/file" + } +} + +resource "tencentcloud_cls_machine_group" "group" { + group_name = "tf-attach-group" + service_logging = true + auto_update = true + update_end_time = "19:05:00" + update_start_time = "17:05:00" + + machine_group_type { + type = "ip" + values = [ + "192.168.1.1", + "192.168.1.2", + ] + } +} + +resource "tencentcloud_cls_config_attachment" "attach" { + config_id = tencentcloud_cls_config.config.id + group_id = tencentcloud_cls_machine_group.group.id +} +` diff --git a/tencentcloud/resource_tc_cls_config_test.go b/tencentcloud/resource_tc_cls_config_test.go new file mode 100644 index 0000000000..be88e1aaa5 --- /dev/null +++ b/tencentcloud/resource_tc_cls_config_test.go @@ -0,0 +1,74 @@ +package tencentcloud + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccTencentCloudClsConfig_basic(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccClsConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("tencentcloud_cls_config.config", "name", "config"), + ), + }, + }, + }) +} + +const testAccClsConfig = ` +resource "tencentcloud_cls_logset" "logset" { + logset_name = "tf-config-test" + tags = { + "test" = "test" + } +} + +resource "tencentcloud_cls_topic" "topic" { + auto_split = true + logset_id = tencentcloud_cls_logset.logset.id + max_split_partitions = 20 + partition_count = 1 + period = 10 + storage_type = "hot" + tags = { + "test" = "test" + } + topic_name = "tf-config-test" +} + +resource "tencentcloud_cls_config" "config" { + name = "config" + output = tencentcloud_cls_topic.topic.id + path = "/var/log/kubernetes/**/kubernetes.audit" + log_type = "json_log" + extract_rule { + filter_key_regex { + key = "key1" + regex = "value1" + } + filter_key_regex { + key = "key2" + regex = "value2" + } + un_match_up_load_switch = true + un_match_log_key = "config" + backtracking = -1 + } + exclude_paths { + type = "Path" + value = "/data" + } + exclude_paths { + type = "File" + value = "/file" + } +} +` diff --git a/tencentcloud/resource_tc_cls_cos_shipper_test.go b/tencentcloud/resource_tc_cls_cos_shipper_test.go index 7277682f28..36ac9624fe 100644 --- a/tencentcloud/resource_tc_cls_cos_shipper_test.go +++ b/tencentcloud/resource_tc_cls_cos_shipper_test.go @@ -17,7 +17,7 @@ func TestAccTencentCloudClsCosShipper_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccClsTopic, + Config: testAccClsCosShipper, Check: resource.ComposeTestCheckFunc( testAccCheckClsCosShipperExists("tencentcloud_cls_cos_shipper.shipper"), resource.TestCheckResourceAttr("tencentcloud_cls_cos_shipper.shipper", "shipper_name", "tf-shipper-test"), diff --git a/tencentcloud/service_tencentcloud_cls.go b/tencentcloud/service_tencentcloud_cls.go index 64fb66cf58..c195960653 100644 --- a/tencentcloud/service_tencentcloud_cls.go +++ b/tencentcloud/service_tencentcloud_cls.go @@ -547,3 +547,29 @@ func (me *ClsService) DeleteClsCosShipper(ctx context.Context, id string) (errRe return } + +// cls config +func (me *ClsService) DeleteClsConfig(ctx context.Context, id string) (errRet error) { + logId := getLogId(ctx) + + request := cls.NewDeleteConfigRequest() + request.ConfigId = &id + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", + logId, "delete object", request.ToJsonString(), errRet.Error()) + } + }() + + ratelimit.Check(request.GetAction()) + response, err := me.client.UseClsClient().DeleteConfig(request) + if err != nil { + errRet = err + return err + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", + logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + return +} diff --git a/website/docs/r/cls_config.html.markdown b/website/docs/r/cls_config.html.markdown new file mode 100644 index 0000000000..a9f46dd0c9 --- /dev/null +++ b/website/docs/r/cls_config.html.markdown @@ -0,0 +1,89 @@ +--- +subcategory: "CLS" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cls_config" +sidebar_current: "docs-tencentcloud-resource-cls_config" +description: |- + Provides a resource to create a cls config +--- + +# tencentcloud_cls_config + +Provides a resource to create a cls config + +## Example Usage + +```hcl +resource "tencentcloud_cls_config" "config" { + name = "config_hello" + output = "4d07fba0-b93e-4e0b-9a7f-d58542560bbb" + path = "/var/log/kubernetes" + log_type = "json_log" + extract_rule { + filter_key_regex { + key = "key1" + regex = "value1" + } + filter_key_regex { + key = "key2" + regex = "value2" + } + un_match_up_load_switch = true + un_match_log_key = "config" + backtracking = -1 + } + exclude_paths { + type = "Path" + value = "/data" + } + exclude_paths { + type = "File" + value = "/file" + } + # user_define_rule = "" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `extract_rule` - (Required) Extraction rule. If ExtractRule is set, LogType must be set. +* `name` - (Required) Collection configuration name. +* `exclude_paths` - (Optional) Collection path blocklist. +* `log_type` - (Optional) Type of the log to be collected. Valid values: json_log: log in JSON format; delimiter_log: log in delimited format; minimalist_log: minimalist log; multiline_log: log in multi-line format; fullregex_log: log in full regex format. Default value: minimalist_log. +* `output` - (Optional) Log topic ID (TopicId) of collection configuration. +* `path` - (Optional) Log collection path containing the filename. +* `user_define_rule` - (Optional) Custom collection rule, which is a serialized JSON string. + +The `exclude_paths` object supports the following: + +* `type` - (Optional) Type. Valid values: File, Path. +* `value` - (Optional) Specific content corresponding to Type. + +The `extract_rule` object supports the following: + +* `backtracking` - (Optional) Size of the data to be rewound in incremental collection mode. Default value: -1 (full collection). +* `begin_regex` - (Optional) First-Line matching rule, which is valid only if log_type is multiline_log or fullregex_log. +* `delimiter` - (Optional) Delimiter for delimited log, which is valid only if log_type is delimiter_log. +* `filter_key_regex` - (Optional) Log keys to be filtered and the corresponding regex. +* `keys` - (Optional) Key name of each extracted field. An empty key indicates to discard the field. This parameter is valid only if log_type is delimiter_log. json_log logs use the key of JSON itself. +* `log_regex` - (Optional) Full log matching rule, which is valid only if log_type is fullregex_log. +* `time_format` - (Optional) Time field format. For more information, please see the output parameters of the time format description of the strftime function in C language. +* `time_key` - (Optional) Time field key name. time_key and time_format must appear in pair. +* `un_match_log_key` - (Optional) Unmatched log key. +* `un_match_up_load_switch` - (Optional) Whether to upload the logs that failed to be parsed. Valid values: true: yes; false: no. + +The `filter_key_regex` object supports the following: + +* `key` - (Optional) Log key to be filtered. +* `regex` - (Optional) Filter rule regex corresponding to key. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/docs/r/cls_config_attachment.html.markdown b/website/docs/r/cls_config_attachment.html.markdown new file mode 100644 index 0000000000..e67a119b43 --- /dev/null +++ b/website/docs/r/cls_config_attachment.html.markdown @@ -0,0 +1,37 @@ +--- +subcategory: "CLS" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cls_config_attachment" +sidebar_current: "docs-tencentcloud-resource-cls_config_attachment" +description: |- + Provides a resource to create a cls config attachment +--- + +# tencentcloud_cls_config_attachment + +Provides a resource to create a cls config attachment + +## Example Usage + +```hcl +resource "tencentcloud_cls_config_attachment" "attach" { + config_id = tencentcloud_cls_config.config.id + group_id = "27752a9b-9918-440a-8ee7-9c84a14a47ed" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `config_id` - (Required, ForceNew) Collection configuration id. +* `group_id` - (Required, ForceNew) Machine group id. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index ad930868c6..a098c6597f 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -277,6 +277,12 @@