Skip to content

Commit

Permalink
New resource: azurerm_sentinel_alert_rule_scheduled #6650
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo committed May 7, 2020
1 parent d1c5abb commit 9498ad8
Show file tree
Hide file tree
Showing 22 changed files with 2,209 additions and 5 deletions.
34 changes: 29 additions & 5 deletions azurerm/helpers/validate/time.go
Expand Up @@ -2,13 +2,13 @@ package validate

import (
"fmt"
"regexp"
"time"

"github.com/Azure/go-autorest/autorest/date"
iso8601 "github.com/btubbs/datetime"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/rickb777/date/period"
)

func ISO8601Duration(i interface{}, k string) (warnings []string, errors []error) {
Expand All @@ -18,14 +18,38 @@ func ISO8601Duration(i interface{}, k string) (warnings []string, errors []error
return
}

matched, _ := regexp.MatchString(`^P([0-9]+Y)?([0-9]+M)?([0-9]+W)?([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+(\.?[0-9]+)?S)?)?$`, v)

if !matched {
errors = append(errors, fmt.Errorf("expected %s to be in ISO 8601 duration format, got %s", k, v))
if _, err := period.Parse(v); err != nil {
errors = append(errors, err)
}
return warnings, errors
}

func ISO8601DurationBetween(min string, max string) func(i interface{}, k string) (warnings []string, errors []error) {
minDuration := period.MustParse(min).DurationApprox()
maxDuration := period.MustParse(max).DurationApprox()
if minDuration >= maxDuration {
panic(fmt.Sprintf("min duration (%v) >= max duration (%v)", minDuration, maxDuration))
}
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
return nil, []error{fmt.Errorf("expected type of %s to be string", k)}
}

p, err := period.Parse(v)
if err != nil {
return nil, []error{err}
}

duration := p.DurationApprox()
if duration < minDuration || duration > maxDuration {
return nil, []error{fmt.Errorf("expected %s to be in the range (%v - %v), got %v", k, minDuration, maxDuration, duration)}
}

return nil, nil
}
}

func ISO8601DateTime(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
Expand Down
1 change: 1 addition & 0 deletions azurerm/internal/services/sentinel/registration.go
Expand Up @@ -29,5 +29,6 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource {
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_sentinel_alert_rule_ms_security_incident": resourceArmSentinelAlertRuleMsSecurityIncident(),
"azurerm_sentinel_alert_rule_scheduled": resourceArmSentinelAlertRuleScheduled(),
}
}

0 comments on commit 9498ad8

Please sign in to comment.