Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSGI-2056 ] Address Service Alert Grouping parameters config permadiff #771

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pagerduty/resource_pagerduty_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ func resourcePagerDutyService() *schema.Resource {
return fmt.Errorf("general urgency cannot be set for a use_support_hours incident urgency rule type")
}
}

// Due to alert_grouping_parameters.type = null is a valid configuration
// for disabling Service's Alert Grouping configuration and having an
// empty alert_grouping_parameters.config block is also valid, API ignore
// this input fields, and turns out that API response for Service
// configuration doesn't bring a representation of this HCL, which leads
// to a permadiff, described in
// https://github.com/PagerDuty/terraform-provider-pagerduty/issues/700
//
// So, bellow is the formated representation alert_grouping_parameters
// value when this permadiff appears and must be ignored.
ignoreThisAlertGroupingParamsConfigDiff := `[]interface {}{map[string]interface {}{"config":[]interface {}{interface {}(nil)}, "type":""}}`
if agpdiff, ok := diff.Get("alert_grouping_parameters").([]interface{}); ok && diff.NewValueKnown("alert_grouping_parameters") && fmt.Sprintf("%#v", agpdiff) == ignoreThisAlertGroupingParamsConfigDiff {
diff.Clear("alert_grouping_parameters")
}
return nil
},
Importer: &schema.ResourceImporter{
Expand Down Expand Up @@ -96,6 +111,7 @@ func resourcePagerDutyService() *schema.Resource {
"config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -584,6 +600,7 @@ func expandAlertGroupingParameters(v interface{}) *pagerduty.AlertGroupingParame

// For Intelligent grouping type, config is null
alertGroupingParameters.Config = nil
log.Printf("[MYDEBUG] config: %#v", alertGroupingParameters.Config)
if groupingType == "content_based" || groupingType == "time" {
alertGroupingParameters.Config = expandAlertGroupingConfig(riur["config"], groupingType)
}
Expand Down
101 changes: 101 additions & 0 deletions pagerduty/resource_pagerduty_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,30 @@ func TestAccPagerDutyService_AlertContentGrouping(t *testing.T) {
"pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"),
),
},
{
Config: testAccCheckPagerDutyServiceConfigWithAlertIntelligentGroupingOmittingConfig(username, email, escalationPolicy, service),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", service),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "alert_grouping_parameters.0.type", "intelligent"),
resource.TestCheckNoResourceAttr(
"pagerduty_service.foo", "alert_grouping_parameters.0.config.0"),
),
},
{
Config: testAccCheckPagerDutyServiceConfigWithAlertIntelligentGroupingTypeNullEmptyConfigConfig(username, email, escalationPolicy, service),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", service),
resource.TestCheckNoResourceAttr(
"pagerduty_service.foo", "alert_grouping_parameters.0.type"),
resource.TestCheckNoResourceAttr(
"pagerduty_service.foo", "alert_grouping_parameters.0.config.0"),
),
},
},
})
}
Expand Down Expand Up @@ -1384,6 +1408,83 @@ resource "pagerduty_service" "foo" {
`, username, email, escalationPolicy, service)
}

func testAccCheckPagerDutyServiceConfigWithAlertIntelligentGroupingOmittingConfig(username, email, escalationPolicy, service 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"
description = "bar"
auto_resolve_timeout = 1800
acknowledgement_timeout = 1800
escalation_policy = pagerduty_escalation_policy.foo.id
alert_creation = "create_alerts_and_incidents"
alert_grouping_parameters {
type = "intelligent"
}
}
`, username, email, escalationPolicy, service)
}

func testAccCheckPagerDutyServiceConfigWithAlertIntelligentGroupingTypeNullEmptyConfigConfig(username, email, escalationPolicy, service 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"
description = "bar"
auto_resolve_timeout = 1800
acknowledgement_timeout = 1800
escalation_policy = pagerduty_escalation_policy.foo.id
alert_creation = "create_alerts_and_incidents"
alert_grouping_parameters {
type = null
config {}
}
}
`, username, email, escalationPolicy, service)
}

func testAccCheckPagerDutyServiceConfigWithAutoPauseNotificationsParameters(username, email, escalationPolicy, service string) string {
return fmt.Sprintf(`
resource "pagerduty_user" "foo" {
Expand Down
Loading