Skip to content

Commit 2a22959

Browse files
committed
fix cls config
1 parent 017e637 commit 2a22959

File tree

1 file changed

+53
-65
lines changed

1 file changed

+53
-65
lines changed

tencentcloud/services/cls/resource_tc_cls_config.go

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cls
22

33
import (
44
"context"
5-
"fmt"
65
"log"
76

87
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
@@ -224,27 +223,23 @@ func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{
224223
if v, ok := d.GetOk("log_type"); ok {
225224
request.LogType = helper.String(v.(string))
226225
}
227-
if v, ok := d.GetOk("extract_rule"); ok {
228-
extractRules := make([]*cls.ExtractRuleInfo, 0, 10)
229-
if len(v.([]interface{})) != 1 {
230-
return fmt.Errorf("need only one extract rule.")
231-
}
226+
227+
if dMap, ok := helper.InterfacesHeadMap(d, "extract_rule"); ok {
232228
extractRule := cls.ExtractRuleInfo{}
233-
dMap := v.([]interface{})[0].(map[string]interface{})
234-
if v, ok := dMap["time_key"]; ok {
235-
extractRule.TimeKey = helper.String(v.(string))
229+
if v, ok := dMap["time_key"].(string); ok && v != "" {
230+
extractRule.TimeKey = helper.String(v)
236231
}
237-
if v, ok := dMap["time_format"]; ok {
238-
extractRule.TimeFormat = helper.String(v.(string))
232+
if v, ok := dMap["time_format"].(string); ok && v != "" {
233+
extractRule.TimeFormat = helper.String(v)
239234
}
240-
if v, ok := dMap["delimiter"]; ok {
241-
extractRule.Delimiter = helper.String(v.(string))
235+
if v, ok := dMap["delimiter"].(string); ok && v != "" {
236+
extractRule.Delimiter = helper.String(v)
242237
}
243-
if v, ok := dMap["log_regex"]; ok {
244-
extractRule.LogRegex = helper.String(v.(string))
238+
if v, ok := dMap["log_regex"].(string); ok && v != "" {
239+
extractRule.LogRegex = helper.String(v)
245240
}
246-
if v, ok := dMap["begin_regex"]; ok {
247-
extractRule.BeginRegex = helper.String(v.(string))
241+
if v, ok := dMap["begin_regex"].(string); ok && v != "" {
242+
extractRule.BeginRegex = helper.String(v)
248243
}
249244
if v, ok := dMap["keys"]; ok {
250245
keys := v.(*schema.Set).List()
@@ -270,8 +265,8 @@ func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{
270265
if v, ok := dMap["un_match_up_load_switch"]; ok {
271266
extractRule.UnMatchUpLoadSwitch = helper.Bool(v.(bool))
272267
}
273-
if v, ok := dMap["un_match_log_key"]; ok {
274-
extractRule.UnMatchLogKey = helper.String(v.(string))
268+
if v, ok := dMap["un_match_log_key"].(string); ok && v != "" {
269+
extractRule.UnMatchLogKey = helper.String(v)
275270
}
276271
if v, ok := dMap["backtracking"]; ok {
277272
extractRule.Backtracking = helper.IntInt64(v.(int))
@@ -282,20 +277,20 @@ func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{
282277
if v, ok := dMap["json_standard"]; ok {
283278
extractRule.JsonStandard = helper.IntInt64(v.(int))
284279
}
285-
if v, ok := dMap["protocol"]; ok {
286-
extractRule.Protocol = helper.String(v.(string))
280+
if v, ok := dMap["protocol"].(string); ok && v != "" {
281+
extractRule.Protocol = helper.String(v)
287282
}
288-
if v, ok := dMap["address"]; ok {
289-
extractRule.Address = helper.String(v.(string))
283+
if v, ok := dMap["address"].(string); ok && v != "" {
284+
extractRule.Address = helper.String(v)
290285
}
291-
if v, ok := dMap["parse_protocol"]; ok {
292-
extractRule.ParseProtocol = helper.String(v.(string))
286+
if v, ok := dMap["parse_protocol"].(string); ok && v != "" {
287+
extractRule.ParseProtocol = helper.String(v)
293288
}
294289
if v, ok := dMap["metadata_type"]; ok {
295290
extractRule.MetadataType = helper.IntInt64(v.(int))
296291
}
297-
if v, ok := dMap["path_regex"]; ok {
298-
extractRule.PathRegex = helper.String(v.(string))
292+
if v, ok := dMap["path_regex"].(string); ok && v != "" {
293+
extractRule.PathRegex = helper.String(v)
299294
}
300295
if v, ok := dMap["meta_tags"]; ok {
301296
for _, item := range v.([]interface{}) {
@@ -310,19 +305,18 @@ func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{
310305
extractRule.MetaTags = append(extractRule.MetaTags, &metaTagInfo)
311306
}
312307
}
313-
extractRules = append(extractRules, &extractRule)
314-
request.ExtractRule = extractRules[0]
308+
request.ExtractRule = &extractRule
315309
}
316310
if v, ok := d.GetOk("exclude_paths"); ok {
317311
excludePaths := make([]*cls.ExcludePathInfo, 0, 10)
318312
for _, item := range v.([]interface{}) {
319313
dMap := item.(map[string]interface{})
320314
excludePath := cls.ExcludePathInfo{}
321-
if v, ok := dMap["type"]; ok {
322-
excludePath.Type = helper.String(v.(string))
315+
if v, ok := dMap["type"].(string); ok && v != "" {
316+
excludePath.Type = helper.String(v)
323317
}
324-
if v, ok := dMap["value"]; ok {
325-
excludePath.Value = helper.String(v.(string))
318+
if v, ok := dMap["value"].(string); ok && v != "" {
319+
excludePath.Value = helper.String(v)
326320
}
327321
excludePaths = append(excludePaths, &excludePath)
328322
}
@@ -553,27 +547,22 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
553547
if v, ok := d.GetOk("log_type"); ok {
554548
request.LogType = helper.String(v.(string))
555549
}
556-
if v, ok := d.GetOk("extract_rule"); ok {
557-
extractRules := make([]*cls.ExtractRuleInfo, 0, 10)
558-
if len(v.([]interface{})) != 1 {
559-
return fmt.Errorf("need only one extract rule.")
560-
}
550+
if dMap, ok := helper.InterfacesHeadMap(d, "extract_rule"); ok {
561551
extractRule := cls.ExtractRuleInfo{}
562-
dMap := v.([]interface{})[0].(map[string]interface{})
563-
if v, ok := dMap["time_key"]; ok {
564-
extractRule.TimeKey = helper.String(v.(string))
552+
if v, ok := dMap["time_key"].(string); ok && v != "" {
553+
extractRule.TimeKey = helper.String(v)
565554
}
566-
if v, ok := dMap["time_format"]; ok {
567-
extractRule.TimeFormat = helper.String(v.(string))
555+
if v, ok := dMap["time_format"].(string); ok && v != "" {
556+
extractRule.TimeFormat = helper.String(v)
568557
}
569-
if v, ok := dMap["delimiter"]; ok {
570-
extractRule.Delimiter = helper.String(v.(string))
558+
if v, ok := dMap["delimiter"].(string); ok && v != "" {
559+
extractRule.Delimiter = helper.String(v)
571560
}
572-
if v, ok := dMap["log_regex"]; ok {
573-
extractRule.LogRegex = helper.String(v.(string))
561+
if v, ok := dMap["log_regex"].(string); ok && v != "" {
562+
extractRule.LogRegex = helper.String(v)
574563
}
575-
if v, ok := dMap["begin_regex"]; ok {
576-
extractRule.BeginRegex = helper.String(v.(string))
564+
if v, ok := dMap["begin_regex"].(string); ok && v != "" {
565+
extractRule.BeginRegex = helper.String(v)
577566
}
578567
if v, ok := dMap["keys"]; ok {
579568
keys := v.(*schema.Set).List()
@@ -599,8 +588,8 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
599588
if v, ok := dMap["un_match_up_load_switch"]; ok {
600589
extractRule.UnMatchUpLoadSwitch = helper.Bool(v.(bool))
601590
}
602-
if v, ok := dMap["un_match_log_key"]; ok {
603-
extractRule.UnMatchLogKey = helper.String(v.(string))
591+
if v, ok := dMap["un_match_log_key"].(string); ok && v != "" {
592+
extractRule.UnMatchLogKey = helper.String(v)
604593
}
605594
if v, ok := dMap["backtracking"]; ok {
606595
extractRule.Backtracking = helper.IntInt64(v.(int))
@@ -611,20 +600,20 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
611600
if v, ok := dMap["json_standard"]; ok {
612601
extractRule.JsonStandard = helper.IntInt64(v.(int))
613602
}
614-
if v, ok := dMap["protocol"]; ok {
615-
extractRule.Protocol = helper.String(v.(string))
603+
if v, ok := dMap["protocol"].(string); ok && v != "" {
604+
extractRule.Protocol = helper.String(v)
616605
}
617-
if v, ok := dMap["address"]; ok {
618-
extractRule.Address = helper.String(v.(string))
606+
if v, ok := dMap["address"].(string); ok && v != "" {
607+
extractRule.Address = helper.String(v)
619608
}
620-
if v, ok := dMap["parse_protocol"]; ok {
621-
extractRule.ParseProtocol = helper.String(v.(string))
609+
if v, ok := dMap["parse_protocol"].(string); ok && v != "" {
610+
extractRule.ParseProtocol = helper.String(v)
622611
}
623612
if v, ok := dMap["metadata_type"]; ok {
624613
extractRule.MetadataType = helper.IntInt64(v.(int))
625614
}
626-
if v, ok := dMap["path_regex"]; ok {
627-
extractRule.PathRegex = helper.String(v.(string))
615+
if v, ok := dMap["path_regex"].(string); ok && v != "" {
616+
extractRule.PathRegex = helper.String(v)
628617
}
629618
if v, ok := dMap["meta_tags"]; ok {
630619
for _, item := range v.([]interface{}) {
@@ -639,8 +628,7 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
639628
extractRule.MetaTags = append(extractRule.MetaTags, &metaTagInfo)
640629
}
641630
}
642-
extractRules = append(extractRules, &extractRule)
643-
request.ExtractRule = extractRules[0]
631+
request.ExtractRule = &extractRule
644632
}
645633
}
646634
if d.HasChange("exclude_paths") {
@@ -649,11 +637,11 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
649637
for _, item := range v.([]interface{}) {
650638
dMap := item.(map[string]interface{})
651639
excludePath := cls.ExcludePathInfo{}
652-
if v, ok := dMap["type"]; ok {
653-
excludePath.Type = helper.String(v.(string))
640+
if v, ok := dMap["type"].(string); ok && v != "" {
641+
excludePath.Type = helper.String(v)
654642
}
655-
if v, ok := dMap["value"]; ok {
656-
excludePath.Value = helper.String(v.(string))
643+
if v, ok := dMap["value"].(string); ok && v != "" {
644+
excludePath.Value = helper.String(v)
657645
}
658646
excludePaths = append(excludePaths, &excludePath)
659647
}

0 commit comments

Comments
 (0)