Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource: azurerm_sentinel_alert_rule_scheduled #6650

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(),
}
}