Skip to content

Commit

Permalink
implement integration action ignore action, update go-sdk (#208)
Browse files Browse the repository at this point in the history
authored-by: ilteriş tabak <[email protected]>
  • Loading branch information
ilteristabak authored Dec 24, 2020
1 parent e5fcdff commit 6f098f5
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
88 changes: 82 additions & 6 deletions opsgenie/resource_opsgenie_integration_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
},
},
},
},
},
},
},
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions opsgenie/resource_opsgenie_integration_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions website/docs/r/integration_action.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The actions that are supported are:
* close
* acknowledge
* add_note
* ignore

## Example Usage

Expand Down Expand Up @@ -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"
}
}
}
}
```

Expand Down

0 comments on commit 6f098f5

Please sign in to comment.