-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from stmcallister/master
Adding pagerduty_priority data source
- Loading branch information
Showing
11 changed files
with
223 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
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.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters