Skip to content

Commit

Permalink
Merge pull request #871 from cjgajard/issue-867
Browse files Browse the repository at this point in the history
Prevent timeout for alert_grouping_parameters to be explicitly set to zero when they are of type "content_based"
  • Loading branch information
imjaroiswebdev authored May 14, 2024
2 parents a9a6cba + b8d1432 commit 819a07c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pagerduty/resource_pagerduty_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ func expandAlertGroupingParameters(v interface{}) *pagerduty.AlertGroupingParame
}

alertGroupingParameters.Config = expandAlertGroupingConfig(ragpVal["config"])
if groupingType == "content_based" && alertGroupingParameters.Config != nil {
alertGroupingParameters.Config.Timeout = nil
}
return alertGroupingParameters
}

Expand Down
78 changes: 78 additions & 0 deletions pagerduty/resource_pagerduty_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,45 @@ func TestAccPagerDutyService_ResponsePlay(t *testing.T) {

}

func TestAccPagerDutyService_AlertGroupingParametersAddConfigField(t *testing.T) {
username := fmt.Sprintf("tf-%s", acctest.RandString(5))
email := fmt.Sprintf("%[email protected]", username)
escalationPolicy := fmt.Sprintf("tf-%s", acctest.RandString(5))
service := fmt.Sprintf("tf-%s", acctest.RandString(5))

fields := []string{"custom_details.alert_name"}
fieldsUpdated := []string{"custom_details.alert_name", "custom_details.stage"}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPagerDutyServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckPagerDutyServiceConfigWithConfigFields(
username, email, escalationPolicy, service, fields),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttrSet("pagerduty_service.foo", "alert_grouping_parameters.#"),
resource.TestCheckResourceAttrSet("pagerduty_service.foo", "alert_grouping_parameters.0.config.#"),
resource.TestCheckResourceAttr("pagerduty_service.foo", "alert_grouping_parameters.0.config.0.fields.0", fields[0]),
),
},
{
Config: testAccCheckPagerDutyServiceConfigWithConfigFields(
username, email, escalationPolicy, service, fieldsUpdated),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttrSet("pagerduty_service.foo", "alert_grouping_parameters.#"),
resource.TestCheckResourceAttrSet("pagerduty_service.foo", "alert_grouping_parameters.0.config.#"),
resource.TestCheckResourceAttr("pagerduty_service.foo", "alert_grouping_parameters.0.config.0.fields.0", fieldsUpdated[0]),
resource.TestCheckResourceAttr("pagerduty_service.foo", "alert_grouping_parameters.0.config.0.fields.1", fieldsUpdated[1]),
),
},
},
})
}

func testAccCheckPagerDutyServiceSaveServiceId(p *string, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -2455,3 +2494,42 @@ resource "pagerduty_service" "foo" {
}
`, username, email, escalationPolicy, responsePlay, service)
}

func testAccCheckPagerDutyServiceConfigWithConfigFields(username, email, escalationPolicy, service string, fields []string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" {
name = "%s"
email = "%s"
color = "green"
role = "user"
job_title = "foo"
description = "foo"
}
resource "pagerduty_escalation_policy" "foo" {
name = "%s"
description = "bar"
num_loops = 2
rule {
escalation_delay_in_minutes = 10
target {
type = "user_reference"
id = pagerduty_user.foo.id
}
}
}
resource "pagerduty_service" "foo" {
name = "%s"
escalation_policy = pagerduty_escalation_policy.foo.id
alert_grouping_parameters {
type = "content_based"
config {
aggregate = "all"
fields = ["%v"]
time_window = 300
}
}
}
`, username, email, escalationPolicy, service, strings.Join(fields, `","`))
}

0 comments on commit 819a07c

Please sign in to comment.