Skip to content

Commit

Permalink
Notification Policy De duplication Action Bug Fix (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
prakhar-mudaiya authored Apr 15, 2021
1 parent 5f0f42e commit 9e1a0e8
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.4 (April 14, 2021)
BUGFIX:
* **Notification Policy:** De-duplication Action problem fixed.

## 0.6.3 (February 11, 2021)
BUGFIX:
* **Alert Policy:** Global alert policy import fixed
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/v2 v2.4.0
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.7-0.20201230123508-d0825cdedb9b
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8
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 @@ -275,6 +275,8 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.7-0.20201230123508-d0825cdedb9b h1:yxiXbZ+RIao4NJHdBgdw991bvLfzBxid8Qq/LzqXFHU=
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.7-0.20201230123508-d0825cdedb9b/go.mod h1:4OjcxgwdXzezqytxN534MooNmrxRD50geWZxTD7845s=
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8 h1:qF/rRi8GSU2mjBXfJIyMj9GGmjedsV3Gm1uYbiGlCRk=
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8/go.mod h1:4OjcxgwdXzezqytxN534MooNmrxRD50geWZxTD7845s=
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
4 changes: 2 additions & 2 deletions opsgenie/resource_opsgenie_notification_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ func resourceOpsGenieNotificationPolicyRead(d *schema.ResourceData, meta interfa
d.Set("auto_restart_action", nil)
}
// Workaround for a mispelling in ops-genie-sdk-v2 v1.0.5
if policy.DeDuplicationActionAction != nil {
d.Set("de_duplication_action", flattenOpsGenieNotificationPolicyDeDuplicationAction(policy.DeDuplicationActionAction))
if policy.DeDuplicationAction != nil {
d.Set("de_duplication_action", flattenOpsGenieNotificationPolicyDeDuplicationAction(policy.DeDuplicationAction))
} else {
d.Set("de_duplication_action", nil)
}
Expand Down
40 changes: 40 additions & 0 deletions opsgenie/resource_opsgenie_notification_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ func TestAccOpsGenieNotificationPolicy_basic(t *testing.T) {
})
}

func TestAccOpsGenieDeDuplicationNotificationPolicy_basic(t *testing.T) {
teamName := acctest.RandString(6)
notificationPolicyName := acctest.RandString(6)

config := testAccOpsGenieDeDuplicationActionNotificationPolicy_basic(teamName, notificationPolicyName)

resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories,
CheckDestroy: testCheckOpsGenieNotificationPolicyDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckOpsGenieNotificationPolicyExists("opsgenie_notification_policy.test"),
),
},
},
})
}

func testCheckOpsGenieNotificationPolicyDestroy(s *terraform.State) error {
client, err := policy.NewClient(testAccProvider.Meta().(*OpsgenieClient).client.Config)
if err != nil {
Expand Down Expand Up @@ -182,3 +202,23 @@ resource "opsgenie_notification_policy" "test" {
}
`, teamName, notificationPolicyName)
}

func testAccOpsGenieDeDuplicationActionNotificationPolicy_basic(teamName, notificationPolicyName string) string {
return fmt.Sprintf(`
resource "opsgenie_team" "test" {
name = "genieteam-%s"
description = "This team deals with all the things"
}
resource "opsgenie_notification_policy" "test" {
name = "geniepolicy-%s"
team_id = opsgenie_team.test.id
policy_description = "Perfect notification policy for the team."
de_duplication_action {
count = 20
de_duplication_action_type = "value-based"
}
filter {}
}
`, teamName, notificationPolicyName)
}

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 @@ -177,7 +177,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.7-0.20201230123508-d0825cdedb9b
# github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.8
## explicit
github.com/opsgenie/opsgenie-go-sdk-v2/alert
github.com/opsgenie/opsgenie-go-sdk-v2/client
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/notification_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ The `auto_restart_action` block supports:

The `de_duplication_action` block supports:

* `duration` - (Required) Duration of this action. This is a block, structure is documented below.

* `de_duplication_action_type` - (Required) Deduplication type. Possible values are: `value-based`, `frequency-based`
* `de_duplication_action_type` - (Required) Deduplication type. Possible values are: "value-based", "frequency-based"

* `count` - (Required) - Count

* `duration` - (Optional) Duration of this action (only required for "frequency-based" de-duplication action). This is a block, structure is documented below.

The `delay_action` block supports:

* `delay_option` - (Required) Defines until what day to delay or for what duration. Possible values are: `for-duration`, `next-time`, `next-weekday`, `next-monday`, `next-tuesday`, `next-wednesday`, `next-thursday`, `next-friday`, `next-saturday`, `next-sunday`
Expand Down

0 comments on commit 9e1a0e8

Please sign in to comment.