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

Adding pagerduty_priority data source #219

Merged
merged 3 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-pagerduty
require (
github.com/google/go-querystring v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.7.0
github.com/heimweh/go-pagerduty v0.0.0-20200415004831-bc2b3224a572
github.com/heimweh/go-pagerduty v0.0.0-20200429000711-fdd3a48907e7
)

go 1.13
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/heimweh/go-pagerduty v0.0.0-20190807171021-2a6540956dc5 h1:UZQ03lpxS/AUrMTlh1yQ/MJEJ+2he5bCItZ4W9Lgs1c=
github.com/heimweh/go-pagerduty v0.0.0-20190807171021-2a6540956dc5/go.mod h1:6+bccpjQ/PM8uQY9m8avM4MJea+3vo3ta9r8kGQ4XFY=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/heimweh/go-pagerduty v0.0.0-20200314051819-4b75e8d46b79 h1:pFvZwIP/uRMQioGOgp/avKBfWGygpsSx4zxESmsK1GM=
github.com/heimweh/go-pagerduty v0.0.0-20200314051819-4b75e8d46b79/go.mod h1:6+bccpjQ/PM8uQY9m8avM4MJea+3vo3ta9r8kGQ4XFY=
github.com/heimweh/go-pagerduty v0.0.0-20200331225917-7fbbcd73f188 h1:oh+QxBGkrMPDUJ2R0u4ik6anVybX2byrACqdbeLveLc=
github.com/heimweh/go-pagerduty v0.0.0-20200331225917-7fbbcd73f188/go.mod h1:6+bccpjQ/PM8uQY9m8avM4MJea+3vo3ta9r8kGQ4XFY=
github.com/heimweh/go-pagerduty v0.0.0-20200415004831-bc2b3224a572 h1:UPbUDXwtlgbBldY7kaQKI28dsZmUxmtzhsZA0db0lUI=
github.com/heimweh/go-pagerduty v0.0.0-20200415004831-bc2b3224a572/go.mod h1:6+bccpjQ/PM8uQY9m8avM4MJea+3vo3ta9r8kGQ4XFY=
github.com/heimweh/go-pagerduty v0.0.0-20200429000711-fdd3a48907e7 h1:8groiuI/kigz8jYT46EKNqDYVcEfSDnhv5p+VgZfPGU=
github.com/heimweh/go-pagerduty v0.0.0-20200429000711-fdd3a48907e7/go.mod h1:6+bccpjQ/PM8uQY9m8avM4MJea+3vo3ta9r8kGQ4XFY=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
60 changes: 60 additions & 0 deletions pagerduty/data_source_pagerduty_priority.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package pagerduty

import (
"fmt"
"log"
"strings"

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

func dataSourcePagerDutyPriority() *schema.Resource {
return &schema.Resource{
Read: dataSourcePagerDutyPriorityRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of the priority to find in the PagerDuty API",
},
"description": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourcePagerDutyPriorityRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*pagerduty.Client)

log.Printf("[INFO] Reading PagerDuty priority")

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

resp, _, err := client.Priorities.List()
if err != nil {
return err
}

var found *pagerduty.Priority

for _, priority := range resp.Priorities {
if strings.EqualFold(priority.Name, searchTeam) {
found = priority
break
}
}

if found == nil {
return fmt.Errorf("Unable to locate any priority with name: %s", searchTeam)
}

d.SetId(found.ID)
d.Set("name", found.Name)
d.Set("description", found.Description)

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

import (
"testing"

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

func TestAccDataSourcePagerDutyPriority_Basic(t *testing.T) {
dataSourceName := "data.pagerduty_priority.p1"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourcePagerDutyPriorityConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
resource.TestCheckResourceAttr(dataSourceName, "name", "P1"),
),
},
},
})
}
func TestAccDataSourcePagerDutyPriority_P2(t *testing.T) {
dataSourceName := "data.pagerduty_priority.p2"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourcePagerDutyP2Config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
resource.TestCheckResourceAttr(dataSourceName, "name", "P2"),
),
},
},
})
}

const testAccDataSourcePagerDutyPriorityConfig = `
data "pagerduty_priority" "p1" {
name = "p1"
}
`

const testAccDataSourcePagerDutyP2Config = `
data "pagerduty_priority" "p2" {
name = "p2"
}
`
1 change: 1 addition & 0 deletions pagerduty/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func Provider() terraform.ResourceProvider {
"pagerduty_extension_schema": dataSourcePagerDutyExtensionSchema(),
"pagerduty_service": dataSourcePagerDutyService(),
"pagerduty_business_service": dataSourcePagerDutyBusinessService(),
"pagerduty_priority": dataSourcePagerDutyPriority(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions vendor/github.com/heimweh/go-pagerduty/pagerduty/priority.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ github.com/hashicorp/terraform-svchost/auth
github.com/hashicorp/terraform-svchost/disco
# github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/hashicorp/yamux
# github.com/heimweh/go-pagerduty v0.0.0-20200415004831-bc2b3224a572
# github.com/heimweh/go-pagerduty v0.0.0-20200429000711-fdd3a48907e7
github.com/heimweh/go-pagerduty/pagerduty
# github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
github.com/jmespath/go-jmespath
Expand Down
66 changes: 66 additions & 0 deletions website/docs/d/priority.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
layout: "pagerduty"
page_title: "PagerDuty: pagerduty_priority"
sidebar_current: "docs-pagerduty-datasource-priority"
description: |-
Get information about a priority that you can use with ruleset_rules, etc.
---

# pagerduty\_priority

Use this data source to get information about a specific [priority][1] that you can use for other PagerDuty resources.

## Example Usage

```hcl
data "pagerduty_priority" "p1" {
name = "P1"
}
resource "pagerduty_ruleset" "foo" {
name = "Primary Ruleset"
}
resource "pagerduty_ruleset_rule" "foo" {
ruleset = pagerduty_ruleset.foo.id
position = 0
disabled = "false"
conditions {
operator = "and"
subconditions {
operator = "contains"
parameter {
value = "disk space"
path = "payload.summary"
}
}
subconditions {
operator = "contains"
parameter {
value = "db"
path = "payload.source"
}
}
}
actions {
route {
value = "P5DTL0K"
}
priority {
value = pagerduty_priority.p1.id
Copy link

Choose a reason for hiding this comment

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

I guess it should be data.pagerduty_priority.p1.id instead of pagerduty_priority.p1.id

Copy link

Choose a reason for hiding this comment

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

@stmcallister Any thoughts on this?

}
}
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the priority to find in the PagerDuty API.

## Attributes Reference
* `id` - The ID of the found priority.
* `name` - The name of the found priority.
* `description` - A description of the found priority.

[1]: https://developer.pagerduty.com/api-reference/reference/REST/openapiv3.json/paths/~1priorities/get
1 change: 1 addition & 0 deletions website/docs/r/ruleset_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ The following arguments are supported:

### Action (`actions`) supports the following:
* `route` (Optional) - The ID of the service where the event will be routed.
* `priority` (Optional) - The ID of the priority applied to the event.
* `severity` (Optional) - The [severity level](https://support.pagerduty.com/docs/rulesets#section-set-severity-with-event-rules) of the event. Can be either `info`,`error`,`warning`, or `critical`.
* `annotate` (Optional) - Note added to the event.
* `extractions` (Optional) - Allows you to copy important data from one event field to another. Extraction rules must use valid [RE2 regular expression syntax](https://github.com/google/re2/wiki/Syntax). Extraction objects consist of the following fields:
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/service_dependency.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The following attributes are exported:

## Import

Service dependencies can be imported using the related business service id and the ruleset_rule id separated by a dot, e.g.
Service dependencies can be imported using the related business service id and the dependency id separated by a dot, e.g.

```
$ terraform import pagerduty_service_dependency.main P4B2Z7G.D5RTHKRNGU4PYE90PJ
Expand Down