Skip to content

Commit e8df413

Browse files
author
Ashish Gaurav
committed
[Monitors] add verfication logic for use_row_count and field
Took 18 minutes
1 parent 9c60ed2 commit e8df413

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

sumologic/resource_sumologic_slo.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func resourceToSLO(d *schema.ResourceData) (*SLOLibrarySLO, error) {
484484
return nil, err
485485
}
486486

487-
return &SLOLibrarySLO{
487+
slo := SLOLibrarySLO{
488488
ID: d.Id(),
489489
Name: d.Get("name").(string),
490490
Description: d.Get("description").(string),
@@ -503,7 +503,14 @@ func resourceToSLO(d *schema.ResourceData) (*SLOLibrarySLO, error) {
503503
Indicator: *indicator,
504504
Service: d.Get("service").(string),
505505
Application: d.Get("application").(string),
506-
}, nil
506+
}
507+
508+
err = verifySLOObject(slo)
509+
if err != nil {
510+
return nil, err
511+
}
512+
513+
return &slo, nil
507514
}
508515

509516
func getSLOCompliance(d *schema.ResourceData) *SLOCompliance {
@@ -658,3 +665,19 @@ func resourceSumologicSLODelete(d *schema.ResourceData, meta interface{}) error
658665

659666
return nil
660667
}
668+
669+
func verifySLOObject(slo SLOLibrarySLO) error {
670+
671+
if slo.Name == "" {
672+
return fmt.Errorf("name is required")
673+
}
674+
675+
for _, q := range slo.Indicator.Queries {
676+
for _, qg := range q.QueryGroup {
677+
if qg.Field != "" && qg.UseRowCount {
678+
return fmt.Errorf("'field' for the query can not be specfied when 'use_row_count' is true")
679+
}
680+
}
681+
}
682+
return nil
683+
}

0 commit comments

Comments
 (0)