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

Instantiate scheduled_actions if incident_urgency_rules with type = "use_support_hours" #99

Merged
merged 4 commits into from
Nov 2, 2018
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
2 changes: 1 addition & 1 deletion pagerduty/data_source_pagerduty_vendor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccDataSourcePagerDutyVendor_Basic(t *testing.T) {
Config: testAccDataSourcePagerDutyVendorConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "id", "PZQ6AUS"),
resource.TestCheckResourceAttr(dataSourceName, "name", "Amazon Cloudwatch"),
resource.TestCheckResourceAttr(dataSourceName, "name", "Amazon CloudWatch"),
),
},
},
Expand Down
11 changes: 7 additions & 4 deletions pagerduty/resource_pagerduty_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,19 @@ func buildServiceStruct(d *schema.ResourceData) (*pagerduty.Service, error) {

if attr, ok := d.GetOk("incident_urgency_rule"); ok {
service.IncidentUrgencyRule = expandIncidentUrgencyRule(attr)
}

if attr, ok := d.GetOk("support_hours"); ok {
service.SupportHours = expandSupportHours(attr)
if service.IncidentUrgencyRule.Type == "use_support_hours" {
service.ScheduledActions = make([]*pagerduty.ScheduledAction, 1)
}
}

if attr, ok := d.GetOk("scheduled_actions"); ok {
service.ScheduledActions = expandScheduledActions(attr)
}

if attr, ok := d.GetOk("support_hours"); ok {
service.SupportHours = expandSupportHours(attr)
}

return &service, nil
}

Expand Down
110 changes: 110 additions & 0 deletions pagerduty/resource_pagerduty_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,60 @@ func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(t *testing.T) {
"pagerduty_service.foo", "support_hours.0.type", "fixed_time_per_day"),
),
},
{
Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesWithoutScheduledActionsConfig(username, email, escalationPolicy, service),
Check: resource.ComposeTestCheckFunc(
testAccCheckPagerDutyServiceExists("pagerduty_service.foo"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "name", service),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "description", "foo"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "auto_resolve_timeout", "1800"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "acknowledgement_timeout", "1800"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "alert_creation", "create_incidents"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.#", "1"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.0.during_support_hours.#", "1"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.0.during_support_hours.0.type", "constant"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.0.during_support_hours.0.urgency", "high"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.0.outside_support_hours.#", "1"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.0.outside_support_hours.0.type", "constant"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.0.outside_support_hours.0.urgency", "severity_based"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.0.type", "use_support_hours"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.#", "1"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.days_of_week.#", "5"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.days_of_week.0", "1"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.days_of_week.1", "2"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.days_of_week.2", "3"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.days_of_week.3", "4"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.days_of_week.4", "5"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.end_time", "17:00:00"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.start_time", "09:00:00"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.time_zone", "America/Lima"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "support_hours.0.type", "fixed_time_per_day"),
),
},
{
Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfigUpdated(username, email, escalationPolicy, serviceUpdated),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -660,6 +714,62 @@ resource "pagerduty_service" "foo" {
`, username, email, escalationPolicy, service)
}

func testAccCheckPagerDutyServiceWithIncidentUrgencyRulesWithoutScheduledActionsConfig(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 = "foo"
auto_resolve_timeout = 1800
acknowledgement_timeout = 1800
escalation_policy = "${pagerduty_escalation_policy.foo.id}"

incident_urgency_rule {
type = "use_support_hours"

during_support_hours {
type = "constant"
urgency = "high"
}
outside_support_hours {
type = "constant"
urgency = "severity_based"
}
}

support_hours = [{
type = "fixed_time_per_day"
time_zone = "America/Lima"
start_time = "09:00:00"
end_time = "17:00:00"
days_of_week = [ 1, 2, 3, 4, 5 ]
}]
}
`, username, email, escalationPolicy, service)
}

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