Skip to content

Commit

Permalink
[ORCA-3444] Add support for Event Orchestrations (#512)
Browse files Browse the repository at this point in the history
* ORCA-3459 - event orchestration resource

* reformat

* [REVERT LATER] Temporarily pointing to the local copy of go-pagerduty

* rename Orchestration references to EventOrchestration

* add more properties, mapping logic; add tests

* more tests to event_orchestration_resource

* add datasource event orchestration

* [REVERT LATER]-local testing

* fix create logic (set integrations), remove description and routes from orchestration data source

* fix data source, add data source tests

* reformat

* Add import tests

* update to latest alenapan/go-pagerduty

* add team checks to the tests

* [ORCA-3475] Allow deleting event orchestration team from an orchestration (#494)

* support unsetting orch team

* add retry logic to the event orchestration update method

* [ORCA-3463] Orchestration Path Router Resource (#493)

* router path

* Add support for parent

* refactor

* update handler and actions support

* support conditions

* move conditions to util

* move parent to util

* test for multiple rules and conditions

* actions and catchall

* refactor tests

* validateFunc

* refactor

* undo local vendor module path change

* rules schema change and test

* PR comments addressed

* Event orchestration unrouted resource (#495)

* Init commit for unrouted

* Added tests for unrouted

* Added catch_all to unrouted schema

* Tweaked catch_all

* Merge event-orchestrations

* Add testacc for unrouted

* Added full config test for unrouted

* Add test for number of extractions and variables

* Cleaned router and added new test checks to unrouted

* Change escalation_policy from snake case to camel case

* make type computed and set it on read/update

* Orca 3486 refactor (#500)

* Clean sweeper function for router/unrouted

* Clean sweeper function

* [ORCA-3465] - Event Orchestration Service path resource (#499)

* ORCA-3465 - Event Orchestration Service Path resource

* add resource file

* fix read/update, add test

* more tests

* more service path tests, add conditions

* more tests

* more tests

* add more service path props

* fix orch path PUT payload, add tests

* fix Suspend

* ToDos

* add catch_all support, fix tests

* add support for regex extractions, add mor tests, add service path import test

* update client

* PR feedback

* Flatten teams block (#506)

* Flatten teams block

* Fixed naming for the test orchestration

* ORCA-3486 - remove team attribute from service path

* flatten/rename parent to 'service' for service path

* remove type attribute from unrouted

* remove type attribute from router

* flatten/rename parent to 'event_orchestration' for router

* set event_orchestration attr on router import

* flatten/rename parent to 'event_orchestration' for unrouted

* Clean teams block

* revert changes on web file

* [ORCA-3486] - Reuse shared Event Orchestration Path logic, add import tests (#509)

* ORCA-3486 - add import tests for router/unrouted

* ORCA-3486 - add import tests for router, unrouted

* reuse severity/event_action validation functions in unrouted/service

* reuse variables and extractions schema in router/unrouted

* reuse shared conditions schema and mapping functions in router/unrouted/service

* [ORCA-3486] Extend unrouted tests, add CustomizeDiff, clean shared functions (#510)

* Extend unrouted tests, add CustomizeDiff, clean shared functions

* Move shared functions for unrouted and service paths to utils file

* orchestration and path resource documentation

* datasource documentation

* refactor

* update comment

* update type field documentation

* update documentation

* cleanup

* Remove mention of the suppress action from event_orchestration_unrouted docs

* Add "Optional" info to 1 attribute in event_orchestration_service docs

* give a better datasource example

* cleanup

* Add Event Orchestration info to the CHANGELOG (release date TBD) (#514)

* update go-pagerduty package

* Router - make sets, rules, conditions singular

* Unrouted, Service - make sets, rules, conditions, variables, extractions, pd_automation_actions, automations_action (headers, params) singular

* Event Orchestration - make integrations singular

* update Event Orchestration documentation

* EO data source - retry on any error

* EO data source - retry on any error

Co-authored-by: Pari Dhanakoti <pdhanakoti@pagerduty.com>
Co-authored-by: Alex Zakabluk <azakabluk@pagerduty.com>
Co-authored-by: Marcos Wright-Kuhns <webmaster@wrightkuhns.com>
Co-authored-by: Scott McAllister <smcallister@pagerduty.com>
  • Loading branch information
5 people committed Jun 9, 2022
1 parent 9175f2c commit d223aac
Show file tree
Hide file tree
Showing 30 changed files with 4,939 additions and 28 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 2.5.0 (June 1, 2022)

FEATURES:
* Support for Event Orchestration via several new resources. ([#512](https://github.com/PagerDuty/terraform-provider-pagerduty/pull/512))
* `resource/pagerduty_event_orchestration`
* `resource/pagerduty_event_orchestration_router`
* `resource/pagerduty_event_orchestration_unrouted`
* `resource/pagerduty_event_orchestration_service`

## 2.4.2 (May 20, 2022)

IMPROVEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
cloud.google.com/go v0.71.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/heimweh/go-pagerduty v0.0.0-20220422231448-43095fe5ba3f
github.com/heimweh/go-pagerduty v0.0.0-20220527195341-4e587aa9b58e
golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd // indirect
google.golang.org/api v0.35.0 // indirect
google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ github.com/heimweh/go-pagerduty v0.0.0-20220208023456-83fe435832fb h1:p3faOVCU8L
github.com/heimweh/go-pagerduty v0.0.0-20220208023456-83fe435832fb/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w=
github.com/heimweh/go-pagerduty v0.0.0-20220422231448-43095fe5ba3f h1:NLk7iDq85F2lz0q1gY32vZR506aYiNcgvV+Us1rX1q4=
github.com/heimweh/go-pagerduty v0.0.0-20220422231448-43095fe5ba3f/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w=
github.com/heimweh/go-pagerduty v0.0.0-20220428180718-5a69bb821163 h1:ETKxW+KSjOPaRzZU9f+QrjCkrL7hQqtMPKDv8DnLDO4=
github.com/heimweh/go-pagerduty v0.0.0-20220428180718-5a69bb821163/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w=
github.com/heimweh/go-pagerduty v0.0.0-20220527195341-4e587aa9b58e h1:xit0rQWTVlM9ohz4IzrddDKglC7jey+m3GSI/bz3TIw=
github.com/heimweh/go-pagerduty v0.0.0-20220527195341-4e587aa9b58e/go.mod h1:JtJGtgN0y9KOCaqFMZFaBCWskpO/KK3Ro9TwjP9ss6w=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
102 changes: 102 additions & 0 deletions pagerduty/data_source_pagerduty_event_orchestration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package pagerduty

import (
"fmt"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/heimweh/go-pagerduty/pagerduty"
)

func dataSourcePagerDutyEventOrchestration() *schema.Resource {
return &schema.Resource{
Read: dataSourcePagerDutyEventOrchestrationRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"integration": {
Type: schema.TypeList,
Computed: true,
Optional: true, // Tests keep failing if "Optional: true" is not provided
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"parameters": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"routing_key": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
},
}
}

func dataSourcePagerDutyEventOrchestrationRead(d *schema.ResourceData, meta interface{}) error {
client, err := meta.(*Config).Client()
if err != nil {
return err
}

log.Printf("[INFO] Reading PagerDuty Event Orchestration")

searchName := d.Get("name").(string)

return resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, _, err := client.EventOrchestrations.List()
if err != nil {
return resource.RetryableError(err)
}

var found *pagerduty.EventOrchestration

for _, orchestration := range resp.Orchestrations {
if orchestration.Name == searchName {
found = orchestration
break
}
}

if found == nil {
return resource.NonRetryableError(
fmt.Errorf("Unable to locate any Event Orchestration with the name: %s", searchName),
)
}

// Get the found orchestration by ID so we can set the integrations property
// since the list ndpoint does not return it
orch, _, err := client.EventOrchestrations.Get(found.ID)
if err != nil {
return resource.RetryableError(err)
}

d.SetId(orch.ID)
d.Set("name", orch.Name)

if len(orch.Integrations) > 0 {
d.Set("integration", flattenEventOrchestrationIntegrations(orch.Integrations))
}

return nil
})
}
64 changes: 64 additions & 0 deletions pagerduty/data_source_pagerduty_event_orchestration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package pagerduty

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccDataSourcePagerDutyEventOrchestration_Basic(t *testing.T) {
name := fmt.Sprintf("tf-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourcePagerDutyEventOrchestrationConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccDataSourcePagerDutyEventOrchestration("pagerduty_event_orchestration.test", "data.pagerduty_event_orchestration.by_name"),
),
},
},
})
}

func testAccDataSourcePagerDutyEventOrchestration(src, n string) resource.TestCheckFunc {
return func(s *terraform.State) error {

srcR := s.RootModule().Resources[src]
srcA := srcR.Primary.Attributes

r := s.RootModule().Resources[n]
a := r.Primary.Attributes

if a["id"] == "" {
return fmt.Errorf("Expected to get an Event Orchestration ID from PagerDuty")
}

testAtts := []string{"id", "name", "integration"}

for _, att := range testAtts {
if a[att] != srcA[att] {
return fmt.Errorf("Expected the Event Orchestration %s to be: %s, but got: %s", att, srcA[att], a[att])
}
}

return nil
}
}

func testAccDataSourcePagerDutyEventOrchestrationConfig(name string) string {
return fmt.Sprintf(`
resource "pagerduty_event_orchestration" "test" {
name = "%s"
}
data "pagerduty_event_orchestration" "by_name" {
name = pagerduty_event_orchestration.test.name
}
`, name)
}
Loading

0 comments on commit d223aac

Please sign in to comment.