Skip to content

Commit

Permalink
Merge pull request #65 from iLert/fix/alert-action-delay-sec-validation
Browse files Browse the repository at this point in the history
Fix/alert action delay sec validation
  • Loading branch information
STLVRTX authored Nov 28, 2023
2 parents 7b2f76f + 81bef55 commit cfcc91b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 27.11.2023, Version 2.2.1

- fix/alert-action-delay-sec-validation in [#65](https://github.com/iLert/terraform-provider-ilert/pull/65)

## 13.11.2023, Version 2.2.0

- feature/alert-action-new-trigger-type-delaysec in [#63](https://github.com/iLert/terraform-provider-ilert/pull/63)
Expand Down
12 changes: 8 additions & 4 deletions ilert/resource_alert_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,8 @@ func resourceAlertAction() *schema.Resource {
},
},
"delay_sec": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 7200),
Type: schema.TypeInt,
Optional: true,
},
},
CreateContext: resourceAlertActionCreate,
Expand Down Expand Up @@ -669,7 +668,8 @@ func buildAlertAction(d *schema.ResourceData) (*ilert.AlertAction, error) {
if val, ok := d.GetOk("trigger_types"); ok {
vL := val.([]interface{})
sL := make([]string, 0)
_, delaySecIsSet := d.GetOk("delay_sec")
delaySec, delaySecExists := d.GetOk("delay_sec")
delaySecIsSet := delaySecExists || (delaySec != nil && delaySec.(int) == 0)
for _, m := range vL {
v := m.(string)
if v == ilert.AlertActionTriggerTypes.AlertEscalationEnded && !delaySecIsSet {
Expand Down Expand Up @@ -992,6 +992,10 @@ func buildAlertAction(d *schema.ResourceData) (*ilert.AlertAction, error) {
}

if val, ok := d.GetOk("delay_sec"); ok {
delaySec := val.(int)
if delaySec != 0 && (delaySec < 30 || delaySec > 7200) {
return nil, fmt.Errorf("[ERROR] Can't set 'delay_sec', value must be either 0 or between 30 and 7200")
}
alertAction.DelaySec = val.(int)
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/alert_action.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The following arguments are supported:
- `alert_source` - (Required) An [alert source](#alert-source-arguments) block.
- `connector` - (Required) A [connector](#connector-arguments) block.
- `trigger_mode` - (Optional) The trigger mode of the alert action. Allowed values are `AUTOMATIC` or `MANUAL`. Default: `AUTOMATIC`.
- `delay_sec` - (Optional) The number of seconds the alert action will be delayed when reacing end of escalation. Can only be set when one of `trigger_types` is set to `alert-escalation-ended`.
- `delay_sec` - (Optional) The number of seconds the alert action will be delayed when reacing end of escalation. Can only be set when one of `trigger_types` is set to `alert-escalation-ended`. Must be either `0` or a value between `30` and `7200`.
- `trigger_types` - (Optional if the `MANUAL` trigger mode and required if the `AUTOMATIC` trigger mode) A list of the trigger types. Allowed values are `alert-created`, `alert-assigned`, `alert-auto-escalated`, `alert-acknowledged`, `alert-raised`, `alert-comment-added`, `alert-escalation-ended`, `alert-resolved`, `alert-auto-resolved`, `alert-responder-added`, `alert-responder-removed`, `alert-channel-attached`, `alert-channel-detached`.
- `datadog` - (Optional) A [datadog](#datadog-arguments) block.
- `jira` - (Optional) A [jira](#jira-arguments) block.
Expand Down

0 comments on commit cfcc91b

Please sign in to comment.