diff --git a/pagerduty/data_source_pagerduty_vendor_test.go b/pagerduty/data_source_pagerduty_vendor_test.go index 8d019711e..3c347e433 100644 --- a/pagerduty/data_source_pagerduty_vendor_test.go +++ b/pagerduty/data_source_pagerduty_vendor_test.go @@ -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"), ), }, }, diff --git a/pagerduty/resource_pagerduty_service.go b/pagerduty/resource_pagerduty_service.go index 496f576d3..e324dd3ee 100644 --- a/pagerduty/resource_pagerduty_service.go +++ b/pagerduty/resource_pagerduty_service.go @@ -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 } diff --git a/pagerduty/resource_pagerduty_service_test.go b/pagerduty/resource_pagerduty_service_test.go index 6d2e7f9dd..6c5ec4f18 100644 --- a/pagerduty/resource_pagerduty_service_test.go +++ b/pagerduty/resource_pagerduty_service_test.go @@ -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( @@ -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" {