@@ -2,7 +2,6 @@ package cls
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
"log"
7
6
8
7
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
@@ -224,27 +223,23 @@ func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{
224
223
if v , ok := d .GetOk ("log_type" ); ok {
225
224
request .LogType = helper .String (v .(string ))
226
225
}
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 {
232
228
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 )
236
231
}
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 )
239
234
}
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 )
242
237
}
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 )
245
240
}
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 )
248
243
}
249
244
if v , ok := dMap ["keys" ]; ok {
250
245
keys := v .(* schema.Set ).List ()
@@ -270,8 +265,8 @@ func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{
270
265
if v , ok := dMap ["un_match_up_load_switch" ]; ok {
271
266
extractRule .UnMatchUpLoadSwitch = helper .Bool (v .(bool ))
272
267
}
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 )
275
270
}
276
271
if v , ok := dMap ["backtracking" ]; ok {
277
272
extractRule .Backtracking = helper .IntInt64 (v .(int ))
@@ -282,20 +277,20 @@ func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{
282
277
if v , ok := dMap ["json_standard" ]; ok {
283
278
extractRule .JsonStandard = helper .IntInt64 (v .(int ))
284
279
}
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 )
287
282
}
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 )
290
285
}
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 )
293
288
}
294
289
if v , ok := dMap ["metadata_type" ]; ok {
295
290
extractRule .MetadataType = helper .IntInt64 (v .(int ))
296
291
}
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 )
299
294
}
300
295
if v , ok := dMap ["meta_tags" ]; ok {
301
296
for _ , item := range v .([]interface {}) {
@@ -310,19 +305,18 @@ func resourceTencentCloudClsConfigCreate(d *schema.ResourceData, meta interface{
310
305
extractRule .MetaTags = append (extractRule .MetaTags , & metaTagInfo )
311
306
}
312
307
}
313
- extractRules = append (extractRules , & extractRule )
314
- request .ExtractRule = extractRules [0 ]
308
+ request .ExtractRule = & extractRule
315
309
}
316
310
if v , ok := d .GetOk ("exclude_paths" ); ok {
317
311
excludePaths := make ([]* cls.ExcludePathInfo , 0 , 10 )
318
312
for _ , item := range v .([]interface {}) {
319
313
dMap := item .(map [string ]interface {})
320
314
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 )
323
317
}
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 )
326
320
}
327
321
excludePaths = append (excludePaths , & excludePath )
328
322
}
@@ -553,27 +547,22 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
553
547
if v , ok := d .GetOk ("log_type" ); ok {
554
548
request .LogType = helper .String (v .(string ))
555
549
}
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 {
561
551
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 )
565
554
}
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 )
568
557
}
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 )
571
560
}
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 )
574
563
}
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 )
577
566
}
578
567
if v , ok := dMap ["keys" ]; ok {
579
568
keys := v .(* schema.Set ).List ()
@@ -599,8 +588,8 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
599
588
if v , ok := dMap ["un_match_up_load_switch" ]; ok {
600
589
extractRule .UnMatchUpLoadSwitch = helper .Bool (v .(bool ))
601
590
}
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 )
604
593
}
605
594
if v , ok := dMap ["backtracking" ]; ok {
606
595
extractRule .Backtracking = helper .IntInt64 (v .(int ))
@@ -611,20 +600,20 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
611
600
if v , ok := dMap ["json_standard" ]; ok {
612
601
extractRule .JsonStandard = helper .IntInt64 (v .(int ))
613
602
}
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 )
616
605
}
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 )
619
608
}
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 )
622
611
}
623
612
if v , ok := dMap ["metadata_type" ]; ok {
624
613
extractRule .MetadataType = helper .IntInt64 (v .(int ))
625
614
}
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 )
628
617
}
629
618
if v , ok := dMap ["meta_tags" ]; ok {
630
619
for _ , item := range v .([]interface {}) {
@@ -639,8 +628,7 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
639
628
extractRule .MetaTags = append (extractRule .MetaTags , & metaTagInfo )
640
629
}
641
630
}
642
- extractRules = append (extractRules , & extractRule )
643
- request .ExtractRule = extractRules [0 ]
631
+ request .ExtractRule = & extractRule
644
632
}
645
633
}
646
634
if d .HasChange ("exclude_paths" ) {
@@ -649,11 +637,11 @@ func resourceTencentCloudClsConfigUpdate(d *schema.ResourceData, meta interface{
649
637
for _ , item := range v .([]interface {}) {
650
638
dMap := item .(map [string ]interface {})
651
639
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 )
654
642
}
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 )
657
645
}
658
646
excludePaths = append (excludePaths , & excludePath )
659
647
}
0 commit comments