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

[ORCA-3444] Add support for Event Orchestrations #512

Merged
merged 52 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e3ba4e7
ORCA-3459 - event orchestration resource
alenapan May 4, 2022
2ca22de
reformat
alenapan May 4, 2022
59695ae
[REVERT LATER] Temporarily pointing to the local copy of go-pagerduty
alenapan May 4, 2022
77b07ad
rename Orchestration references to EventOrchestration
alenapan May 4, 2022
9dc2976
add more properties, mapping logic; add tests
alenapan May 5, 2022
c5aa937
more tests to event_orchestration_resource
Pari-Dhanakoti May 5, 2022
60cfa6c
add datasource event orchestration
Pari-Dhanakoti May 5, 2022
febcb67
[REVERT LATER]-local testing
Pari-Dhanakoti May 5, 2022
4f8a589
fix create logic (set integrations), remove description and routes fr…
alenapan May 5, 2022
f86990f
fix data source, add data source tests
alenapan May 6, 2022
6ce2d67
reformat
alenapan May 6, 2022
b253c96
Add import tests
alenapan May 6, 2022
cf4c9d8
update to latest alenapan/go-pagerduty
alenapan May 6, 2022
37c0107
add team checks to the tests
alenapan May 6, 2022
e25a2f3
[ORCA-3475] Allow deleting event orchestration team from an orchestra…
alenapan May 10, 2022
735f401
[ORCA-3463] Orchestration Path Router Resource (#493)
Pari-Dhanakoti May 12, 2022
bdf67f2
Event orchestration unrouted resource (#495)
alexzakabluk May 13, 2022
3162fdc
make type computed and set it on read/update
Pari-Dhanakoti May 19, 2022
0459e90
Orca 3486 refactor (#500)
alexzakabluk May 19, 2022
ab94a67
[ORCA-3465] - Event Orchestration Service path resource (#499)
alenapan May 20, 2022
1c89062
Flatten teams block (#506)
alexzakabluk May 20, 2022
8f4d19b
ORCA-3486 - remove team attribute from service path
alenapan May 20, 2022
f1397ab
flatten/rename parent to 'service' for service path
alenapan May 20, 2022
91b1c62
remove type attribute from unrouted
alenapan May 20, 2022
468d254
remove type attribute from router
alenapan May 20, 2022
8db156a
flatten/rename parent to 'event_orchestration' for router
alenapan May 20, 2022
2d4ac6b
set event_orchestration attr on router import
alenapan May 20, 2022
4f8f3aa
flatten/rename parent to 'event_orchestration' for unrouted
alenapan May 20, 2022
5c91e51
Clean teams block
alexzakabluk May 20, 2022
62f424c
revert changes on web file
alexzakabluk May 20, 2022
8170b51
[ORCA-3486] - Reuse shared Event Orchestration Path logic, add import…
alenapan May 20, 2022
0f2bd6e
[ORCA-3486] Extend unrouted tests, add CustomizeDiff, clean shared fu…
alexzakabluk May 24, 2022
0a4781d
orchestration and path resource documentation
Pari-Dhanakoti May 18, 2022
b48c9a6
datasource documentation
Pari-Dhanakoti May 18, 2022
a692119
refactor
Pari-Dhanakoti May 18, 2022
fb82f8b
update comment
Pari-Dhanakoti May 18, 2022
282404b
update type field documentation
Pari-Dhanakoti May 19, 2022
e69c11f
update documentation
Pari-Dhanakoti May 20, 2022
064154f
cleanup
Pari-Dhanakoti May 22, 2022
22fca15
Remove mention of the suppress action from event_orchestration_unrout…
metavida May 24, 2022
cb45904
Add "Optional" info to 1 attribute in event_orchestration_service docs
metavida May 24, 2022
9219f51
give a better datasource example
Pari-Dhanakoti May 24, 2022
0d89d5d
cleanup
alenapan May 25, 2022
0cfb66d
Add Event Orchestration info to the CHANGELOG (release date TBD) (#514)
metavida May 27, 2022
3ad7c3b
update go-pagerduty package
alenapan May 27, 2022
623b2a5
Router - make sets, rules, conditions singular
alenapan Jun 1, 2022
d8bf338
Unrouted, Service - make sets, rules, conditions, variables, extracti…
alenapan Jun 1, 2022
ab1294a
Event Orchestration - make integrations singular
alenapan Jun 1, 2022
ff5d3c9
update Event Orchestration documentation
alenapan Jun 1, 2022
4fcf232
Merge pull request #517 from PagerDuty/event-orch-resource-singular-n…
Jun 1, 2022
9636f8c
EO data source - retry on any error
alenapan Jun 1, 2022
67e1f0a
EO data source - retry on any error
alenapan Jun 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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