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

Event Orchestration: add support for Dynamic Routing and Dynamic Escalation Policy Assignment #885

Conversation

alenapan
Copy link
Contributor

@alenapan alenapan commented Jun 17, 2024

@alenapan alenapan marked this pull request as ready for review July 12, 2024 21:08
@alenapan alenapan changed the title [DO NOT MERGE] Event Orchestration: add support for Dynamic Routing and Dynamic Escalation Policy Event Orchestration: add support for Dynamic Routing and Dynamic Escalation Policy Assignment Jul 12, 2024
@@ -374,6 +378,7 @@ func expandGlobalPathActions(v interface{}) *pagerduty.EventOrchestrationPathRul
actions.Suppress = a["suppress"].(bool)
actions.Suspend = intTypeToIntPtr(a["suspend"].(int))
actions.Priority = a["priority"].(string)
actions.EscalationPolicy = stringTypeToStringPtr(a["escalation_policy"].(string))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: The EscalationPolicy property is a string pointer (*string) and not a string because we need to be able to send null to the API in order to reset the action.

@@ -113,6 +135,54 @@ func resourcePagerDutyEventOrchestrationPathRouter() *schema.Resource {
}
}

func checkDynamicRoutingRule(context context.Context, diff *schema.ResourceDiff, i interface{}) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: This function performs the following checks and returns a plan error if any of the checks are violated:

  • A Router can have at most one Dynamic Routing rule
  • Dynamic Routing rule must be the first rule of the first ("start") set
  • A Dynamic Routing rule, if placed correctly as the first rule of the first set, cannot have conditions and the route_to action

Comment on lines +367 to +372
dra := am["dynamic_route_to"]
if isNonEmptyList(dra) {
actions.DynamicRouteTo = expandRouterDynamicRouteToAction(dra)
} else {
actions.RouteTo = am["route_to"].(string)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: Because dynamic_route_to and route_to are mutually-exclusive, we only set the route_to action if dynamic_route_to is not set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: Made the same changes as in the pagerduty/resource_pagerduty_event_orchestration_path_global.go file

Copy link
Contributor

@imjaroiswebdev imjaroiswebdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @alenapan this Event Orchestration API enhancement looks pretty good implemented for me.

nit: I'd only suggest you to consider the addition of this acceptance test, in order to test that imports for pagerduty_event_orchestration_router keep working after adding dynamic_route_to.

go.mod Outdated Show resolved Hide resolved
alenapan and others added 7 commits July 22, 2024 11:50
…vent_orchestration_router` (#1)

* temporarily replace go-client with a feature branch

* ORCA-4811 - add support for  action

* fix import tests

* Revert "fix import tests"

This reverts commit e42694d.
* Update the router example to use the pagerduty_service data source

* Add a dynamic router rule example

* Document the dynamic vs static router actions
…d Service Event Orchestration resources (#5)

* WIP

* Add tests for global and service orchs

* Changes from review

* Formatting changes, renamed methods to be clearer
* Syntax errors 🤦
* Missed re-adding the expand line :o
*

* Catch-all supports EP, ensure it fits there

* Add test cases to test tf resource

* Add delete config

* Do not add empty string for policy

* Global and service path flattening

* WIP Test for EP with terraformed ID

* WIP

* Temporary, running pagerduty-go from fork

* Fixup tests, validate that *string escalation_policy is accepted

* reformat test config

* reimport go-pagerduty

---------

Co-authored-by: Alena Pantuzenko <apantuzenko@pagerduty.com>
@c-kaieong c-kaieong force-pushed the event-orchestration-dynamic-routing-and-esc-policy-support branch from 80bcc9e to 9539e47 Compare July 22, 2024 15:50
@imjaroiswebdev imjaroiswebdev merged commit b473252 into PagerDuty:master Jul 22, 2024
1 check passed
@NargiT
Copy link
Contributor

NargiT commented Jul 25, 2024

Hello @alenapan

Documentation for dynamic_routing has a small error.

      actions {
        dynamic_route_to { # no equal sign
          lookup_by = "service_id"
          source = "event.custom_details.pd_service_id"
          regex = "(.*)" # regex instead of regexp
        }
      }

@alenapan
Copy link
Contributor Author

Hello @alenapan

Documentation for dynamic_routing has a small error.

      actions {
        dynamic_route_to { # no equal sign
          lookup_by = "service_id"
          source = "event.custom_details.pd_service_id"
          regex = "(.*)" # regex instead of regexp
        }
      }

Hi @NargiT, thanks for letting me know! I fixed it in #917 and passed it onto the TF Provider repo owners, so hopefully we can release it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants