From 10e6a3e82d34fc12cbdd957625debdb0692c67b3 Mon Sep 17 00:00:00 2001 From: dheeruk12 <96110782+dheeruk12@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:24:58 +0530 Subject: [PATCH 1/2] update action types in alert rules --- zenduty/resource_alertrules.go | 121 +++++++++++++++++---------------- 1 file changed, 63 insertions(+), 58 deletions(-) diff --git a/zenduty/resource_alertrules.go b/zenduty/resource_alertrules.go index a84a2fb..af2553f 100644 --- a/zenduty/resource_alertrules.go +++ b/zenduty/resource_alertrules.go @@ -81,7 +81,7 @@ 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")) } @@ -89,70 +89,73 @@ func AlertRuleAction(Ctx context.Context, d *schema.ResourceData, m interface{}, 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 } @@ -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 } From 4ed685caf1b46bc0a567a3507eeef313cee57fcd Mon Sep 17 00:00:00 2001 From: dheeruk12 <96110782+dheeruk12@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:46:09 +0530 Subject: [PATCH 2/2] bump zenduty go sdk version --- docs/resources/zenduty_alertrules.md | 3 +++ go.mod | 2 +- go.sum | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/resources/zenduty_alertrules.md b/docs/resources/zenduty_alertrules.md index c008956..6aab9e8 100644 --- a/docs/resources/zenduty_alertrules.md +++ b/docs/resources/zenduty_alertrules.md @@ -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`) diff --git a/go.mod b/go.mod index d41a655..ea870d5 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index b37c701..00f59d0 100644 --- a/go.sum +++ b/go.sum @@ -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=