diff --git a/go.mod b/go.mod index 7860447ff..967b43a76 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/hashicorp/terraform-plugin-mux v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 github.com/hashicorp/terraform-plugin-testing v1.6.0 - github.com/heimweh/go-pagerduty v0.0.0-20240206151700-a2cbd995ef76 + github.com/heimweh/go-pagerduty v0.0.0-20240226201314-bfc8dce0a3ff ) require ( diff --git a/go.sum b/go.sum index 2e39e5e26..2b02034cd 100644 --- a/go.sum +++ b/go.sum @@ -93,8 +93,8 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= -github.com/heimweh/go-pagerduty v0.0.0-20240206151700-a2cbd995ef76 h1:+JY7wpGAsTe/r51/nTdo3pQQ2Wj4cTXpsQfij1JK2gc= -github.com/heimweh/go-pagerduty v0.0.0-20240206151700-a2cbd995ef76/go.mod h1:r59w5iyN01Qvi734yA5hZldbSeJJmsJzee/1kQ/MK7s= +github.com/heimweh/go-pagerduty v0.0.0-20240226201314-bfc8dce0a3ff h1:w5M1cWVKdfMoQnSyzmLYFSpByn7cnC86vKZTiCBPiwY= +github.com/heimweh/go-pagerduty v0.0.0-20240226201314-bfc8dce0a3ff/go.mod h1:r59w5iyN01Qvi734yA5hZldbSeJJmsJzee/1kQ/MK7s= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= diff --git a/pagerduty/event_orchestration_path_util.go b/pagerduty/event_orchestration_path_util.go index de93114f1..92f7b41de 100644 --- a/pagerduty/event_orchestration_path_util.go +++ b/pagerduty/event_orchestration_path_util.go @@ -65,6 +65,17 @@ var eventOrchestrationAutomationActionObjectSchema = map[string]*schema.Schema{ }, } +var eventOrchestrationIncidentCustomFieldsObjectSchema = map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Required: true, + }, + "value": { + Type: schema.TypeString, + Required: true, + }, +} + var eventOrchestrationAutomationActionSchema = map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -235,6 +246,20 @@ func flattenEventOrchestrationPathVariables(v []*pagerduty.EventOrchestrationPat return res } +func expandEventOrchestrationPathIncidentCustomFields(v interface{}) []*pagerduty.EventOrchestrationPathIncidentCustomFieldUpdate { + res := []*pagerduty.EventOrchestrationPathIncidentCustomFieldUpdate{} + + for _, eai := range v.([]interface{}) { + ea := eai.(map[string]interface{}) + ext := &pagerduty.EventOrchestrationPathIncidentCustomFieldUpdate{ + ID: ea["id"].(string), + Value: ea["value"].(string), + } + res = append(res, ext) + } + return res +} + func expandEventOrchestrationPathExtractions(v interface{}) []*pagerduty.EventOrchestrationPathActionExtractions { res := []*pagerduty.EventOrchestrationPathActionExtractions{} @@ -301,6 +326,21 @@ func expandEventOrchestrationAutomationActionObjects(v interface{}) []*pagerduty return result } +func flattenEventOrchestrationIncidentCustomFieldUpdates(v []*pagerduty.EventOrchestrationPathIncidentCustomFieldUpdate) []interface{} { + var result []interface{} + + for _, i := range v { + custom_field := map[string]string{ + "id": i.ID, + "value": i.Value, + } + + result = append(result, custom_field) + } + + return result +} + func flattenEventOrchestrationAutomationActions(v []*pagerduty.EventOrchestrationPathAutomationAction) []interface{} { var result []interface{} diff --git a/pagerduty/resource_pagerduty_event_orchestration_path_global.go b/pagerduty/resource_pagerduty_event_orchestration_path_global.go index 9045800a7..1f989d5fe 100644 --- a/pagerduty/resource_pagerduty_event_orchestration_path_global.go +++ b/pagerduty/resource_pagerduty_event_orchestration_path_global.go @@ -65,6 +65,13 @@ var eventOrchestrationPathGlobalCatchAllActionsSchema = map[string]*schema.Schem Schema: eventOrchestrationPathExtractionsSchema, }, }, + "incident_custom_field_update": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: eventOrchestrationIncidentCustomFieldsObjectSchema, + }, + }, } var eventOrchestrationPathGlobalRuleActionsSchema = buildEventOrchestrationPathGlobalRuleActionsSchema() @@ -349,10 +356,11 @@ func expandGlobalPathCatchAll(v interface{}) *pagerduty.EventOrchestrationPathCa } func expandGlobalPathActions(v interface{}) *pagerduty.EventOrchestrationPathRuleActions { - actions := &pagerduty.EventOrchestrationPathRuleActions{ - AutomationActions: []*pagerduty.EventOrchestrationPathAutomationAction{}, - Variables: []*pagerduty.EventOrchestrationPathActionVariables{}, - Extractions: []*pagerduty.EventOrchestrationPathActionExtractions{}, + var actions = &pagerduty.EventOrchestrationPathRuleActions{ + AutomationActions: []*pagerduty.EventOrchestrationPathAutomationAction{}, + Variables: []*pagerduty.EventOrchestrationPathActionVariables{}, + Extractions: []*pagerduty.EventOrchestrationPathActionExtractions{}, + IncidentCustomFieldUpdates: []*pagerduty.EventOrchestrationPathIncidentCustomFieldUpdate{}, } for _, i := range v.([]interface{}) { @@ -372,6 +380,7 @@ func expandGlobalPathActions(v interface{}) *pagerduty.EventOrchestrationPathRul actions.AutomationActions = expandEventOrchestrationPathAutomationActions(a["automation_action"]) actions.Variables = expandEventOrchestrationPathVariables(a["variable"]) actions.Extractions = expandEventOrchestrationPathExtractions(a["extraction"]) + actions.IncidentCustomFieldUpdates = expandEventOrchestrationPathIncidentCustomFields(a["incident_custom_field_update"]) } return actions @@ -449,6 +458,9 @@ func flattenGlobalPathActions(actions *pagerduty.EventOrchestrationPathRuleActio if actions.AutomationActions != nil { flattenedAction["automation_action"] = flattenEventOrchestrationAutomationActions(actions.AutomationActions) } + if actions.IncidentCustomFieldUpdates != nil { + flattenedAction["incident_custom_field_update"] = flattenEventOrchestrationIncidentCustomFieldUpdates(actions.IncidentCustomFieldUpdates) + } actionsMap = append(actionsMap, flattenedAction) diff --git a/pagerduty/resource_pagerduty_event_orchestration_path_global_test.go b/pagerduty/resource_pagerduty_event_orchestration_path_global_test.go index 03dd94dbb..bdc6fded0 100644 --- a/pagerduty/resource_pagerduty_event_orchestration_path_global_test.go +++ b/pagerduty/resource_pagerduty_event_orchestration_path_global_test.go @@ -295,17 +295,17 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAutomationActionsConfig(t, return fmt.Sprintf("%s%s", createBaseGlobalOrchConfig(t, ep, s, o), `resource "pagerduty_event_orchestration_global" "my_global_orch" { event_orchestration = pagerduty_event_orchestration.orch.id - + set { id = "start" rule { label = "rule 1" - actions { + actions { automation_action { name = "test" url = "https://test.com" auto_send = true - + header { key = "foo" value = "bar" @@ -314,7 +314,7 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAutomationActionsConfig(t, key = "baz" value = "buz" } - + parameter { key = "source" value = "orch" @@ -363,16 +363,16 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAutomationActionsParamsUpd return fmt.Sprintf("%s%s", createBaseGlobalOrchConfig(t, ep, s, o), `resource "pagerduty_event_orchestration_global" "my_global_orch" { event_orchestration = pagerduty_event_orchestration.orch.id - + set { id = "start" rule { label = "rule 1" - actions { + actions { automation_action { name = "test1" url = "https://test1.com" - + header { key = "foo1" value = "bar1" @@ -412,12 +412,12 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAutomationActionsParamsDel return fmt.Sprintf("%s%s", createBaseGlobalOrchConfig(t, ep, s, o), `resource "pagerduty_event_orchestration_global" "my_global_orch" { event_orchestration = pagerduty_event_orchestration.orch.id - + set { id = "start" rule { label = "rule 1" - actions { + actions { automation_action { name = "test" url = "https://test.com" @@ -444,7 +444,7 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalInvalidExtractionsConfig(t createBaseGlobalOrchConfig(t, ep, s, o), fmt.Sprintf(`resource "pagerduty_event_orchestration_global" "my_global_orch" { event_orchestration = pagerduty_event_orchestration.orch.id - + set { id = "start" rule { @@ -467,7 +467,7 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAllActionsConfig(t, ep, s, return fmt.Sprintf("%s%s", createBaseGlobalOrchConfig(t, ep, s, o), `resource "pagerduty_event_orchestration_global" "my_global_orch" { event_orchestration = pagerduty_event_orchestration.orch.id - + set { id = "start" rule { @@ -505,6 +505,10 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAllActionsConfig(t, ep, s, source = "event.group" target = "event.custom_details.message" } + incident_custom_field_update { + id = "PIJ90N7" + value = "foo" + } } } rule { @@ -574,7 +578,7 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAllActionsUpdateConfig(t, return fmt.Sprintf("%s%s", createBaseGlobalOrchConfig(t, ep, s, o), `resource "pagerduty_event_orchestration_global" "my_global_orch" { event_orchestration = pagerduty_event_orchestration.orch.id - + set { id = "start" rule { @@ -603,6 +607,10 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAllActionsUpdateConfig(t, target = "event.custom_details.message_upd" template = "[UPD] High CPU usage on {{variables.hostname}}: {{variables.cpu_val}}" } + incident_custom_field_update { + id = "PIJ90N7" + value = "bar" + } } } rule { @@ -666,7 +674,7 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAllActionsUpdateConfig(t, path = "event.custom_details.updated_at" type = "regex" value = "UPD (.*)" - } + } extraction { regex = ".*" source = "event.custom_details.region_upd" @@ -682,7 +690,7 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAllActionsDeleteConfig(t, return fmt.Sprintf("%s%s", createBaseGlobalOrchConfig(t, ep, s, o), `resource "pagerduty_event_orchestration_global" "my_global_orch" { event_orchestration = pagerduty_event_orchestration.orch.id - + set { id = "start" rule { @@ -719,7 +727,7 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalOneSetNoActionsConfig(t, e return fmt.Sprintf("%s%s", createBaseGlobalOrchConfig(t, ep, s, o), `resource "pagerduty_event_orchestration_global" "my_global_orch" { event_orchestration = pagerduty_event_orchestration.orch.id - + set { id = "start" rule { diff --git a/pagerduty/resource_pagerduty_event_orchestration_path_service.go b/pagerduty/resource_pagerduty_event_orchestration_path_service.go index c8a029d30..220806ff8 100644 --- a/pagerduty/resource_pagerduty_event_orchestration_path_service.go +++ b/pagerduty/resource_pagerduty_event_orchestration_path_service.go @@ -75,6 +75,13 @@ var eventOrchestrationPathServiceCatchAllActionsSchema = map[string]*schema.Sche Schema: eventOrchestrationPathExtractionsSchema, }, }, + "incident_custom_field_update": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: eventOrchestrationIncidentCustomFieldsObjectSchema, + }, + }, } var eventOrchestrationPathServiceRuleActionsSchema = buildEventOrchestrationPathServiceRuleActionsSchema() @@ -456,6 +463,7 @@ func expandServicePathActions(v interface{}) *pagerduty.EventOrchestrationPathRu PagerdutyAutomationActions: []*pagerduty.EventOrchestrationPathPagerdutyAutomationAction{}, Variables: []*pagerduty.EventOrchestrationPathActionVariables{}, Extractions: []*pagerduty.EventOrchestrationPathActionExtractions{}, + IncidentCustomFieldUpdates: []*pagerduty.EventOrchestrationPathIncidentCustomFieldUpdate{}, } for _, i := range v.([]interface{}) { @@ -475,6 +483,7 @@ func expandServicePathActions(v interface{}) *pagerduty.EventOrchestrationPathRu actions.AutomationActions = expandEventOrchestrationPathAutomationActions(a["automation_action"]) actions.Variables = expandEventOrchestrationPathVariables(a["variable"]) actions.Extractions = expandEventOrchestrationPathExtractions(a["extraction"]) + actions.IncidentCustomFieldUpdates = expandEventOrchestrationPathIncidentCustomFields(a["incident_custom_field_update"]) } return actions @@ -569,6 +578,9 @@ func flattenServicePathActions(actions *pagerduty.EventOrchestrationPathRuleActi if actions.AutomationActions != nil { flattenedAction["automation_action"] = flattenEventOrchestrationAutomationActions(actions.AutomationActions) } + if actions.IncidentCustomFieldUpdates != nil { + flattenedAction["incident_custom_field_update"] = flattenEventOrchestrationIncidentCustomFieldUpdates(actions.IncidentCustomFieldUpdates) + } actionsMap = append(actionsMap, flattenedAction) diff --git a/pagerduty/resource_pagerduty_event_orchestration_path_service_test.go b/pagerduty/resource_pagerduty_event_orchestration_path_service_test.go index c42e27b7c..ff91dcbd0 100644 --- a/pagerduty/resource_pagerduty_event_orchestration_path_service_test.go +++ b/pagerduty/resource_pagerduty_event_orchestration_path_service_test.go @@ -345,7 +345,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceDefaultConfig(ep, s strin return fmt.Sprintf("%s%s", createBaseServicePathConfig(ep, s), `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" } @@ -361,17 +361,17 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAutomationActionsConfig(e return fmt.Sprintf("%s%s", createBaseServicePathConfig(ep, s), `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" rule { label = "rule 1" - actions { + actions { automation_action { name = "test" url = "https://test.com" auto_send = true - + header { key = "foo" value = "bar" @@ -380,7 +380,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAutomationActionsConfig(e key = "baz" value = "buz" } - + parameter { key = "source" value = "orch" @@ -429,16 +429,16 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAutomationActionsParamsUp return fmt.Sprintf("%s%s", createBaseServicePathConfig(ep, s), `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" rule { label = "rule 1" - actions { + actions { automation_action { name = "test1" url = "https://test1.com" - + header { key = "foo1" value = "bar1" @@ -478,12 +478,12 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAutomationActionsParamsDe return fmt.Sprintf("%s%s", createBaseServicePathConfig(ep, s), `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" rule { label = "rule 1" - actions { + actions { automation_action { name = "test" url = "https://test.com" @@ -510,7 +510,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceInvalidExtractionsConfig( createBaseServicePathConfig(ep, s), fmt.Sprintf(`resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" rule { @@ -533,7 +533,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAllActionsConfig(ep, s st return fmt.Sprintf("%s%s", createBaseServicePathConfig(ep, s), `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" rule { @@ -574,6 +574,10 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAllActionsConfig(ep, s st source = "event.group" target = "event.custom_details.message" } + incident_custom_field_update { + id = "PIJ90N7" + value = "foo" + } } } } @@ -637,7 +641,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAllActionsUpdateConfig(ep return fmt.Sprintf("%s%s", createBaseServicePathConfig(ep, s), `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" rule { @@ -669,6 +673,10 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAllActionsUpdateConfig(ep target = "event.custom_details.message_upd" template = "[UPD] High CPU usage on {{variables.hostname}}: {{variables.cpu_val}}" } + incident_custom_field_update { + id = "PIJ90N7" + value = "bar" + } } } } @@ -726,7 +734,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAllActionsUpdateConfig(ep path = "event.custom_details.updated_at" type = "regex" value = "UPD (.*)" - } + } extraction { regex = ".*" source = "event.custom_details.region_upd" @@ -742,7 +750,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceAllActionsDeleteConfig(ep return fmt.Sprintf("%s%s", createBaseServicePathConfig(ep, s), `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" rule { @@ -775,7 +783,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceOneSetNoActionsConfig(ep, return fmt.Sprintf("%s%s", createBaseServicePathConfig(ep, s), `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id - + set { id = "start" rule { @@ -800,7 +808,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceEnableEOForServiceEnableU `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id enable_event_orchestration_for_service = true - + set { id = "start" } @@ -817,7 +825,7 @@ func testAccCheckPagerDutyEventOrchestrationPathServiceEnableEOForServiceDisable `resource "pagerduty_event_orchestration_service" "serviceA" { service = pagerduty_service.bar.id enable_event_orchestration_for_service = false - + set { id = "start" } diff --git a/vendor/github.com/heimweh/go-pagerduty/pagerduty/event_orchestration_path.go b/vendor/github.com/heimweh/go-pagerduty/pagerduty/event_orchestration_path.go index afc5a128a..42bd64351 100644 --- a/vendor/github.com/heimweh/go-pagerduty/pagerduty/event_orchestration_path.go +++ b/vendor/github.com/heimweh/go-pagerduty/pagerduty/event_orchestration_path.go @@ -59,12 +59,18 @@ type EventOrchestrationPathRuleActions struct { Annotate string `json:"annotate"` PagerdutyAutomationActions []*EventOrchestrationPathPagerdutyAutomationAction `json:"pagerduty_automation_actions"` AutomationActions []*EventOrchestrationPathAutomationAction `json:"automation_actions"` + IncidentCustomFieldUpdates []*EventOrchestrationPathIncidentCustomFieldUpdate `json:"incident_custom_field_updates"` Severity string `json:"severity"` EventAction string `json:"event_action"` Variables []*EventOrchestrationPathActionVariables `json:"variables"` Extractions []*EventOrchestrationPathActionExtractions `json:"extractions"` } +type EventOrchestrationPathIncidentCustomFieldUpdate struct { + ID string `json:"id,omitempty"` + Value string `json:"value,omitempty"` +} + type EventOrchestrationPathPagerdutyAutomationAction struct { ActionId string `json:"action_id,omitempty"` } diff --git a/vendor/modules.txt b/vendor/modules.txt index 4c8122f2b..c5341e271 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -250,7 +250,7 @@ github.com/hashicorp/terraform-svchost # github.com/hashicorp/yamux v0.1.1 ## explicit; go 1.15 github.com/hashicorp/yamux -# github.com/heimweh/go-pagerduty v0.0.0-20240206151700-a2cbd995ef76 +# github.com/heimweh/go-pagerduty v0.0.0-20240226201314-bfc8dce0a3ff ## explicit; go 1.17 github.com/heimweh/go-pagerduty/pagerduty github.com/heimweh/go-pagerduty/persistentconfig diff --git a/website/docs/r/event_orchestration_global.html.markdown b/website/docs/r/event_orchestration_global.html.markdown index 837731507..d59a62809 100644 --- a/website/docs/r/event_orchestration_global.html.markdown +++ b/website/docs/r/event_orchestration_global.html.markdown @@ -113,6 +113,9 @@ The following arguments are supported: * `suspend` - (Optional) The number of seconds to suspend the resulting alert before triggering. This effectively pauses incident notifications. If a `resolve` event arrives before the alert triggers then PagerDuty won't create an incident for this alert. * `priority` - (Optional) The ID of the priority you want to set on resulting incident. Consider using the [`pagerduty_priority`](https://registry.terraform.io/providers/PagerDuty/pagerduty/latest/docs/data-sources/priority) data source. * `annotate` - (Optional) Add this text as a note on the resulting incident. +* `incident_custom_field_update` - (Optional) Assign a custom field to the resulting incident. + * `id` - (Required) The custom field id + * `value` - (Required) The value to assign to this custom field * `automation_action` - (Optional) Create a [Webhook](https://support.pagerduty.com/docs/event-orchestration#webhooks) associated with the resulting incident. * `name` - (Required) Name of this Webhook. * `url` - (Required) The API endpoint where PagerDuty's servers will send the webhook request. diff --git a/website/docs/r/event_orchestration_service.html.markdown b/website/docs/r/event_orchestration_service.html.markdown index 2ea891342..17f7d8fb3 100644 --- a/website/docs/r/event_orchestration_service.html.markdown +++ b/website/docs/r/event_orchestration_service.html.markdown @@ -31,17 +31,22 @@ resource "pagerduty_team" "engineering" { resource "pagerduty_user" "example" { name = "Earline Greenholt" email = "125.greenholt.earline@graham.name" - teams = [pagerduty_team.engineering.id] } -resource "pagerduty_escalation_policy" "foo" { +resource "pagerduty_team_membership" "foo" { + user_id = pagerduty_user.example.id + team_id = pagerduty_team.engineering.id + role = "manager" +} + +resource "pagerduty_escalation_policy" "example" { name = "Engineering Escalation Policy" num_loops = 2 rule { escalation_delay_in_minutes = 10 target { - type = "user" + type = "user_reference" id = pagerduty_user.example.id } } @@ -55,6 +60,12 @@ resource "pagerduty_service" "example" { alert_creation = "create_alerts_and_incidents" } +resource "pagerduty_incident_custom_field" "cs_impact" { + name = "impact" + data_type = "string" + field_type = "single_value" +} + data "pagerduty_priority" "p1" { name = "P1" } @@ -99,6 +110,10 @@ resource "pagerduty_event_orchestration_service" "www" { actions { annotate = "Please use our P1 runbook: https://docs.test/p1-runbook" priority = data.pagerduty_priority.p1.id + incident_custom_field_update { + id = pagerduty_incident_custom_field.cs_impact.id + value = "High Impact" + } } } rule { @@ -170,6 +185,9 @@ The following arguments are supported: * `suspend` - (Optional) The number of seconds to suspend the resulting alert before triggering. This effectively pauses incident notifications. If a `resolve` event arrives before the alert triggers then PagerDuty won't create an incident for this alert. * `priority` - (Optional) The ID of the priority you want to set on resulting incident. Consider using the [`pagerduty_priority`](https://registry.terraform.io/providers/PagerDuty/pagerduty/latest/docs/data-sources/priority) data source. * `annotate` - (Optional) Add this text as a note on the resulting incident. +* `incident_custom_field_update` - (Optional) Assign a custom field to the resulting incident. + * `id` - (Required) The custom field id + * `value` - (Required) The value to assign to this custom field * `pagerduty_automation_action` - (Optional) Configure a [Process Automation](https://support.pagerduty.com/docs/event-orchestration#process-automation) associated with the resulting incident. * `action_id` - (Required) Id of the Process Automation action to be triggered. * `automation_action` - (Optional) Create a [Webhook](https://support.pagerduty.com/docs/event-orchestration#webhooks) associated with the resulting incident.