Skip to content

Commit 35bdfee

Browse files
authored
Merge pull request #424 from SumoLogic/apoorv-slo-compliance-validation-fix
fix slo compliance period validation
2 parents 52d0382 + d69c23b commit 35bdfee

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.18.1 (August 25, 2022)
2+
3+
BUG FIXES:
4+
* Fix compliance period validation for SLOs (GH-424)
5+
16
## 2.18.0 (August 8, 2022)
27

38
FEATURES:

sumologic/resource_sumologic_slo.go

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
66
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
77
"log"
8+
"strings"
89
)
910

1011
const fieldNameWindowBasedEvaluation = `window_based_evaluation`
@@ -200,12 +201,9 @@ func resourceSumologicSLO() *schema.Resource {
200201
Required: true,
201202
},
202203
"size": {
203-
Type: schema.TypeString,
204-
Required: true,
205-
ValidateFunc: validation.StringInSlice([]string{
206-
"Week", "Month", "Quarter",
207-
"1d", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", "10d", "11d", "12d", "13d", "14d",
208-
}, false),
204+
Type: schema.TypeString,
205+
Required: true,
206+
ValidateFunc: validateSLOComplianceSize,
209207
},
210208
"start_from": {
211209
Type: schema.TypeString,
@@ -684,3 +682,36 @@ func verifySLOObject(slo SLOLibrarySLO) error {
684682
}
685683
return nil
686684
}
685+
686+
// lintignore:V013
687+
func validateSLOComplianceSize(i interface{}, k string) (warnings []string, errors []error) {
688+
v, ok := i.(string)
689+
if !ok {
690+
errors = append(errors, fmt.Errorf("expected type of %s to be string", k))
691+
return warnings, errors
692+
}
693+
694+
var validPeriods []string
695+
696+
calendarPeriods := []string{"Week", "Month", "Quarter"}
697+
for _, calendarPeriod := range calendarPeriods {
698+
validPeriods = append(validPeriods, calendarPeriod)
699+
}
700+
701+
minRollingDays := 1
702+
maxRollingDays := 90
703+
for days := minRollingDays; days <= maxRollingDays; days++ {
704+
validPeriods = append(validPeriods, fmt.Sprintf("%dd", days))
705+
}
706+
707+
for _, validPeriod := range validPeriods {
708+
if v == validPeriod {
709+
return warnings, errors
710+
}
711+
}
712+
713+
errorMessage := "compliance period must be " + strings.Join(calendarPeriods, ", ") + " or " +
714+
fmt.Sprintf("%dd...%dd", minRollingDays, maxRollingDays)
715+
716+
return warnings, append(errors, fmt.Errorf(errorMessage))
717+
}

0 commit comments

Comments
 (0)