Skip to content

Commit 9aaf65e

Browse files
jtsaitostack72
authored andcommitted
Add support for missing attributes for PagerDuty service resource (hashicorp#11856)
* Add urgencies for PagerDuty services * Improve naming, comments, handle unexpected urgency rules * Document urgency rules for PagerDuty service
1 parent 1ba5b4a commit 9aaf65e

6 files changed

Lines changed: 857 additions & 43 deletions

File tree

builtin/providers/pagerduty/import_pagerduty_service_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,24 @@ func TestAccPagerDutyService_import(t *testing.T) {
2626
},
2727
})
2828
}
29+
30+
func TestAccPagerDutyServiceWithIncidentUrgency_import(t *testing.T) {
31+
resourceName := "pagerduty_service.foo"
32+
33+
resource.Test(t, resource.TestCase{
34+
PreCheck: func() { testAccPreCheck(t) },
35+
Providers: testAccProviders,
36+
CheckDestroy: testAccCheckPagerDutyServiceDestroy,
37+
Steps: []resource.TestStep{
38+
resource.TestStep{
39+
Config: testAccCheckPagerDutyServiceWithIncidentUrgencyRulesConfig,
40+
},
41+
42+
resource.TestStep{
43+
ResourceName: resourceName,
44+
ImportState: true,
45+
ImportStateVerify: true,
46+
},
47+
},
48+
})
49+
}

builtin/providers/pagerduty/resource_pagerduty_service.go

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,124 @@ func resourcePagerDutyService() *schema.Resource {
5050
Type: schema.TypeString,
5151
Required: true,
5252
},
53+
"incident_urgency_rule": &schema.Schema{
54+
Type: schema.TypeList,
55+
Required: true,
56+
Elem: &schema.Resource{
57+
Schema: map[string]*schema.Schema{
58+
"type": {
59+
Type: schema.TypeString,
60+
Required: true,
61+
},
62+
"urgency": {
63+
Type: schema.TypeString,
64+
Optional: true,
65+
},
66+
"during_support_hours": {
67+
Type: schema.TypeList,
68+
MaxItems: 1,
69+
MinItems: 1,
70+
Optional: true,
71+
Elem: &schema.Resource{
72+
Schema: map[string]*schema.Schema{
73+
"type": {
74+
Type: schema.TypeString,
75+
Optional: true,
76+
},
77+
"urgency": {
78+
Type: schema.TypeString,
79+
Optional: true,
80+
},
81+
},
82+
},
83+
},
84+
"outside_support_hours": {
85+
Type: schema.TypeList,
86+
MaxItems: 1,
87+
MinItems: 1,
88+
Optional: true,
89+
Elem: &schema.Resource{
90+
Schema: map[string]*schema.Schema{
91+
"type": {
92+
Type: schema.TypeString,
93+
Optional: true,
94+
},
95+
"urgency": {
96+
Type: schema.TypeString,
97+
Optional: true,
98+
},
99+
},
100+
},
101+
},
102+
},
103+
},
104+
},
105+
"support_hours": &schema.Schema{
106+
Type: schema.TypeList,
107+
Optional: true,
108+
MaxItems: 1,
109+
MinItems: 1,
110+
ForceNew: true,
111+
Elem: &schema.Resource{
112+
Schema: map[string]*schema.Schema{
113+
"type": {
114+
Type: schema.TypeString,
115+
Optional: true,
116+
},
117+
"time_zone": {
118+
Type: schema.TypeString,
119+
Optional: true,
120+
},
121+
"start_time": {
122+
Type: schema.TypeString,
123+
Optional: true,
124+
},
125+
"end_time": {
126+
Type: schema.TypeString,
127+
Optional: true,
128+
},
129+
"days_of_week": {
130+
Type: schema.TypeList,
131+
Optional: true,
132+
MaxItems: 7,
133+
Elem: &schema.Schema{Type: schema.TypeInt},
134+
},
135+
},
136+
},
137+
},
138+
"scheduled_actions": &schema.Schema{
139+
Type: schema.TypeList,
140+
Optional: true,
141+
ForceNew: true,
142+
Elem: &schema.Resource{
143+
Schema: map[string]*schema.Schema{
144+
"type": {
145+
Type: schema.TypeString,
146+
Optional: true,
147+
},
148+
"to_urgency": {
149+
Type: schema.TypeString,
150+
Optional: true,
151+
},
152+
"at": &schema.Schema{
153+
Type: schema.TypeList,
154+
Optional: true,
155+
Elem: &schema.Resource{
156+
Schema: map[string]*schema.Schema{
157+
"type": {
158+
Type: schema.TypeString,
159+
Optional: true,
160+
},
161+
"name": {
162+
Type: schema.TypeString,
163+
Optional: true,
164+
},
165+
},
166+
},
167+
},
168+
},
169+
},
170+
},
53171
},
54172
}
55173
}
@@ -86,6 +204,18 @@ func buildServiceStruct(d *schema.ResourceData) *pagerduty.Service {
86204

87205
service.EscalationPolicy = *escalationPolicy
88206

207+
if attr, ok := d.GetOk("incident_urgency_rule"); ok {
208+
if iur, ok := expandIncidentUrgencyRule(attr); ok {
209+
service.IncidentUrgencyRule = iur
210+
}
211+
}
212+
if attr, ok := d.GetOk("support_hours"); ok {
213+
service.SupportHours = expandSupportHours(attr)
214+
}
215+
if attr, ok := d.GetOk("scheduled_actions"); ok {
216+
service.ScheduledActions = expandScheduledActions(attr)
217+
}
218+
89219
return &service
90220
}
91221

@@ -133,6 +263,16 @@ func resourcePagerDutyServiceRead(d *schema.ResourceData, meta interface{}) erro
133263
d.Set("last_incident_timestamp", service.LastIncidentTimestamp)
134264
d.Set("acknowledgement_timeout", service.AcknowledgementTimeout)
135265

266+
if incidentUrgencyRule, ok := flattenIncidentUrgencyRule(service); ok {
267+
d.Set("incident_urgency_rule", incidentUrgencyRule)
268+
}
269+
270+
supportHours := flattenSupportHours(service)
271+
d.Set("support_hours", supportHours)
272+
273+
scheduledActions := flattenScheduledActions(service)
274+
d.Set("scheduled_actions", scheduledActions)
275+
136276
return nil
137277
}
138278

@@ -168,5 +308,6 @@ func resourcePagerDutyServiceImport(d *schema.ResourceData, meta interface{}) ([
168308
if err := resourcePagerDutyServiceRead(d, meta); err != nil {
169309
return nil, err
170310
}
311+
171312
return []*schema.ResourceData{d}, nil
172313
}

builtin/providers/pagerduty/resource_pagerduty_service_integration_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ resource "pagerduty_service" "foo" {
117117
auto_resolve_timeout = 1800
118118
acknowledgement_timeout = 1800
119119
escalation_policy = "${pagerduty_escalation_policy.foo.id}"
120+
121+
incident_urgency_rule {
122+
type = "constant"
123+
urgency = "high"
124+
}
120125
}
121126
122127
data "pagerduty_vendor" "datadog" {
@@ -162,6 +167,11 @@ resource "pagerduty_service" "foo" {
162167
auto_resolve_timeout = 3600
163168
acknowledgement_timeout = 3600
164169
escalation_policy = "${pagerduty_escalation_policy.foo.id}"
170+
171+
incident_urgency_rule {
172+
type = "constant"
173+
urgency = "high"
174+
}
165175
}
166176
167177
data "pagerduty_vendor" "datadog" {

0 commit comments

Comments
 (0)