From 6f098f5469224f725f6894a90f3b6a1496ba803f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ilteri=C5=9F?= Date: Thu, 24 Dec 2020 17:10:28 +0300 Subject: [PATCH] implement integration action ignore action, update go-sdk (#208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit authored-by: ilteriş tabak --- CHANGELOG.md | 5 ++ go.mod | 2 +- go.sum | 2 + .../resource_opsgenie_integration_action.go | 88 +++++++++++++++++-- ...source_opsgenie_integration_action_test.go | 11 +++ .../opsgenie-go-sdk-v2/integration/request.go | 5 +- .../opsgenie-go-sdk-v2/integration/result.go | 1 + vendor/modules.txt | 2 +- website/docs/r/integration_action.markdown | 13 +++ 9 files changed, 119 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06976293..ec435ee2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.5.7 (December 24, 2020) +IMPROVEMENTS: +* **Integration Actions :** add support for ignore action + + ## 0.5.6 (December 24, 2020) IMPROVEMENTS: * **Integration Actions :** add custom priority for create action (#177) diff --git a/go.mod b/go.mod index 95e73c23..cf84860b 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.14 require ( github.com/hashicorp/go-retryablehttp v0.6.6 github.com/hashicorp/terraform-plugin-sdk v1.15.0 - github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.4 + github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.5 github.com/pkg/errors v0.8.1 ) diff --git a/go.sum b/go.sum index 45ff18dc..b99f94d6 100644 --- a/go.sum +++ b/go.sum @@ -175,6 +175,8 @@ github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.3-0.20201204102414-d90cad05198b h1:N github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.3-0.20201204102414-d90cad05198b/go.mod h1:VOkJ7STzYj+nXRhMcBTcmt8uZZ17KZKJdZtJpgHLbT8= github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.4 h1:ZMCrwMWK2FKSOGJjxrJdaNuwBRIIhUJgByZvX83jIkU= github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.4/go.mod h1:VOkJ7STzYj+nXRhMcBTcmt8uZZ17KZKJdZtJpgHLbT8= +github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.5 h1:KEDXdM0rrDnPmAffZrqTAtlKmFj7ZmPJXpXJvLKFMNI= +github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.5/go.mod h1:VOkJ7STzYj+nXRhMcBTcmt8uZZ17KZKJdZtJpgHLbT8= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/opsgenie/resource_opsgenie_integration_action.go b/opsgenie/resource_opsgenie_integration_action.go index 1eaeaade..8ac9fbce 100644 --- a/opsgenie/resource_opsgenie_integration_action.go +++ b/opsgenie/resource_opsgenie_integration_action.go @@ -453,6 +453,74 @@ func resourceOpsgenieIntegrationAction() *schema.Resource { }, }, }, + "ignore": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "type": { + Type: schema.TypeString, + Optional: true, + Default: "ignore", + }, + "order": { + Type: schema.TypeInt, + Optional: true, + Default: 1, + }, + "filter": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"match-all", "match-any-condition", "match-all-conditions"}, false), + }, + "conditions": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "field": { + Type: schema.TypeString, + Required: true, + }, + "key": { + Type: schema.TypeString, + Optional: true, + }, + "not": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "operation": { + Type: schema.TypeString, + Required: true, + }, + "expected_value": { + Type: schema.TypeString, + Optional: true, + }, + "order": { + Type: schema.TypeInt, + Optional: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, }, } } @@ -517,10 +585,13 @@ func expandOpsgenieIntegrationActions(input interface{}) []integration.Integrati action.Type = integration.ActionType(inputMap["type"].(string)) action.Name = inputMap["name"].(string) - action.Alias = inputMap["alias"].(string) action.Order = inputMap["order"].(int) - action.User = inputMap["user"].(string) - action.Note = inputMap["note"].(string) + if action.Type != integration.Ignore { + action.Alias = inputMap["alias"].(string) + action.User = inputMap["user"].(string) + action.Note = inputMap["note"].(string) + } + if priority := inputMap["priority"]; priority != nil { action.Priority = priority.(string) } @@ -600,10 +671,12 @@ func flattenOpsgenieIntegrationActions(input []integration.IntegrationAction) [] actionMap := make(map[string]interface{}) actionMap["type"] = action.Type actionMap["name"] = action.Name - actionMap["alias"] = action.Alias + if action.Type != "ignore" { + actionMap["user"] = action.User + actionMap["alias"] = action.Alias + actionMap["note"] = action.Note + } actionMap["order"] = action.Order - actionMap["note"] = action.Note - actionMap["user"] = action.User actionMap["filter"] = flattenOpsgenieFilter(action.Filter) if action.Type == "create" { actionMap["source"] = action.Source @@ -648,6 +721,7 @@ func resourceOpsgenieIntegrationActionCreate(d *schema.ResourceData, meta interf Close: expandOpsgenieIntegrationActions(d.Get("close")), Acknowledge: expandOpsgenieIntegrationActions(d.Get("acknowledge")), AddNote: expandOpsgenieIntegrationActions(d.Get("add_note")), + Ignore: expandOpsgenieIntegrationActions(d.Get("ignore")), } log.Printf("[INFO] Creating OpsGenie integration actions for '%s'", integrationId) @@ -681,6 +755,7 @@ func resourceOpsgenieIntegrationActionRead(d *schema.ResourceData, meta interfac d.Set("close", flattenOpsgenieIntegrationActions(result.Close)) d.Set("acknowledge", flattenOpsgenieIntegrationActions(result.Acknowledge)) d.Set("add_note", flattenOpsgenieIntegrationActions(result.AddNote)) + d.Set("ignore", flattenOpsgenieIntegrationActions(result.Ignore)) return nil } @@ -702,6 +777,7 @@ func resourceOpsgenieIntegrationActionDelete(d *schema.ResourceData, meta interf Close: []integration.IntegrationAction{}, Acknowledge: []integration.IntegrationAction{}, AddNote: []integration.IntegrationAction{}, + Ignore: []integration.IntegrationAction{}, } _, err = client.UpdateAllActions(context.Background(), deleteRequest) diff --git a/opsgenie/resource_opsgenie_integration_action_test.go b/opsgenie/resource_opsgenie_integration_action_test.go index 842386e1..64d24a15 100644 --- a/opsgenie/resource_opsgenie_integration_action_test.go +++ b/opsgenie/resource_opsgenie_integration_action_test.go @@ -329,6 +329,17 @@ resource "opsgenie_integration_action" "test_api" { type = "user" } } + ignore { + name = "Ignore alerts with priority P5" + filter { + type = "match-all-conditions" + conditions { + field = "priority" + operation = "equals" + expected_value = "P5" + } + } + } close { name = "Low priority alerts" filter { diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/request.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/request.go index 3c6fdb8f..3deba478 100644 --- a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/request.go +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/request.go @@ -370,6 +370,7 @@ type UpdateAllIntegrationActionsRequest struct { Close []IntegrationAction `json:"close"` Acknowledge []IntegrationAction `json:"acknowledge"` AddNote []IntegrationAction `json:"addNote"` + Ignore []IntegrationAction `json:"ignore"` } type IntegrationAction struct { @@ -474,11 +475,11 @@ func validateResponders(responders []Responder) error { func validateActionType(actionType ActionType) error { switch actionType { - case Create, Close, Acknowledge, AddNote: + case Create, Close, Acknowledge, AddNote, Ignore: return nil } return errors.New("Action type should be one of these: " + - "'Create','Close','Acknowledge','AddNote'") + "'Create','Close','Acknowledge','AddNote','Ignore'") } func validateConditionMatchType(matchType og.ConditionMatchType) error { diff --git a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/result.go b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/result.go index 7312b0c1..3d5746a4 100644 --- a/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/result.go +++ b/vendor/github.com/opsgenie/opsgenie-go-sdk-v2/integration/result.go @@ -162,6 +162,7 @@ const ( Close ActionType = "close" Acknowledge ActionType = "acknowledge" AddNote ActionType = "AddNote" + Ignore ActionType = "ignore" ) type Responder struct { diff --git a/vendor/modules.txt b/vendor/modules.txt index cc18fef3..161d2242 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -215,7 +215,7 @@ github.com/mitchellh/mapstructure github.com/mitchellh/reflectwalk # github.com/oklog/run v1.0.0 github.com/oklog/run -# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.4 +# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.5 ## explicit github.com/opsgenie/opsgenie-go-sdk-v2/alert github.com/opsgenie/opsgenie-go-sdk-v2/client diff --git a/website/docs/r/integration_action.markdown b/website/docs/r/integration_action.markdown index 00b410a3..0bbd6941 100644 --- a/website/docs/r/integration_action.markdown +++ b/website/docs/r/integration_action.markdown @@ -17,6 +17,7 @@ The actions that are supported are: * close * acknowledge * add_note +* ignore ## Example Usage @@ -124,6 +125,18 @@ resource "opsgenie_integration_action" "test_action" { type = "match-all" } } + + ignore { + name = "Ignore alerts with ignore tag" + filter { + type = "match-all-conditions" + conditions { + field = "tags" + operation = "contains" + expected_value = "ignore" + } + } + } } ```