Skip to content

Commit

Permalink
Merge pull request #749 from swbradshaw/ORCA-4263
Browse files Browse the repository at this point in the history
[ORCA-4263] Support for incident custom fields for Event Orchestration
  • Loading branch information
imjaroiswebdev authored Feb 26, 2024
2 parents 620f5d2 + 145834d commit 50c2c13
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 44 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
40 changes: 40 additions & 0 deletions pagerduty/event_orchestration_path_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{}

Expand Down Expand Up @@ -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{}

Expand Down
20 changes: 16 additions & 4 deletions pagerduty/resource_pagerduty_event_orchestration_path_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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{}) {
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -314,7 +314,7 @@ func testAccCheckPagerDutyEventOrchestrationPathGlobalAutomationActionsConfig(t,
key = "baz"
value = "buz"
}
parameter {
key = "source"
value = "orch"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions pagerduty/resource_pagerduty_event_orchestration_path_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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{}) {
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 50c2c13

Please sign in to comment.