Skip to content

Commit

Permalink
Merge pull request #17 from dheeruk12/main
Browse files Browse the repository at this point in the history
add missing action types in alert rules
  • Loading branch information
dheeruk12 authored Nov 6, 2023
2 parents 7f3a866 + 06d1a01 commit e84aabe
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 59 deletions.
3 changes: 3 additions & 0 deletions docs/resources/zenduty_alertrules.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ resource "zenduty_alertrules" "example_alertrules" {
* `12` - add tag, value should be the unique_id of the tag
* `14` - add sla , value should be the unique_id of the sla
* `15` - add team priority , value should be the unique_id of the team priority
* `16` - add task template , value should be the unique_id of the task template
* `17` - add assign incident responder , value should be the unique_id of the responder
* `18` - hash entity_id, value is not required

* `value` (Required)(string) - The value of the action. (not required for `3`)
* `key` (Optional)(string) - The key of the action. (required for `11`)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module terraform-provider-zenduty
go 1.17

require (
github.com/Zenduty/zenduty-go-sdk v0.1.9
github.com/Zenduty/zenduty-go-sdk v0.2.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ github.com/Zenduty/zenduty-go-sdk v0.1.8 h1:vREmE/XO+nVR7oZ0JLp2W18QTl8r3a6ymsYY
github.com/Zenduty/zenduty-go-sdk v0.1.8/go.mod h1:XnK1p2uyFpBUwbW+xecKSww0klZOSKKoywobqGDlFE8=
github.com/Zenduty/zenduty-go-sdk v0.1.9 h1:8sHPvCMyAZL+bRJQvSmweIFCq046OFRE450v5yw/N3s=
github.com/Zenduty/zenduty-go-sdk v0.1.9/go.mod h1:XnK1p2uyFpBUwbW+xecKSww0klZOSKKoywobqGDlFE8=
github.com/Zenduty/zenduty-go-sdk v0.2.0 h1:2Z7R2cUpfUL1TRUV0+ePApwaRMFOkb+0zDjedp+cBmg=
github.com/Zenduty/zenduty-go-sdk v0.2.0/go.mod h1:XnK1p2uyFpBUwbW+xecKSww0klZOSKKoywobqGDlFE8=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down
121 changes: 63 additions & 58 deletions zenduty/resource_alertrules.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,78 +81,81 @@ func AlertRuleAction(Ctx context.Context, d *schema.ResourceData, m interface{},
newAction.ActionType = v.(int)
}

if (newAction.ActionType > 15) || (newAction.ActionType < 1) {
if (newAction.ActionType > 18) || (newAction.ActionType < 1) {
return nil, diag.FromErr(errors.New("action_type is not valid"))
}

if v, ok := ruleMap["value"]; ok {
value = v.(string)
}

if (newAction.ActionType == 1) || (newAction.ActionType == 2) || (newAction.ActionType == 3) || (newAction.ActionType == 4) || (newAction.ActionType == 5) || (newAction.ActionType == 6) || (newAction.ActionType == 7) || (newAction.ActionType == 8) || (newAction.ActionType == 9) || (newAction.ActionType == 10) || (newAction.ActionType == 11) || (newAction.ActionType == 12) || (newAction.ActionType == 13) || (newAction.ActionType == 14) || (newAction.ActionType == 15) {
if (newAction.ActionType != 3) && (value == "") {
return nil, diag.FromErr(errors.New("value is required"))
if ((newAction.ActionType != 3) && (newAction.ActionType != 18)) && (value == "") {
return nil, diag.FromErr(errors.New("value is required"))
}
if ((newAction.ActionType == 4) || (newAction.ActionType == 12) || (newAction.ActionType == 14) || (newAction.ActionType == 15) || (newAction.ActionType == 16)) && (!IsValidUUID(value)) {
return nil, diag.FromErr(errors.New(value + " is not a valid UUID"))
}

if (newAction.ActionType == 7) && (!(value == "0" || value == "1")) {
return nil, diag.FromErr(errors.New("incident urgency should be 0 or 1"))
}
if newAction.ActionType == 1 {
i, err := strconv.Atoi(value)
if i < 0 || i > 5 {
return nil, diag.FromErr(errors.New("value should be between 0 and 5"))
}
if ((newAction.ActionType == 4) || (newAction.ActionType == 12) || (newAction.ActionType == 13) || (newAction.ActionType == 14) || (newAction.ActionType == 15)) && (!IsValidUUID(value)) {
return nil, diag.FromErr(errors.New(value + " is not a valid UUID"))
if err != nil {
return nil, diag.FromErr(errors.New("value is not valid"))
}

if (newAction.ActionType == 7) && (!(value == "0" || value == "1")) {
return nil, diag.FromErr(errors.New("incident urgency should be 0 or 1"))
newAction.Value = value
} else if newAction.ActionType == 3 {
value = ""
} else if newAction.ActionType == 4 {
newAction.EscalationPolicy = value
value = ""
} else if newAction.ActionType == 6 {

newAction.AssignedTo = value
value = ""
} else if newAction.ActionType == 11 {
if v, ok := ruleMap["key"]; ok {
key = v.(string)
}
if key == "" {
return nil, diag.FromErr(errors.New("key(ie..role_id) is required"))
}
if newAction.ActionType == 1 {
i, err := strconv.Atoi(value)
if i < 0 || i > 5 {
return nil, diag.FromErr(errors.New("value should be between 0 and 5"))
}
if err != nil {
return nil, diag.FromErr(errors.New("value is not valid"))
}
newAction.Value = value
} else if newAction.ActionType == 3 {
value = ""
} else if newAction.ActionType == 4 {
newAction.EscalationPolicy = value
value = ""
} else if newAction.ActionType == 6 {

newAction.AssignedTo = value
value = ""
} else if newAction.ActionType == 11 {
if v, ok := ruleMap["key"]; ok {
key = v.(string)
}
if key == "" {
return nil, diag.FromErr(errors.New("key(ie..role_id) is required"))
}
if !IsValidUUID(key) {
return nil, diag.FromErr(errors.New("key(ie..role_id) is not valid UUID"))
}

newAction.Key = key

} else if newAction.ActionType == 14 {
newAction.SLA = value
value = ""
if newAction.SLA == "" {
return nil, diag.FromErr(errors.New("sla is required"))
} else if !IsValidUUID(newAction.SLA) {
return nil, diag.FromErr(errors.New("sla is not valid UUID"))
}

} else if newAction.ActionType == 15 {
newAction.TeamPriority = value
value = ""
if newAction.TeamPriority == "" {
return nil, diag.FromErr(errors.New("team_priority is required"))
} else if !IsValidUUID(newAction.TeamPriority) {
return nil, diag.FromErr(errors.New("team_priority is not valid UUID"))
}
if !IsValidUUID(key) {
return nil, diag.FromErr(errors.New("key(ie..role_id) is not valid UUID"))
}

newAction.Value = value
newAction.Key = key

} else if newAction.ActionType == 14 {
newAction.SLA = value
value = ""
if newAction.SLA == "" {
return nil, diag.FromErr(errors.New("sla is required"))
} else if !IsValidUUID(newAction.SLA) {
return nil, diag.FromErr(errors.New("sla is not valid UUID"))
}

} else if newAction.ActionType == 15 {
newAction.TeamPriority = value
value = ""
if newAction.TeamPriority == "" {
return nil, diag.FromErr(errors.New("team_priority is required"))
} else if !IsValidUUID(newAction.TeamPriority) {
return nil, diag.FromErr(errors.New("team_priority is not valid UUID"))
}
} else if newAction.ActionType == 16 {
newAction.TaskTemplates = value
value = ""
} else if newAction.ActionType == 18 {
value = ""
}

newAction.Value = value

newAlertRule.Actions[i] = newAction

}
Expand Down Expand Up @@ -269,6 +272,8 @@ func flattenAlertActions(rule *client.AlertRule) []map[string]interface{} {
newAction["value"] = action.SLA
} else if action.ActionType == 15 {
newAction["value"] = action.TeamPriority
} else if action.ActionType == 16 {
newAction["value"] = action.TaskTemplates
} else {
newAction["value"] = action.Value
}
Expand Down

0 comments on commit e84aabe

Please sign in to comment.