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

r/pagerduty_service: add alert_creation attribute #38

Merged
merged 1 commit into from
Sep 20, 2017
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
14 changes: 14 additions & 0 deletions pagerduty/resource_pagerduty_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func resourcePagerDutyService() *schema.Resource {
Optional: true,
Default: "Managed by Terraform",
},
"alert_creation": {
Type: schema.TypeString,
Optional: true,
Default: "create_incidents",
ValidateFunc: validateValueFunc([]string{
"create_alerts_and_incidents",
"create_incidents",
}),
},
"auto_resolve_timeout": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -191,6 +200,10 @@ func buildServiceStruct(d *schema.ResourceData) *pagerduty.Service {
service.AcknowledgementTimeout = attr.(int)
}

if attr, ok := d.GetOk("alert_creation"); ok {
service.AlertCreation = attr.(string)
}

if attr, ok := d.GetOk("escalation_policy"); ok {
service.EscalationPolicy = &pagerduty.EscalationPolicyReference{
ID: attr.(string),
Expand Down Expand Up @@ -248,6 +261,7 @@ func resourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) erro
d.Set("auto_resolve_timeout", service.AutoResolveTimeout)
d.Set("last_incident_timestamp", service.LastIncidentTimestamp)
d.Set("acknowledgement_timeout", service.AcknowledgementTimeout)
d.Set("alert_creation", service.AlertCreation)

if service.IncidentUrgencyRule != nil {
if err := d.Set("incident_urgency_rule", flattenIncidentUrgencyRule(service.IncidentUrgencyRule)); err != nil {
Expand Down
12 changes: 12 additions & 0 deletions pagerduty/resource_pagerduty_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func TestAccPagerDutyService_Basic(t *testing.T) {
"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(
Expand All @@ -84,6 +86,8 @@ func TestAccPagerDutyService_Basic(t *testing.T) {
"pagerduty_service.foo", "auto_resolve_timeout", "3600"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "acknowledgement_timeout", "3600"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "alert_creation", "create_incidents"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.#", "1"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -120,6 +124,8 @@ func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(t *testing.T) {
"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(
Expand Down Expand Up @@ -182,6 +188,8 @@ func TestAccPagerDutyService_BasicWithIncidentUrgencyRules(t *testing.T) {
"pagerduty_service.foo", "auto_resolve_timeout", "3600"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "acknowledgement_timeout", "3600"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "alert_creation", "create_incidents"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.#", "1"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -260,6 +268,8 @@ func TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules(t *testing.T)
"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(
Expand All @@ -280,6 +290,8 @@ func TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules(t *testing.T)
"pagerduty_service.foo", "auto_resolve_timeout", "3600"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "acknowledgement_timeout", "3600"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "alert_creation", "create_incidents"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "incident_urgency_rule.#", "1"),
resource.TestCheckResourceAttr(
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ resource "pagerduty_service" "example" {
auto_resolve_timeout = 14400
acknowledgement_timeout = 600
escalation_policy = "${pagerduty_escalation_policy.example.id}"
alert_creation = "create_incidents"
}
```

Expand All @@ -52,6 +53,7 @@ The following arguments are supported:
* `auto_resolve_timeout` - (Optional) Time in seconds that an incident is automatically resolved if left open for that long. Disabled if not set.
* `acknowledgement_timeout` - (Optional) Time in seconds that an incident changes to the Triggered State after being Acknowledged. Disabled if not set.
* `escalation_policy` - (Required) The escalation policy used by this service.
* `alert_creation` - (Optional) Must be one of two values. PagerDuty receives events from your monitoring systems and can then create incidents in different ways. Value "create_incidents" is default: events will create an incident that cannot be merged. Value "create_alerts_and_incidents" is the alternative: events will create an alert and then add it to a new incident, these incidents can be merged.

You may specify one optional `incident_urgency_rule` block configuring what urgencies to use.
Your PagerDuty account must have the `urgencies` ability to assign an incident urgency rule.
Expand Down